$(document).ready(function() {
	
	
	// ---------------------------------------------------
	// --------------------------------------------------- SEARCHBOX
	// ---------------------------------------------------
	var defaultSearchValue = $("#searchBox").val();

	$("#searchBox").focus( function () {
		if( $("#searchBox").val() == defaultSearchValue ){ $("#searchBox").val('') }
	});
	$("#searchBox").blur( function(){
  		if( $("#searchBox").val() == '' ){ $("#searchBox").val(defaultSearchValue); }
 	});
	
	
	// ---------------------------------------------------
	// --------------------------------------------------- LANGUAGE
	// ---------------------------------------------------
	var languageListIsVisible = false;
	var languageListHeight = $("#languageList").height();
	$("#languageList").hide().css({ height : 0 });

	
	$("#languageSelector").click(function() {
		if(!languageListIsVisible){
			languageListIsVisible = true;
			
			$("#languageList").stop().show().animate({ height : languageListHeight }, { duration: 250, easing: 'easeInOutCubic' });
			$("#languageSelector p").addClass("active");
			
		}else{
			$("#languageList").stop().animate({ height: 0 }, { duration: 400, easing: 'easeInOutCubic', complete: function () {
				$("#languageList").hide();
			 }});
			languageListIsVisible = false;
			$("#languageSelector p").removeClass("active");
		}
	});
	
	$("#languageList").mouseleave(function() {
		if(languageListIsVisible){
			$("#languageList").stop().animate({ height: 0 }, { duration: 400, easing: 'easeInOutCubic', complete: function () {
				$("#languageList").hide();
			 }});

			languageListIsVisible = false;
			$("#languageSelector p").removeClass("active");
		}
	});



	// ---------------------------------------------------
	// --------------------------------------------------- PRODUCT NAV OPEN/CLOSE
	// ---------------------------------------------------
	
	var navProductOpened = false;
	var navProductCloseTimeout = null;
	var navProductCloseSpeed = 200;
	var navProductHeight = $("#navProduct").height();
	var navProductIsActive = ( $("#navProductButt").hasClass("active") ) ? true : false;
	
	$("#navProduct").hide().css({ height : 0 });
	
	
	var np_url = window.location.pathname;
	var np_index = np_url.lastIndexOf("/");
	var np_filename = np_url.substr(np_index);
	//alert("np_url:" + np_filename);


	if(np_filename != "/produkte.php"){

		$("#navProductButt").mouseenter(function() {
			clearTimeout(navProductCloseTimeout);
			if(!navProductIsActive)  $("li#navProductButt").addClass("active");
			if(!navProductOpened){
				//navProductTimeout = setTimeout(openProductNav, 400);
				openProductNav();
			}
				
		});
		
		$("#navProductButt").mouseleave(function() {
			if(navProductOpened){
				navProductCloseTimeout = setTimeout(closeProductNav, navProductCloseSpeed);
			}
			if(!navProductIsActive)  $("li#navProductButt").removeClass("active");
		});
		
		$("#navProduct").mouseenter(function() {
			clearTimeout(navProductCloseTimeout);
			if(!navProductIsActive)  $("li#navProductButt").addClass("active");
			if(!navProductOpened){
				openProductNav();
			}
		});
		
		$("#navProduct").mouseleave(function() {
			if(!navProductIsActive)  $("li#navProductButt").removeClass("active");
			if(navProductOpened){
				navProductCloseTimeout = setTimeout(closeProductNav, navProductCloseSpeed);
			}
			
			
		});

	}

		
	function openProductNav(){
		//$("#navProduct").stop().slideDown(1000, 'easeInOutCubic');
		navProductOpened = true;
		var $div = $('#navProduct');
		$div.stop().show().animate({ height : navProductHeight }, { duration: 1000, easing: 'easeInOutCubic' });
	}
	
	function closeProductNav(){
		//$("#navProduct").stop().slideUp(500, 'easeInOutCubic');
		navProductOpened = false;
		var $div = $('#navProduct');
		$div.stop().animate({ height: 0 }, { duration: 1000, easing: 'easeInOutCubic', complete: function () {
			$div.hide();
		 }});
	}
	



	// ---------------------------------------------------
	// --------------------------------------------------- PRODUCT NAV HOVER
	// ---------------------------------------------------

	
	$("#navProductLists ul li a").mouseenter(
		function () {
			var id = $(this).index("#navProductLists a") ;
			//alert( "id: " + id);
			$("#productPreview").find("img.active").removeClass("active");
			$("#productPreview img").eq(id).addClass("active");
		}
	);


});
 
