var collapsedClipValue = "rect(150px 250px 220px 0px)";
var expandedClipValue  = "rect(25px 250px 220px 0px)";		

$(document).ready(function() {
	$(window).trigger("resize");
	$("#slideshow_home #login").css("clip", collapsedClipValue);
	
	$("#overlay_login_btn").click(function(){
		$("#login img.tab_login").trigger("click");	
	});
	
	if($('#faq_list').length > 0) {
		$('#faq_list').accordion({ active: false, alwaysOpen: false }); 
	}
	
	// Opera fix for double scrollbar
	if($.browser.opera)
	{
		var ScrollHeight = $("body")[0].scrollHeight;
		var BodyHeight   = $("body").height();
		
		if(ScrollHeight > BodyHeight) {
			$("html").css("height","auto");	
			$("body").css("height","auto");	
		}
	}
	
	$("#header .languages select").msDropDown();
});

$(window).load(function() {
	
})


$(window).resize(function() {

	$("#login").css("width", "250px");	


	/* 
	 * Bg container fix for all browsers, except ie and firefox
	 */
	
	if(!$.browser.msie &&
	   !$.browser.mozilla)
	{
		if($("#bgcontainer").length > 0) {
			var SiteHeight = $("#site").height();
			var BodyHeight = $("body").height();
			var BodyWidth  = $("body").width();
			
			if(SiteHeight > BodyHeight) {
				var EnlargePercent = (SiteHeight / BodyHeight);
				ContainerWidth  = BodyWidth  * EnlargePercent;
				ContainerHeight = BodyHeight * EnlargePercent;
	
				$("#bgcontainer").css("height", ContainerHeight);
				$("#bgcontainer").css("width", ContainerWidth);
			}
		}
	}
	

	if($(window).width() < 990) {
		$("body").css("overflow-x", "visible");	
	} else {
		$("body").css("overflow-x", "hidden");
	}
	
	$("#login img.tab_login").click(function() {
		var LoginCssTop = parseInt($("#login").css("top"));
		var TopValue    = 0;		
		
		if(LoginCssTop < -75) {
			// Slide out
			TopValue = -75 + "px";
			var FormContent = $("#login .form").html();
			$("#login .txt").html(FormContent);		
						
			animatedClipValue = expandedClipValue;
		} else {
			// slide in
			TopValue = -200 + "px";				
			$("#login .txt").html("Klik hier om in te loggen");	
			
			animatedClipValue = collapsedClipValue;
		}
		
		$("#login").animate({
			top: TopValue,
			"clip":animatedClipValue	
		}, 1000);	
	});			
});

/*
 * Function for showing and hiding tabs on right side of website
 */

var bMoving = false;

function ShowTabContent(Element) {
	
	var CssClipDefaultValue = "rect(0px, 470px, 260px, 0px)";
	
	// Same values as in stylesheet.css
	var aCssClipValues = new Array();
	aCssClipValues[0] = "rect(0px, 54px, 99px, 0px)";   // Tab cosmetics
	aCssClipValues[1] = "rect(52px, 54px, 203px, 0px)"; // Tab home & interieur
	aCssClipValues[2] = "rect(109px, 54px, 260px, 0px)"; // Tab city & home wear
	
	if(!bMoving) {
		$("#tab_content .tab").each(function(i){
	
			if(this == Element.parentNode.parentNode) {
					var RightValue = parseInt($(this).css("right"));
	
					if(RightValue < -1) {
						// slide in
						RightValue = "-1px";
						$(Element.parentNode).css("clip",CssClipDefaultValue);
					} else {
						// slide out
						RightValue = "-417px";
					}
					
					var zIndexValue = 20;
			}	else {
					// slide out
					RightValue = "-417px";
					$(this).css("z-index", 25);
					var zIndexValue = 25;
			}
			
			bMoving = true;
			
			$(this).animate({
				right: RightValue	
			}, 1000, function(){ 
				$(this).css("z-index", zIndexValue); 
				
				if(RightValue == "-417px") {
					$(this).find(".content").css("clip",aCssClipValues[i]);		
				}
				
				bMoving = false;
			});
		});	 	
	}
}

function setImageGallery(aImages)
{
	for(var i = 0; i < aImages.length; i++)
	{
		if(aImages[i][0].length > 0) {
			$("ul.images").append("<li><span class=\"top\"></span><a href=\"" + aImages[i][1] + "\" rel=\"prettyPhoto[gallery]\" title=\"" + aImages[i][2] + "\"><img src=\"" + aImages[i][0] + "\" alt=\"" + aImages[i][2] + "\" /></a><span class=\"bottom\"></span></li>");		
		}
	}
    
    $("#content ul.images li:nth-child(4)").attr("class","last");
    $("#content ul.images li:last").attr("class","last");
}

function showProductTabsByLanguage(SiteLang)
{	
	switch(SiteLang) 
	{
		//case "NL"    :
		case "BE-FR" :
		case "FR"    :
		{
			$("#tab_content .city-homewear").hide();	
		}
		break;
		
		case "DE" :
		{
			$("#tab_content .home-interieur").hide();
			$("#tab_content .city-homewear").hide();		
		}
		break;
		
		case "BE-NL" :
		case "EN" : { /* show all */ } break;	
	}	
}



/* Menu rollin- and out */

$(document).ready(function() {
	$('#subnavigation li a').click(function(){
     return MenuRollIn($(this));
   });
})

