/*

function doit() {	
	$("#headimage").animate({"opacity":1}, { duration: 1500, easing: "easeInQuad", queue: false} );
}

*/
function resizeFP() {
	var pageHeight = $(window).height();
		if (pageHeight < 630) {
			var newsize = pageHeight - 50; // 200 is the suggested size for subnavi and stuff
			if (newsize < 300) newsize = 300;
			$("#headimage").css("height",newsize);
			$("#header").css("height",newsize);
		} else {
			$("#headimage").css("height",600);
			$("#header").css("height",600);
		}
}
	

$(document).ready(function() {

	var mfcurrentlanguage;

	var myloc = String(document.location);
	if ( myloc.search(/pages\/de\/.+/) != -1 ) { mfcurrentlanguage="de";	}
	if ( myloc.search(/pages\/en\/.+/) != -1 ) { mfcurrentlanguage="en";	}
	if ( myloc.search(/pages\/fr\/.+/) != -1 ) { mfcurrentlanguage="fr";	}


	/* Apply fancybox to multiple items */
	if ( myloc.search(/press.+/) != -1 ) { 
		$("a.clippings").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true
		});
	}
	
	
	$(function() {
		$('#slideshow img:first').fadeIn(1000, function() {
			$('#slideshow').cycle({ 
			    fx:    'fade', 
			    timeout: 3000,
			    speed:  1000,
			    pause: 1,
			    next:   '#slideshow' 
			    
			 });
	    });
	});

	
		
	// disable accidentaly selecting the buttons

