var searchString = "Suchen";
var partnerPLZString = "Bitte PLZ ihres Bauvorhabens eingeben!";
var activeGalleryImage = 0;
var activeTopicList = 1;
var itemsWidth = 2168;
var sliderMinLeft = -2168;

var ua = navigator.userAgent;
var checker = {
	iphone: ua.match(/(iPhone|iPod|iPad)/),
	blackberry: ua.match(/BlackBerry/),
	android: ua.match(/Android/)
};

$(document).ready(function() {

	$(".productDetailNav").find(".dropdown").click(function(e){
		if (!$(this).next(".optionContainer").is(":visible")) {
			showDropdown(this,e);
			e.preventDefault();
		} else {
			//hideDropdown();
			e.preventDefault();
		}
	});

	function dropdownGoto(option) {
		var path = $(option).attr("rel");                
		if (!parseInt(path)) {
			$("body").css("cursor", "progress");
			window.location.href=path + "#productdetail";
		}
	}
	
	function hideDropdown() {
		$(".optionContainer").fadeOut(200);
		$(".optionContainer").find(".option").unbind("click");
		$(document).unbind("click");
		$(window).unbind("keydown");
	}
	
	var opening=false;
	
	function showDropdown(dropdown,e)
	{
		opening=true;
		hideDropdown();
		$(dropdown).next(".optionContainer").fadeIn(200);
		
		$(dropdown).next(".optionContainer").find(".option").click(function(a) {
			dropdownGoto(this);
			$(this).parent(".optionContainer").prev(".dropdown").html($(this).html());
			hideDropdown();
			a.preventDefault();                    
		});
		
		$(document).click(function(i){
			var target=i.target;
			if (!opening && !$(target).is('.dropdownContainer')  && !$(target).parents().is('.dropdownContainer')) {
				hideDropdown();
			}
		});
		
		$(window).keydown(function(e) {                   
			if (e.keyCode == 40) { // runter
				if ($(".optionContainer:visible").find(".option.active").next(".option").length) {                           
					var curr = $(".optionContainer:visible").find(".option.active");
					$(".optionContainer").find(".option").removeClass("active");
					curr.next(".option").addClass("active");                           
				} else if ($(".optionContainer:visible").find(".option").length) {
					$(".optionContainer").find(".option").removeClass("active");
					$(".optionContainer").find(".option:first").addClass("active");
				}
				e.preventDefault();
			}
			
			if (e.keyCode == 38) { // rauf
				if ($(".optionContainer:visible").find(".option.active").prev(".option").length) {
					var curr = $(".optionContainer:visible").find(".option.active");
					$(".optionContainer").find(".option").removeClass("active");
					curr.prev(".option").addClass("active");
				} else if ($(".optionContainer:visible").find(".option").length) {
					$(".optionContainer").find(".option").removeClass("active");
					$(".optionContainer").find(".option:last").addClass("active");
				}
				e.preventDefault();
			}
			
			if (e.keyCode == 27) {
				hideDropdown();
				e.preventDefault();
			}
			
			if (e.keyCode == 13) {
				if ($(".optionContainer:visible").find(".option.active").length) {
					dropdownGoto($(".optionContainer:visible").find(".option.active"));
					$(".optionContainer:visible").prev(".dropdown").html($(".optionContainer:visible").find(".option.active").html());
					hideDropdown();
				}
				e.preventDefault();
			}                 
		});
		e.preventDefault();
		opening=false;
	}
	
	$("span.option").hover(function() {
		$(this).parent().find(".option").removeClass("active")
		$(this).addClass("active");
	}, function () {
		$(this).parent().find(".option").removeClass("active")
	});
		
	$("#productInOut .inside").live("click", function() {
		$("#productInOut .outside_active").attr("class", "outside");
		$(this).attr("class", "inside_active");
		$("a#inside").show();
		$("a#outside").hide();
	});
		
	$("#productInOut .outside").live("click", function() {
		$("#productInOut .inside_active").attr("class", "inside");
		$(this).attr("class", "outside_active");
		$("a#inside").hide();
		$("a#outside").show();
	});


	$('.headerItem ul li').click(function() {
		$('.headerItem ul li').attr("class", $(this).attr("class").split("_act").join(""));
	
		
		$(this).attr("class", $(this).attr("class") + "_act");
		$('.headerItem img').hide(); 
		$('.headerItem img.' + $(this).attr('id')).show();
		$(".productTable td .productHighlighter").show();
		$(".productTable td." + $(this).attr('id') + " .productHighlighter").hide();
	});

	if(checker.iphone || checker.android || checker.blackberry) {

		if($(".productTable tr").size() >= 6 && $(".productTable").size() == 1) {
			var imageSize = "pr_detail";
		} else {
			var imageSize = "text_image_part";
		}

		$('.prImageHover').click(function(event){
			event.preventDefault();
			$('#productHoverImage').find("img").attr("src", 'image.php?name=' + imageSize + '&id=' + $(this).attr("hoverimage"));
			$('#productHoverImage').find("p#hoverText").html("<b>" + $(this).attr("title") + "</b><br>" + $(this).find("img").attr("name"));
			$('#productHoverImage').find("p").show();
			$('#productHoverImage').find("a").attr("href", $(this).attr("href"));
		});

		$('.prImageHoverSp').click(function(event){
			event.preventDefault();
			$('#productHoverImageSp').find("img").attr("src", 'image.php?name=text_image_part&id=' + $(this).attr("hoverimage"));
			$('#productHoverImageSp').find("p#hoverText").html("<b>" + $(this).attr("title") + "</b><br>" + $(this).find("img").attr("name"));
			$('#productHoverImageSp').find("p").show();
			$('#productHoverImageSp').find("a").attr("href", $(this).attr("href"));
		});
		
	} else {
	
		/*if($(".productTable tr").size() >= 6 && $(".productTable").size() == 1) {
			var imageSize = "pr_detail";
		} else {
			var imageSize = "text_image_part";
		}*/
	
		$('.prImageHover').hover(function(){
			$('#productHoverImage').find("img").attr("src", 'image.php?name=' + $(this).attr("hoversize") + '&id=' + $(this).attr("hoverimage"));
			$('#productHoverImage').find("p#hoverText").html("<b>" + $(this).attr("title") + "</b><br>" + $(this).find("img").attr("name"));
			$('#productHoverImage').find("p").show();
			$('#productHoverImage').find("a").attr("href", $(this).attr("href"));
		});

		$('.prImageHoverSp').hover(function(){
			$('#productHoverImageSp').find("img").attr("src", 'image.php?name=' + $(this).attr("hoversize") + '&id=' + $(this).attr("hoverimage"));
			$('#productHoverImageSp').find("p#hoverText").html("<b>" + $(this).attr("title") + "</b><br>" + $(this).find("img").attr("name"));
			$('#productHoverImageSp').find("p").show();
			$('#productHoverImageSp').find("a").attr("href", $(this).attr("href"));
		});
	}

	$('.wrapper_animation_content .b_arrow_left').click(function(e){
		e.preventDefault();
        
		$(".wrapper_animation_content div.fixFrameAnimation").each(function(i){
			if($(this).is(":visible")) {

				var state = i-1;

				if(state < 0) {
					state = $(".wrapper_animation_content div.fixFrameAnimation").length - 1;
				}

				$(".wrapper_animation_content div.fixFrameAnimation").eq(i).hide();
				$(".wrapper_animation_content div.fixFrameAnimation").eq(state).show();
                
				$(".wrapper_animation_content ul li a").removeClass("active");
				$(".wrapper_animation_content ul li:eq(" + state + ") a").addClass("active");
                
				return false;
			}
		});
	});
    
	$('.wrapper_animation_content .b_arrow_right').click(function(e){
		e.preventDefault();
		var count = $(".wrapper_animation_content img").length;
        
		$(".wrapper_animation_content div.fixFrameAnimation").each(function(i){
			if($(this).is(":visible")) {
                
				var state = i+1;
                
				if(state >= count) {
					state = 0;
				}
                
				$(".wrapper_animation_content div.fixFrameAnimation").eq(i).hide();
				$(".wrapper_animation_content div.fixFrameAnimation").eq(state).show();

				$(".wrapper_animation_content ul li a").removeClass("active");
				$(".wrapper_animation_content ul li:eq(" + state + ") a").addClass("active");
                
				return false;
			}
		});
	});


	var container = $('div.sliderGallery');
	var ul = $('ul', container);
    
	//console.log(itemsWidth);
	$("#searchOverlay").css("left", ($("li.headNavSearch").position().left+14) + "px");
	$("#languageOverlay").css("left", ($("li.headNavLanguage").position().left-8) + "px");

	$('.slider', container).slider({
		min: 0,
		max: itemsWidth,
		stop: function (event, ui) {
			ul.animate({
				'left' : ui.value * -1
			}, 500);
		},
		slide: function (event, ui) {
			ul.css('left', ui.value * -1);
		}
	});

	jQuery("#gallery").jcarousel({
		scroll: 1
	});

	$("#searchInput").focus(function() {
		if (this.value == searchString) this.value='';
		showSearchOverlay();
	});
	$("#searchInput").blur(function() {
		if (this.value=='') this.value=searchString;
	});

	$(".partnerSucheInput").blur(function(){
		if(this.value=='') this.value=partnerPLZString;
	});

	$(".partnerSucheInput").click(function(){
		if(this.value==partnerPLZString) this.value='';
	});

	$(".partnerSucheInputOrt").blur(function(){
		if(this.value=='') this.value=partnerPLZString;
	});

	$(".partnerSucheInputOrt").click(function(){
		if(this.value==partnerPLZString) this.value='';
	});

	$(".partnerSucheButton").click(function(){
		$("#searchPartnerForm").submit();
	});

	$(".menuWrapper").hover( function () {
		var offset = $(this).offset ();
		var width = $(this).width ();

		$(this).find (".subMenuItem").slideDown ();
	}, function () {
		$(this).find (".subMenuItem").slideUp ();
	});

	$("#newsSwitcherBox a").click ( function () {
		$("#newsSwitcherBox a").removeClass ();
		$("#newsSwitcherBox a").addClass ("newsSwitchItem");
		$(this).addClass ("newsSwitchItemActive");

		var x = $(this);

		$(".leftNewsTeaser").hide ();
		$("#leftNewsTeaser_" + x.attr ("rel")).fadeIn ();
	} );
	
	$("#topicSwitcherBox a").click ( function () {
	
		$("#topicSwitcherBox a").removeClass ();
		$("#topicSwitcherBox a").addClass ("topicSwitchItem");
		$(this).addClass ("topicSwitchItemActive");

		var x = $(this);

		$(".topicTeaserContainer .topicTeaser").hide ();
		$(".topicTeaserContainer #topicTeaser_" + x.attr ("rel")).fadeIn ();
	} );


	$(".imageGallery").live("click", function ()
	{
		$("#ImageContainer").attr("style", "background:url(" + $(this).attr ("href") + ") no-repeat center #ddd", 1000);
		$("#ImageCaption").html ($(this).find ("img").attr ("alt"));
		var id = this.id.split("_")[1];
		activeGalleryImage = id;

		if (($(".imageGallery").length-1) == activeGalleryImage)
		{
			$("#buttonNext").fadeOut();
		}
		else
		{
			$("#buttonNext").fadeIn();
		}
		if (activeGalleryImage == 0)
		{
			$("#buttonPrev").fadeOut();
		}
		else
		{
			$("#buttonPrev").fadeIn();
		}
		return false;
	} );

/*
	$("a[rel=fancybox]").fancybox({
		type: 'image'
	});*/
	
	$(".productPic a.fancybox").fancybox({
		overlayShow: false,
		cyclic:true,
		showNavArrows: false,
		type: 'image',
		titleShow: false
	});
	
	$("a#quer").fancybox({
		overlayShow: false,
		cyclic:true,
		showNavArrows: false,
		type: 'image',
		titleShow: false
	});

	$(".galleryitem a.fancybox").fancybox(
	{
		overlayShow: false,
		cyclic:true,
		showNavArrows: false,
		type: 'image',
		titleShow: false,
		onComplete: function()
		{
			if ($.browser.msie)
			{
				$("#fancybox-ie").height(parseInt($("#fancybox-inner img").height()+40));
				$("#fancybox-wrap").height(parseInt($("#fancybox-inner img").height()+40));
				$("#fancybox-ie").width(parseInt($("#fancybox-inner img").width()+40));
				$("#fancybox-wrap").width(parseInt($("#fancybox-inner img").width()+40));
			}
		}
	}
	);

	$("a.productCluetipOpen").cluetip({
		width: '300px', 
		dropShadowSteps:0, 
		sticky: false, 
		showTitle: false, 
		ajaxCache: true, 
		clickThrough:true
	});

	$("a.productListImageOpen").fancybox({
		showNavArrows: true,
		titleShow: true,
		titlePosition: 'inside',
		type:'image'
	});


	/*
    $("a.productInfoBoxOpen").fancybox({
        overlayShow: false,
        cyclic:true,
        showNavArrows: false,
        autoScale : true,
        titleShow: false,
        autoDimensions: true,
        onComplete: function() {
            
            
            if ($.browser.msie)
            {
               //if ($("#fancybox-wrap").height() < $("#fancybox-inner").height())
               //{
                    $("#fancybox-ie").height(parseInt($("#fancybox-inner").height()+30));
                    $("#fancybox-wrap").height(parseInt($("#fancybox-inner").height()+45));
               //}
            }
        }
    });
*/
	$(".openProductOverlay").fancybox({
		overlayShow: false,
		autoScale : true,
		autoDimensions: true,
		titleShow: false,
		onComplete: function(){

			$("object").addClass("hide");
			$("img.flash-alternative").addClass("show");
			$("embed").addClass("hide");
			//$("embed").parent().addClass("hide");
			
			$("#overlayContainer").css("float", "left");

			/*if ($.browser.msie)
                {
                  if ($("#fancybox-wrap").height() < $("#fancybox-inner").height())
                   {
                       $("#fancybox-inner").height($("#fancybox-inner").height()+30);
                       $("#fancybox-wrap").height($("#fancybox-inner").height()+45);
                   }
                }*/

			$("#fancybox-inner").height($("#fancybox-inner #overlayContainer").height() + 20);
			$("#fancybox-wrap").height($("#fancybox-inner").height() + 10);

			$("#fancybox-inner").width( $("#fancybox-inner #overlayContainer").width() + 34);
			$("#fancybox-wrap").width( $("#fancybox-inner").width() + 10);
				

		/*
                if ($("#fancybox-inner").hasScrollbar())
                {                
                    $("#fancybox-wrap").width( $("#fancybox-wrap").width() + 34 );
                    $("#fancybox-inner").width( $("#fancybox-inner").width() + 34 );
                }
                else
                {
                    //$("#fancybox-wrap").width( $("#fancybox-wrap").width() + 20);
                    //$("#fancybox-inner").width( $("#fancybox-inner").width() + 20);
                }
                $("#fancybox-inner").css("overflow-y", "auto");
                $("#fancybox-inner").css("overflow-x", "hidden");
			*/

		/*if($("#fancybox-inner").height() > $("#fancybox-").height()) {
                
            } */               //$("#fancybox-inner").css("overflow", "hidden");
		//}
		},
		onClosed: function() {
			$("object").removeClass("hide");
			$("embed").removeClass("hide");
			//$("embed").parent().removeClass("hide");
			$("img.flash-alternative").removeClass("show");

		}
	});

	$("a.galleryBoxOpen").fancybox({
		overlayShow: false,
		autoScale : true,
		autoDimensions: true,
		scrolling:'no',
		titleShow: false,
		onComplete: function(){

			$("object").addClass("hide");
			$("img.flash-alternative").addClass("show");
			$("embed").addClass("hide");


			//alert("make it bigger!! " + $("#fancybox-inner").height() + "px");
			/*if ($.browser.msie)
			{
                
				if($("#fancybox-wrap").height() <  495) {
					$("#fancybox-inner").height(460);
					$("#fancybox-ie").height(460);
					$("#fancybox-wrap").height(495);

				} else {
					$("#fancybox-inner").css("overflow", "hidden");
				}
			}
			else
			{
				if($("#fancybox-inner").height() <  456 || $("#fancybox-inner").width() < 536) {
					$("#fancybox-inner").height(456);
					$("#fancybox-wrap").height(476);
					$("#fancybox-inner").width(536);
					$("#fancybox-wrap").width(556);
				} else {

					$("#fancybox-inner").css("overflow", "hidden");
				}
			}*/
		},
		onClosed: function() {
			$("object").removeClass("hide");
			$("embed").removeClass("hide");
			$("img.flash-alternative").removeClass("show");

		}
	});



	$("#activationForm").validate({
		rules: {
			accept:{
				required:true
			}
		},
		messages: {
			accept: "erforderlich"
		}
	});
    

	$("#contact_form").validate({
		rules: {
			gender:
			{
				required:true
			},
			firstname:
			{
				required:true
			},
			lastname:
			{
				required:true
			},
			street:
			{
				required:true
			},
			city:
			{
				required:true
			},
			phone:
			{
				required:true
			},
			constadress:
			{
				required:true
			},
			constzip:
			{
				required:true
			},
			constcity:
			{
				required:true
			},
			consttype:
			{
				required:true
			}
		},
		messages: {
			gender:"",
			firstname: "",
			lastname: "",
			street: "",
			city: "",
			phone: "",
			constadress: "",
			constzip: "",
			constcity: "",
			consttype: ""
		}
	});


	$("#cad_form").validate({
		rules: {
			firstname:
			{
				required:true
			},
			lastname:
			{
				required:true
			},
			company:
			{
				required:true
			},
			street:
			{
				required:true
			},
			country:
			{
				required:true
			},
			phone:
			{
				required:true
			},
			mail:
			{
				required:true
			}
		},
		messages: {
			firstname: "",
			lastname: "",
			company: "",
			street: "",
			city: "",
			country: "",
			phone: "",
			mail: ""
		}
	});

	$("#accommodation_form").validate({
		rules: {
			firstname:
			{
				required:true
			},
			lastname:
			{
				required:true
			},
			street:
			{
				required:true
			},
			city:
			{
				required:true
			},
			zip:
			{
				required:true
			},
			phone:
			{
				required:true
			},
			mail:
			{
				required:true
			}
		},
		messages: {
			firstname: "",
			lastname: "",
			street: "",
			city: "",
			zip: "",
           
			phone: "",
			mail: ""
		}
	});
    
	$("#searchForm").validate({
		submitHandler: function(e) {
			if (searchString == $("#searchForm").val())
			{
				return false;
			}
			else
			{
				e.submit();
			}
                   
		},
		rules: {
			searchkey:
			{
				required:true,
				minlength:3
			}
		},
		messages: {
			searchkey:""
		}
	});

	$("#searchPartnerForm").validate({
		submitHandler: function(e) {
			 
			
			var country = ($('.partnerSucheDrop').length > 0) ? $('.partnerSucheDrop').val() : $('.partnerSucheDropOrt').val(); 
                   
			if (parseInt($(".partnerSucheInput").val()) || parseInt($(".partnerSucheInputOrt").val()) || (country > 2) )// Nicht für Österreich & Deutschland
			{                         
				e.submit();                      
			}
			else
			{
					   
				$(".partnerSucheInput").addClass("error");
				$(".partnerSucheInput").val(partnerPLZString);
				$(".partnerSucheInputOrt").addClass("error");
				$(".partnerSucheInputOrt").val(partnerPLZString);
				return false;
			}
		},
		rules: {
			country:{
				required:true
			},
			zip:{
				required: true
			}
		},
		messages: {
			country:"",
			zip:""
		}
	});
	
	$('.partnerSucheDrop').change (function () {
		 
		if ($(this).val() > 2) // Nicht für Österreich & Deutschland
		{
			
			$('#searchPartnerForm').submit();
		}
	}); 
	
	$('.partnerSucheDropOrt').change (function () {
		 
		if ($(this).val() > 2) // Nicht für Österreich & Deutschland
		{
			$('#searchPartnerForm').submit();
		}
	}); 

	$("*").keypress(function(e) {
		if (e.keyCode==27)
		{
			//closeLanguageOverlay();
			closeSearchOverlay();
		}
            
	});

	if (jQuery.browser.msie == true)
	{
		$("input")
		.bind("focus", function()
		{
			$(this).addClass("ieActive");
		})
		.bind ("blur", function() 
		{
			$(this).removeClass("ieActive")
		});

	}

	$("#searchInput").keypress(function(e) {
		if (e.keyCode == 13)
		{
			$("#searchForm").submit();
		}
	});


	if ($(".sliderGallery").is(":visible"))
	{
        
		$(document).keydown(function(e){
			var inputSelected;
			if (jQuery.browser.msie == true)
			{
				inputSelected = $("input.ieActive").length;
                
			}
			else
			{
				inputSelected = $("input:focus").length;
			}
            
			if (e.keyCode == 37) {                                
				if (!getHoldLeft() && (!$("#fancybox-outer").is(":visible")) && !inputSelected){
					slideLeftDown();
				}
			}
			if (e.keyCode == 39 && (!$("#fancybox-outer").is(":visible"))  && !inputSelected) {
				if (!getHoldRight()) {
					slideRightDown();
				}
			}
			if (inputSelected)
			{
             
		}

            
		});
		$(document).keyup(function(e) {
			if (e.keyCode == 37) {
				slideLeftUp();
			}
			if (e.keyCode == 39) {
				slideRightUp();
			}
		});

	}
	$(document).keydown(function(e) {
		//alert("visible : " + $("#ImageContainer").is(":visible"));
		if ($("#ImageContainer").length)
		{            
			if (e.keyCode == 39) {
				galleryNext();
			}
			if (e.keyCode == 37) {
				galleryPrev();
			}
		}
	});
	
	
});

