var actProduct = 1;
var productCount = null;
var url = null;
var productSliderAuto = null;

$(document).ready ( function () 
{	
	productCount = $(".productSliderObject").length;
	
	$(".productBoxContent").css("height", (6) * 60);
	$(".productSliderBox").css("height", (6) * 60);
	
	if (productCount <= 5)
	{
		$(".productBoxBottomArrow").hide();
		$(".productBoxTopArrow").hide();
		productSliderAuto = 1;
	}
	
	$(this).everyTime(4000, 'controlled', function() {
		if(productSliderAuto != 1)
		{
			productSlider('slider_1', 'top');
		}
	});
	

	$("#searchBar").gradient (
	{ 
		from: '7e8489', 
		to: 'b0b6ba'
	});
	
	$("#searchInput").click ( function () {
		$("#searchOverlay").fadeIn ("fast", function () {
			$("#searchOverlay").dropShadow ({
				left: -1,
				top: -1,
				opacity: 0.5
			});
		});
	});
	
	$("#searchCloseBtn").click ( function () {
		$("#searchOverlay").fadeOut ("fast");
		$("#searchOverlay").removeShadow ();
	});
	
	$("#imageContainer > #imageContainerRow > div > a > img").mouseover (setImage);
	$("#imageContainer > #imageContainerRow > div > a > img").mouseout (setImage);	
	
	$("#areaSelect").change ( function () {
		url = company + "/" + lang + "/branche/1," + $("#areaSelect").val();
		if($("#areaSelect").val().toLowerCase() == "all") { url = company + "/" + lang + "/branche/1,all"; }
		window.location.href = url;
	});
	
	$(".mainNode").click ( function () {
		var linkUrl = $(this).attr ("href");
		if (linkUrl != "#")
		{
			window.location.href = linkUrl;
		}
		else 
		{
			$("#mainNavigation ul").hide ();
		}
	});
	
});

function checkBranchenCheckBoxes(countBranchen) {
	for(i = 1; i<=countBranchen; i++) {
		if($("#searchBranche"+i).attr("checked")) return true;
	}
	return false;
}

function setBranchenCheckBoxes(countBranchen) {
	for(i = 1; i<=countBranchen; i++) {
		$("#searchBranche"+i).attr("checked",false);
	}
}

function setSearchCheckBoxes(countBranchen, AllOrNot) {
	if(AllOrNot == 0) {
		brancheCheckedOrNot = checkBranchenCheckBoxes(countBranchen);
		if(brancheCheckedOrNot) {
			$("#searchAllBranchen").attr("checked",false);
		} else {
			$("#searchAllBranchen").attr("checked",true);
		}
	} else {
		setBranchenCheckBoxes(countBranchen);
	}
}

function setInactive ()
{
	$("#imageContainer > .leftImageContainer > div").removeAttr ("class");
	$("#rightImage").slideUp ("fast");
	
}

function setImage ()
{
	var imgSrc = "";
	imgSrc = $(this).attr("src");
	imgSrcExt = imgSrc.substr(imgSrc.lastIndexOf("."),imgSrc.length);
	if (imgSrc.lastIndexOf("_active") > 0)
	{
		imgSrc = imgSrc.replace("_active"+imgSrcExt,imgSrcExt);
	}
	else
	{
		imgSrc = imgSrc.replace(imgSrcExt,"_active"+imgSrcExt);
	}
	$(this).attr("src",imgSrc);
}


function goTo ()
{
	window.open ($("#" + $(this).attr ("id") + " > p").attr ("title"));
}

function productSlider(obj, todo, setvar )
{	
	if (setvar == 1)
	{
		productSliderAuto = 1;
	}
	
	var position;
	
	if (todo == "top")
	{
		if (actProduct == 1)
		{
			actProduct = productCount - 4;
			//alert (actProduct);
		}
		else
		{
			actProduct = actProduct - 1;
		}
	}
	else 
	{
		//alert ((productCount-7));
		if (actProduct == (productCount-4))
			{
				actProduct = 1;
			}
			else
			{
				actProduct = actProduct + 1;
			}
	}
		
	if (actProduct <= 0)
	{
		actProduct = productCount;
	}
	else if (actProduct > productCount)
	{
		actProduct = 1;
	}
	
	position = (actProduct*70)-70;
	
	$("#" + obj + " .productSlider").animate({ 
        top: "-" + position + "px"
      }, 500, "swing" );
}

function goToPage (number)
{
	$("#pageNumber").val (number);
	$("#pageChooser").submit ();
}