var curImage = 0;
var homeImageAnimation;
var home_animation_on = false;
var imageContainerToggler = true;

var currentSearchModelId = false;


$(document).ready(function() {

	// content min-height (depending on menu-height)
	var menu_height = $('#menu_wrapper').height();

	$('#content').css({
		'minHeight': menu_height + 'px'
	});

	/* Menu BEG */

	// menu item level 2 hover
	$('#menu_wrapper a.item_level2 .hover').css({
		'opacity': 0
	});
	
	// menu item level 3 hover
	$('#menu_wrapper .item_level3_wrapper a.item_level3 .hover').css({
		'opacity': 0
	});
	
	$('#menu_wrapper .item_level3_wrapper a.item_level3').unbind('mouseenter').bind('mouseenter', function() {
		$('.hover', this).stop().animate({
			'opacity': 1
		}, 300);
	});
	
	$('#menu_wrapper .item_level3_wrapper a.item_level3').unbind('mouseleave').bind('mouseleave', function() {
		$('.hover', this).stop().animate({
			'opacity': 0
		}, 500);
	});
	
	// hover menu
	$('.item_level2').unbind('mouseenter').bind('mouseenter', function() {
		
		var level2_rel = $(this).attr('rel');
		var level3_wrapper_id = level2_rel.replace(/parent_id_/, '');
		
		var pos_obj = $(this).position();
		var level3_id_selector = $('#level3_' + level3_wrapper_id)
		
		level3_id_selector.css({
			'top': pos_obj.top + 'px'
		});
		
		level3_id_selector.stop().animate({
			'width': '297px'
		});
		
		$('.hover', this).stop().animate({
			'opacity': 1
		}, 300);
		
	});
	
	$('.item_level2').unbind('mouseleave').bind('mouseleave', function() {
		var level2_rel = $(this).attr('rel');
		var level3_wrapper_id = level2_rel.replace(/parent_id_/, '');
		
		$('#level3_' + level3_wrapper_id).stop().animate({
			'width': '0px'
		});
		
		$('.hover', this).stop().animate({
			'opacity': 0
		}, 500);
	});
	
	// hover submenu (only triggering)
	$('.item_level3_wrapper').unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'width': '297px'
		});
	});
	
	$('.item_level3_wrapper').unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'width': '0px'
		});
	});
	/* Menu END */

	/* Sitemap BEG */
	$('.sitemap_item').unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'color': '#000000'
		}, 100);
	});

	$('.sitemap_item').unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'color': '#922224'
		}, 750);
	});
	/* Sitemap END */


	/* Recommendation BEG */
	$("#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': '#BD2725'
		});
	}, function() {
		$(this).stop().animate({
			'backgroundColor': '#D7D7D7'
		});
	});
	
	$('.pfeil').unbind('mouseenter').bind('mouseenter', function() {
		$(this).stop().animate({
			'backgroundPosition': '5px 0px'
		});
	});

	$('.pfeil').unbind('mouseleave').bind('mouseleave', function() {
		$(this).stop().animate({
			'backgroundPosition': '0px 0px'
		});
	});

	// Header animation
	if (typeof homeAnimationImages != 'undefined' && homeAnimationImages) { 
		if (homeAnimationImages.length > 1) {
			$('#header_image_wrapper').rsanimator({
				'images': homeAnimationImages,
				'width': 990,
				'height': 363,
				'description': $('#header_image_description')/*,
				'indicator': {
					'container': $('#home_animatedcar_trigger'),
					'elementClass': 'carTrigger',
					'elementClassActive': 'current'
				}*/
			});
		} else if (homeAnimationImages.length > 0) {
			$('#header_image_wrapper').css({
				'backgroundImage': 'url(' + homeAnimationImages[0].imagefile + ')'
			});
		}
	}

});