function setDefaultSearchCaption(val)
{
	searchString = val;
}

function moveTopicUp() {
	if(activeTopicList > 1) {
		$("#topicListDown").show();
		$("#topicTeaserHolder #topicTeaser_" + activeTopicList).slideToggle();
		activeTopicList = parseInt(activeTopicList)-1;
		$("#topicTeaserHolder #topicTeaser_" + activeTopicList).slideToggle();
		if(activeTopicList <= 1) {
			//$("#topicListUp").hide();
			$("#topicListUp").addClass("none");
		} else {
			$("#topicListUp").removeClass("none");
		}
	}
}

function moveTopicDown() {
	if($("#topicTeaserHolder .topicTeaser").length > activeTopicList) {
		$("#topicListUp").removeClass("none");
		$("#topicTeaserHolder #topicTeaser_" + activeTopicList).slideToggle();
		activeTopicList = parseInt(activeTopicList)+1;
		$("#topicTeaserHolder #topicTeaser_" + activeTopicList).slideToggle();
		if($("#topicTeaserHolder .topicTeaser").length == activeTopicList) {
			$("#topicListDown").hide();
		}
	} else {
		$("#topicListDown").hide();
	}
}

function galleryNext()
{
	if (($(".imageGallery").length-1) > activeGalleryImage)
	{
		activeGalleryImage=parseInt(activeGalleryImage)+1;
		$("#ImageContainer").attr("style", "background:url(" + $("#galleryImage_" + activeGalleryImage).attr ("href") + ") no-repeat center #ddd", 1000);
		$("#ImageCaption").html ($("#galleryImage_" + activeGalleryImage).find ("img").attr ("alt"));

		if (($(".imageGallery").length-1) == activeGalleryImage)
		{
			$("#buttonNext").fadeOut(100);
		}
		else
		{
			$("#buttonNext").fadeIn(100);
		}
		$("#buttonPrev").fadeIn(100);

	}    
}

