function Numsort (a, b) {
  return a - b;
}

function setBoxHeights() {
	boxes = new Array();
	boxHeights = new Array();
	boxes = $("div.product ul");
	
	for(i=0; i<boxes.length; i++) {
		boxHeights[i] = boxes[i].offsetHeight;
	}
	
	boxHeights.sort(Numsort);
	boxHeights.reverse();
	
	for(i=0; i<boxes.length; i++) {
		boxes[i].style.height = boxHeights[0]+"px";
	}
}

function navActivate() {
	navi2links = $(".navi2 li a");
	
	for(i=0; i<navi2links.length; i++) {
		if((navi2links[i].href == window.location.href)||(window.location.href.indexOf(".php")<0 && navi2links[i].href.indexOf("/index.php")>-1)) {
			$(navi2links[i]).parents(".navi1>li").children("a:first-child").addClass("naviact");
			$(navi2links[i]).addClass("navi2act");
			$(navi2links[i]).parents("ul.navi2").css("display","block");
		}
	}
	
	//$(".navi1 li a").addClass("naviact");
}

function setContentelementCols() {
	contentelements = $("div.contentelement");
	
	for(i=0; i<contentelements.length; i++) {	
		if($(contentelements[i]).children(".extracol").html()) {
			$(contentelements[i]).children(".innercontent").css("width","409px");
			$(contentelements[i]).children(".extracol").css("height", $(contentelements[i]).children(".innercontent").height()+"px");
		}
	}
}

function newsToggle() {
	$("div.hiddennews").toggle();
}

function openEditorial(eId) {
	theUrl = "editorial.php?eId="+eId;
	eWindow = window.open(theUrl, "Editorial", "width=490, height=600, top=50, left=50, scrollbars=yes")
	eWindow.focus();
}


$(document).ready(function(){
	setBoxHeights();
	
	navActivate();
	
	$('#fades').cycle(
		{
			timeout:       10000,  // milliseconds between slide transitions (0 to disable auto advance) 
			speed:         2000,  // speed of the transition (any valid fx speed value) 
			height:       '254px', // container height 
			sync:          0,     // true if in/out transitions should occur simultaneously 
			pause:         1     // true to enable "pause on hover" 
		}
	);

	$("#productsbox div.product").hover(
		function () {
			$(this).addClass("producthover");
			$(this).children("h3").addClass("productheadhover");
		}, 
		function () {
			$(this).removeClass("producthover");
			$(this).children("h3").removeClass("productheadhover");
		}
	);
	
	$("#productsbox div.product").click(function() {
		if($(this).children("h3").children("a").attr("href")) {
			window.location.href = $(this).children("h3").children("a").attr("href");
		}
	});
	
	setContentelementCols();
	
	$(".fancygallery").fancybox({			
		'overlayOpacity' : '0.8',
		'overlayColor' : '#000',			
		'hideOnContentClick': false,
		'titlePosition' : 'inside'	
	});
	
	$(".inline").fancybox({
		'hideOnContentClick': false,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'overlayOpacity' : '0.8',
		'overlayColor' : '#000',
		'titlePosition' : 'inside'
	});	
		
	$("div.contentelement .zwischenheadline").prev("a").children("img.thumbimg").css("margin-top","22px");
	$("div.contentelement .zwischenheadline").prev("img.thumbimg").css("margin-top","22px");
	
	$("#searchsubmit").click(function() {
		if((document.forms[0].we_lv_search_0.value != "Suche")&&(document.forms[0].we_lv_search_0.value != "Search")&&(document.forms[0].we_lv_search_0.value != "")) {
			document.forms[0].submit();
		}
		else {
			if(jsLang == "en") {
				alert("Please enter a search term.");
			}
			else {
				alert("Bitte geben Sie einen Suchbegriff ein.");
			}
		}
	});
});