/*
	if (typeof document.onselectstart!="undefined") {
		document.onselectstart=new Function ("return false");
	}else{
		document.onmousedown=new Function ("return false");
		document.onmouseup=new Function ("return true");
	}
*/





	// Suche
	
	var searchHint_de = "Suchbegriff/Art.Nr. eingeben";
	var searchHint_en = "Enter search term / art.num.";
	var searchHint_fr = "LOCALE:Suchbegriff/Art.Nr. eingeben";

	if ($('#searchField').val()=="") {
		$('#searchField').val(eval("searchHint_"+mfcurrentlanguage));
	}
	$('#searchField').bind("focus", function() {
		var self = this;
		if ($(self).val()==eval("searchHint_"+mfcurrentlanguage)) {
			$(self).val("");
		}
	}).bind("blur", function() {
		var self = this;
		if ($(self).val()=="") {
			$(self).val(eval("searchHint_"+mfcurrentlanguage));
		}
	});


	$('#searchSubmit').click(function() {
		var self = this;
		if ($('#searchField').val() == eval("searchHint_"+mfcurrentlanguage)) {
			return false;
		} else {
			$('#searchForm').submit();
		}
	});
	
	
	
	// make front page browsersafe	
	if ( myloc.search(/home.+/) != -1 ) { 
		resizeFP();
		$(window).resize(function() {
			resizeFP();
		});
	}

	// Händlersuche

	$('.accTrigger').bind("click", function() {
		$('.accTrigger').addClass('collapsed').removeClass('expanded');
		$("div.accContent").css("display","none");
		$(this).nextAll("div.accContent").css("display","block");
		$(this).addClass('expanded').removeClass('collapsed');
		

	});

		$('#haendlerListe .trigger').bind("click", function() { 

			var myId = this.id;	
			var myNum = myId.replace("trigger","");
			myheight = Number($(this).attr("rel"));
			rows = 1 + Math.round(myheight / 2);
 			myheight = 50 + (rows  * 170);
			var myPos = -1 * (myNum-1)*640;

 			$('#ScrollContent').css("marginLeft",myPos);
 			$('#ScrollArea').css("height",myheight);

		});
		$('#haendlerListeFB .trigger').bind("click", function() { 

			var myId = this.id;	
			var myNum = myId.replace("trigger","");
			myheight = Number($(this).attr("rel"));
			rows = 1 + Math.round(myheight / 3);
 			myheight = 50 + (rows  * 600);
			var myPos = -1 * (myNum-1)*220;

 			$('#ScrollContent').css("marginLeft",myPos);
 			$('#ScrollArea').css("height",myheight);

		});
	$('#LandDE,#LandAT,#LandCH,#LandSonstige').bind("change", function() {
		$("#subFormSonstige,#subFormAT,#subFormCH,#subFormDE").css({"display":"none"});  
	});

	$('#LandDE').bind("change", function() {

//		if($('#LandDE option').attr("value")="Schweiz") {

		if($('#LandDE option:selected').attr("value")=="Deutschland") {
			$("#subFormDE").css({"display":"block"});  
		}
		if($('#LandDE option:selected').attr("value")=="Schweiz") {
			$("#subFormCH").css({"display":"block"});  
		}
		if($('#LandDE option:selected').attr("value")=="Österreich") {
			$("#subFormAT").css({"display":"block"});  
		}
		if($('#LandDE option:selected').attr("value")=="sonstiges") {
			$("#subFormSonstige").css({"display":"block"});  
		}
	});
	
	$('#LandAT').bind("change", function() {
		if($('#LandAT option:selected').attr("value")=="Deutschland") {
			$("#subFormDE").css({"display":"block"});  
		}
		if($('#LandAT option:selected').attr("value")=="Schweiz") {
			$("#subFormCH").css({"display":"block"});  
		}
		if($('#LandAT option:selected').attr("value")=="Österreich") {
			$("#subFormAT").css({"display":"block"});  
		}
		if($('#LandAT option:selected').attr("value")=="sonstiges") {
			$("#subFormSonstige").css({"display":"block"});  
		}
	});

	
	$('#LandCH').bind("change", function() {
		if($('#LandCH option:selected').attr("value")=="Deutschland") {
			$("#subFormDE").css({"display":"block"});  
		}
		if($('#LandCH option:selected').attr("value")=="Schweiz") {
			$("#subFormCH").css({"display":"block"});  
		}
		if($('#LandCH option:selected').attr("value")=="Österreich") {
			$("#subFormAT").css({"display":"block"});  
		}
		if($('#LandCH option:selected').attr("value")=="sonstiges") {
			$("#subFormSonstige").css({"display":"block"});  
		}
	});
	
	$('#LandSonstige').bind("change", function() {
		if($('#LandSonstige option:selected').attr("value")=="Deutschland") {
			$("#subFormDE").css({"display":"block"});  
		}
		if($('#LandSonstige option:selected').attr("value")=="Schweiz") {
			$("#subFormCH").css({"display":"block"});  
		}
		if($('#LandSonstige option:selected').attr("value")=="Österreich") {
			$("#subFormAT").css({"display":"block"});  
		}
		if($('#LandSonstige option:selected').attr("value")=="sonstiges") {
			$("#subFormSonstige").css({"display":"block"});  
		}
	});


	// Submenu Detailseite


	
	$('#productSelection').bind("change", function() {
		document.location=$('#productSelection option:selected').attr("value");
	});

	if (jQuery.browser.msie) {
/* 		$(".home #logo").css({"opacity":1,"backgroundImage":"url(/media/custom/logoHomeB.gif)"});   */
		$("#headimage").css({"opacity":1});  

	} else {
		$(".home #logo").animate({"opacity":1}, { duration: 500, easing: "swing", queue: false} );  

/*
		$("#headimage img").bind("load", function () { 
				$("#headimage").animate({"opacity":1}, { duration: 1500, easing: "easeInQuad", queue: false} );  
		});
*/


	
		$('.buttonActive').bind("mouseenter", function() {
			var self = this;
			$('.buttonActive').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
			$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
		}).bind("mouseleave", function() {
			var self = this;
			$('.buttonActive').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
		});	
	}
		$('#naviLevel1 li a.inactive').bind("mouseenter", function() {
			var self = this;
			$(self).animate({"color":"#fff"}, { duration: 250, easing: "swing", queue: false} );
		}).bind("mouseleave", function() {
			var self = this;
			$('#naviLevel1 li a').animate({"color":"#000"}, { duration: 250, easing: "swing", queue: false} );
		});	

	$('.pressclipping').bind("mouseenter", function() {
		var self = this;
		$('.pressclipping').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
		$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$('.pressclipping').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	});

	$('.varianteUebersicht').bind("mouseenter", function() {
		var self = this;
		$('.varianteUebersicht').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
		$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$('.varianteUebersicht').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	});

	$('.sortimentItem').bind("mouseenter", function() {
		var self = this;
		$('.sortimentItem').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
		$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$('.sortimentItem').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	});

	$('.sortimentItemlarge').bind("mouseenter", function() {
		var self = this;
		$('.sortimentItemlarge').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
		$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$('.sortimentItemlarge').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	});

	$('.sortimentItemHome').bind("mouseenter", function() {
		var self = this;
		$('.sortimentItemHome').animate({"opacity":0.5}, { duration: 250, easing: "swing", queue: false} );
		$(self).animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$('.sortimentItemHome').animate({"opacity":1}, { duration: 250, easing: "swing", queue: false} );
	});
	

		
	$('.searchresult, .buttonActive').bind("click", function() {
		var self = this;
		document.location= $(self).find("a").attr("href");
	});	
	
	
	

	// Fade in Mood Pictures
	
/* 	window.setTimeout('doit();', 1000); */


	// Theming 
	// summer: e 9 d b d 3, winter: a 5 8 0 5 e


/* 	if ( myloc.search(/h\ome.+/) != -1 ) { $("body").css({"backgroundColor":"#e7d5bb"}); } */
/* 	if ( myloc.search(/winter.+/) != -1 ) { $("body").css({"backgroundColor":"#e7d5bb"}); } */
/* 	if ( myloc.search(/basissortiment.+/) != -1 ) { $("body").css({"backgroundColor":"#e7d5bb"}); } */

/* 	if ( myloc.search(/spring.+/) != -1 ) { $("body").css({"backgroundColor":"#e7d5bb"}); } */
/* 	if ( myloc.search(/printemps.+/) != -1 ) { $("body").css({"backgroundColor":"#e7d5bb"}); } */

	// Jump back to current language home 
	
	$('#logo').bind("click", function() {
		document.location="/pages/"+mfcurrentlanguage+"/home";	
	});
	

	// attach click events to layers

	$('.variantePreviewSmall, .variantePreview, .varianteUebersicht, .sortimentItem, .sortimentItemlarge, .ArtikelUebersicht, .sortimentItemHome').bind("click", function() {
		var self = this;
/* 		alert($(self).find("a").attr("href")); */
		document.location=$(self).find("a").attr("href");
		
	});
	



});  