function galleryPrev()
{
	if (activeGalleryImage > 0)
	{
		activeGalleryImage=parseInt(activeGalleryImage)-1;
		$("#ImageContainer").attr("style", "background:url(" + $("#galleryImage_" + activeGalleryImage).attr ("href") + ") no-repeat center #ddd", 1000);
		$("#ImageCaption").html ($("#galleryImage_" + activeGalleryImage).find ("img").attr ("alt"));
		if (activeGalleryImage == 0 )
		{
			$("#buttonPrev").fadeOut(100);
		}
		else
		{
			$("#buttonPrev").fadeIn(100);
		}
		$("#buttonNext").fadeIn(100);
	}
}
function openGallery ()
{
	var overlay = $("#galleryPopUp");
	overlay.css ("left", ($(window).width ()/2)-(overlay.outerWidth ()/2));
        
	$("#overlay").fadeIn ();

	/*$("#overlay").animate ( {
		opacity: "0.8"
	} );*/

	overlay.fadeIn ();
}

function closePopUp ()
{
	var overlay = $("#galleryPopUp");
	overlay.fadeOut ();

	$("#overlay").hide ();
}

function toggleLanguageOverlay ()
{
	$("#languageOverlay").toggle ("slow");
	closeSearchOverlay();
}

function closeLanguageOverlay()
{
	$("#languageOverlay").hide("slow");
}

