var curImage = 0;
var homeImageAnimation;
var home_animation_on = false;
var imageContainerToggler = true;


$(document).ready(function() {

	$('#black_overlay').unbind('click').bind('click', function() {
		$(this).animate({
			'opacity': '0'
		}, 300, function() {
			$(this).css({
				'display': 'none',
				'opacity': '0.5'
			});
		});
	}).css({
		'height': $(document).height() + 'px'
	});


	// min-content height start
	$('#contentWrapper').animate({
		'minHeight': $('#anmietverkehrMenuWrapper').outerHeight() + $('#reiseangeboteMenuWrapper').outerHeight() + 'px'
	}, 500);
	
	$('#contentMenuWrapper').animate({
		'minHeight': $('#anmietverkehrMenuWrapper').outerHeight() + $('#reiseangeboteMenuWrapper').outerHeight() + 'px'
	}, 750);
	
	// min-content height end


	// Draggable logo BEG
	$('#logo').draggable({
		appendTo: 'body',
		containment: 'body',
		helper: 'original',
		zIndex: 9999,
		stop: function() {
			$(this).animate({
				'top': '60px',
				'left': '0px'
			}, 1000, 'easeOutElastic');
		}
	});
	
	/* Mainmenu start */
	$('#mainMenuWrapper a.mainMenuItem .hover').css({
		'opacity': '0.5'
	});
	
	$('.mainMenuItem').unbind('mouseenter').bind('mouseenter', function() {
		$('.hover', this).stop().animate({
			'height': '50px'
		}, 150);
	});
	
	$('.mainMenuItem').unbind('mouseleave').bind('mouseleave', function() {
		$('.hover', this).stop().animate({
			'height': '0px'
		}, 250);
	});
	/* Mainmenu end */


	// Footer sitemap start
	$('a.sitemap_item').stop().unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'color': '#fdc200'
		}, 100);
	});
	
	$('a.sitemap_item').stop().unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'color': '#FFFFFF'
		}, 1500);
	});
	// Footer sitemap end


	// journey list start
	
	// pageing center
	var pageing_block_width = $('.pageing_block a').length	* $('.pageing_block a').outerWidth();
	var pageing_block_left = ($('.pageing').outerWidth() - pageing_block_width) / 2;
	$('.pageing_block').stop().css({
		'left': pageing_block_left + 'px'
	});

	// image hover
	$('#journey_list_wrapper .image_wrapper').unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'opacity': '0.8'
		}, 200);
	});
	
	$('#journey_list_wrapper .image_wrapper').unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'opacity': '1'
		});
	});
	
	// journey list end
	
	// journey home slider start
	
	$('.image_slider_trigger_left').unbind('mouseenter').bind('mouseenter', function() {
		$('.arrow_left', this).stop().animate({
			'left': '7px'
		}, 250);
	});
	$('.image_slider_trigger_left').unbind('mouseleave').bind('mouseleave', function() {
		$('.arrow_left', this).stop().animate({
			'left': '17px'
		});
	});
	
	$('.image_slider_trigger_right').unbind('mouseenter').bind('mouseenter', function() {
		$('.arrow_right', this).stop().animate({
			'left': '27px'
		}, 250);
	});
	$('.image_slider_trigger_right').unbind('mouseleave').bind('mouseleave', function() {
		$('.arrow_right', this).stop().animate({
			'left': '17px'
		});
	});
	
	$('.image_slider_item_wrapper').unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'opacity': '0.75'
		});
	});
	$('.image_slider_item_wrapper').unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'opacity': '1'
		});
	});
	
	// journey home slider end


	/* Recommendation START */
	$("#recommendation_toggler").click(function (e) {
		e.preventDefault();

		$("#recommendation_container").animate({
			'top': '-420px',
			'height' : '380px'
		}, 700);
	});

	$("#hide_recommendation").click(function () {
		$("#recommendation_container").animate({
			'top': '0px',
			'height' : '0px'
		}, 700);
	});

	var recommendation_message = '';
	$('#recommendation_message').keyup(function(ekey) {
		$('#recommendation_msg_count').text(100 - $(this).val().length);
		if (recommendation_message.length >= 100 && ekey.which != 8 && ekey.which != 46) {
			$(this).val(recommendation_message);
		} else {
			recommendation_message = $(this).val();
		}
	});

	$("#send_recommendation").click(function () {
		$('<input>')
			.css('display', 'none')
			.attr({
				name: 'recommendation_sent',
				value: 'sent_true'
			})
			.appendTo('#form_recommendation')
		;

		$('#form_recommendation').attr({
			method: 'post'
		}).submit();
	});
	/* Recommendation END */
	
	
	// Galleries
	$('.fe_sd_gallery_item').hover(function() {
		$(this).stop().animate({
			'backgroundColor': '#ffea2b'
		});
	}, function() {
		$(this).stop().animate({
			'backgroundColor': '#D7D7D7'
		});
	});

	// Header animation
	if (typeof homeAnimationImages != 'undefined' && homeAnimationImages) { 
		if (homeAnimationImages.length > 1) {
			$('#headerImages').rsanimator({
				'images': homeAnimationImages,
				'width': 606,
				'height': 280/*,
				'indicator': {
					'container': $('#home_animatedcar_trigger'),
					'elementClass': 'carTrigger',
					'elementClassActive': 'current'
				}*/
			});
		} else if (homeAnimationImages.length > 0) {
			$('#headerImages').css({
				'backgroundImage': 'url(' + homeAnimationImages[0].imagefile + ')'
			});
		}
	}
});