function MenuRollOut(){
  $('#subnavigation li').each(function(){
    if($(this).attr("class") == 'current sub'){
      var HeightElement = $(this).find('ul');
      var Height = $(HeightElement)[0].scrollHeight;
          
      $(this).find('ul').css("overflow","hidden");
      $(this).find('ul').css("height","0px");
			
			$(this).find('span.bg-animate').animate({'height': Height + 'px'});
      $(this).find('ul').animate({'height': Height + 'px'}); 
       
    }
  });  
}

function MenuRollIn(ClickedElement){
  var CurrentLiElement =  $('#subnavigation li.current ul');

  var Url = ClickedElement.attr('href');
  
  if(ClickedElement.hasClass('subsubLink')){
    window.location.href = Url;
  } else {
    if(CurrentLiElement.length > 0){
    	$('#subnavigation li span.bg-animate').animate({'height': '0px'}); 
      CurrentLiElement.animate({'height': '0px'}, function(){
        window.location = Url;
      });
    } else {
      window.location.href = Url;  
    }
  }
  return false;
}

function resizeFlashObject(objHeight) 
{
	/* old situation
	if($("#" + objHeight.bannerId).length > 0 && objHeight.mediaHeight > 155) {
		$("#" + objHeight.bannerId + " embed").attr("height",objHeight.mediaHeight+10);	
		$("#" + objHeight.bannerId + " object").attr("height",objHeight.mediaHeight+10);	
	}
	*/
	
	if($("#" + objHeight.bannerId).length > 0) {
			$("#" + objHeight.bannerId + " embed").attr("height",objHeight.mediaHeight+10);	
			$("#" + objHeight.bannerId + " object").attr("height",objHeight.mediaHeight+10);	
	}
}

var bHomepageActive = false;
function showHomepage(currentLangISO) 
{    
	if(!bHomepageActive) {	
		bHomepageActive = true;
		
		var ContentURL = "/IManager/Content/11023/GEpw/mt9209/mx" + currentLangISO;
		
		$("#slideshow_home_container span.bumper").prepend("<img src=\"/pics/overlay_flash_home_" + currentLangISO + ".png\" alt=\"\" style=\"display: none;\" class=\"overlay currentLang\" />");
		
    $("#bumper_languages").fadeOut(500, function() { 
    	
    	var fadeInSpeed = 500;
    	var animationSpeed = 1500;    	
    	
    	$.get(ContentURL, "", function(data) {
    		var Content = $("#ajax-response").html(data);

			  var Navigation = Content.find('ul.mainnav');
	      $('#navigation.home').append(Navigation).hide().fadeIn(fadeInSpeed);	       

	      var Languages  = Content.find('.languages').hide();
	    	$('#header').append(Languages);  
	    	$('#header .languages').fadeIn(fadeInSpeed); 
	    	// set languages dropdown
	    	//$("#header .languages select").msDropDown();  
	    	
	    	
	    	var ContentHome  = Content.find('#ajaxcontent');
	    	$('#content_home').append(ContentHome).hide().fadeIn(fadeInSpeed);         	    	
	    	
	    	var Tabs = Content.find('#tab_content').hide();

	    	$('#slideshow_home_container').prepend(Tabs);
	    	showProductTabsByLanguage(currentLangISO);
	    	$('#tab_content').fadeIn(fadeInSpeed, function() {
	    	});
			}, 'html');


    	$("#flash.bumper").animate({'height': '490px'}, animationSpeed);      
     	  
     	if($.browser.msie && $.browser.version=="6.0") {  
      	$("#slideshow_home_container.bumper").animate({backgroundPosition: '(0px -10px)'}, animationSpeed);
      } else {
      	$("#slideshow_home_container.bumper").animate({backgroundPosition: '(0px -10px)'}, animationSpeed);	
      }    
      
      var imgOverlayBottomVal = "-44px";
      if($.browser.msie && $.browser.version=="6.0") {
      	imgOverlayBottomVal = "-35px";	
      }
      
      $("span.bumper img.overlay").animate({'bottom': imgOverlayBottomVal}, animationSpeed, function() {
      	$("#slideshow_home_container span.bumper img").hide();	
      	$("#slideshow_home_container span.bumper img.overlay.currentLang").show();
      });
			

			if($.browser.msie && $.browser.version=="6.0") {
				$("#site").css("height","auto");
				//setTimeout(function(){ $(window).trigger("resize"); alert("sized"); }, 2000)		
		  }

			
			/* fade effect, not in use because of black background by fading transparent images
      $("#slideshow_home_container span.bumper img.overlay.currentLang").fadeIn(100, function() {
      	$("#slideshow_home_container span.bumper img:last").fadeOut();
      });
      */
    });
  }
    return false;
}

var Flash = new CFlashObj("/media/banner.swf", "250", "155", "http://repos.imanager.nl/transparent.gif");
Flash.Check();

function loadBanner(BannerType, MediaSrc, Hyperlink, BannerId, BannerTarget, FlashId)
{
	Flash.SetTargetDiv(BannerId);
	Flash.Id = FlashId;
	Flash.AddParam('FlashVars', 'Type=' + BannerType + '&Src=' + MediaSrc + '&Hyperlink=' + Hyperlink + '&BannerId=' + BannerId + '&Target=' + BannerTarget);	
	Flash.SetMovie("/media/banner.swf");
	Flash.Write();	
	return false;
}


var toolTipCall = "<" + "script" + " type='text/javascript'>" + "setTooltip()" + "<" + "/script" + ">"; 
function setTooltip() 
{
  $('.errorMsg img').tooltip({
      track: true,
      delay: 0,
      showURL: false,
      bodyHandler: function() { 
        return $($(this).prev(".spanTooltip")).html(); 
      }
  });
}