function toggleproductDetailOverlayContainer ()
{
	$("#productDetailOverlayContainer").toggle ("slow");
}

function toggleproductDetailOverlayContainer2 ()
{
	$("#productDetailOverlayContainer2").toggle ("slow");
}

function toggleproductDetailOverlayContainer3 ()
{
	$("#productDetailOverlayContainer3").toggle ("slow");
}

function toggleSearchOverlay ()
{
	$("#searchOverlay").toggle ("slow");
}
function showSearchOverlay()
{
	$("#searchOverlay").show("slow");
	closeLanguageOverlay();
}
function closeSearchOverlay ()
{
	$("#searchOverlay").hide ("slow");
}


//var sliderMinLeft = -1902;
function setSliderPosition(x)
{
	var style = parseInt(x) + "px";
    
	$(".sliderGallery ul").css("left",style);
	// 100% -> -1902 px
    
	var percent = x/(-itemsWidth)*100;
	$(".ui-slider-handle").css("left", percent + "%");
}

var bHoldRight = false;
var bHoldLeft = false;

function slideRightUp()
{
	bHoldRight=false;
}
function slideRightDown()
{
	bHoldRight=true;
	slideRight();
}
function slideRight()
{
	var posLeft = $(".sliderGallery ul").position().left;
	if (!bHoldLeft) {
		posLeft = posLeft - 50;
	}
	if (bHoldRight)
	{
		if (posLeft>sliderMinLeft)
		{
			$(".sliderGallery ul").animate({
				left: posLeft + "px"
				}, 50, function() {
				setTimeout(slideRight,0);
			});
			var percent = posLeft / (sliderMinLeft)*100;
			$(".ui-slider-handle").css("left",percent + "%");
   
		}
		else
		{
			$(".sliderGallery ul").animate({
				left:sliderMinLeft + "px"
				}, 50);
			$(".ui-slider-handle").css("left","100%");
		}
	}
}
function getHoldRight()
{
	return bHoldRight;
}
function getHoldLeft()
{
	return bHoldLeft;
}
function slideLeftUp()
{
	bHoldLeft = false;
}
function slideLeftDown()
{
	bHoldLeft = true;
	slideLeft();
}
function slideLeft()
{
	var posLeft = $(".sliderGallery ul").position().left;
	if (!bHoldRight) {
		posLeft = posLeft + 50;
	}
	if (bHoldLeft)
	{
		if (posLeft<0)
		{
			$(".sliderGallery ul").animate({
				left: posLeft + "px"
				}, 50, function (){
				setTimeout(slideLeft,0);
			});

			var percent = posLeft / (sliderMinLeft)*100;            
			$(".ui-slider-handle").css("left",percent + "%");
            
		}
		else
		{
			$(".sliderGallery ul").animate({
				left:"0px"
			}, 50);
			$(".ui-slider-handle").css("left","0%");
		}
	}
}

function changeProduct (nr){
	$(".productSet").hide();
	$(".productSet:eq("+ nr +")").show();

//parent.$("#fancybox-wrap").height( $("#fancybox-content-holder").height() + 40 );
//parent.$("#fancybox-inner").height( $("#fancybox-content-holder").height() + 20 );
};

function fancyprev () {
	$.fancybox.prev();
}

function fancynext () {
	$.fancybox.next();
}

jQuery.fn.hasScrollbar = function() {
	var scrollHeight = this.get(0).scrollHeight;

	//safari's scrollHeight includes padding
	if ($.browser.safari)
		scrollHeight -= parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));

	if (this.height() < scrollHeight)
		return true;
	else
		return false;
}
