// Flash header Script
// Keep It Sample

if(window.attachEvent) //IE
{
	window.attachEvent("onload", _initPageFunction);
}
else if(window.addEventListener) //DOM
{
	window.addEventListener("load", _initPageFunction, false);
}

// Function used to initialize all functions used in page

function _initPageFunction()
{
    _initLogo();
    _initGirl();

    _initImagePreview();

    _initCountDown();

    _initLoginPageForgotPassword();    
	
	_highlightPage();
	
	/*pngfix();*/
	
	var IE6 = false /*@cc_on || @_jscript_version <= 5.7 @*/;
	if(IE6)
	{
		_fixLogin();
		
		_fixFlyLeft();
	}
    
}

// function that insert a link over the logo in the header of the page for SEO
function _initLogo()
{
	if(document.getElementById('contentLogo'))
	{
		var oDivLogo = document.getElementById('contentLogo');
		if(EcommercePageCulture == "fr-CA")
		{
		    if (oDivLogo) { oDivLogo.innerHTML = '<a id="votreLogo" href="/" title="keep it sample.ca&trade; pr&eacute;sente">keep it sample.ca&trade; pr&eacute;sente</a>'; }
		}
		else if(EcommercePageCulture == "es-MX")
		{
		    if (oDivLogo) { oDivLogo.innerHTML = '<a id="votreLogo" href="/" title="keep it sample.ca&trade; presents">keep it sample.ca&trade; presents</a>'; }
		}
		else
		{
		    if (oDivLogo) { oDivLogo.innerHTML = '<a id="votreLogo" href="/" title="keep it sample.ca&trade; presents">keep it sample.ca&trade; presents</a>'; }
		}
	}
}

function _initGirl()
{
    var divGirl = document.createElement("div");

  /*  if(document.getElementById('tblPromotion'))
    {
	    divGirl.id = "divGirl3";
    }else{
	    divGirl.id = "divGirl";
    }*/
	if(document.getElementById("productListingContainerKIS")){
		divGirl.id = "divGirl3";
	}
	else if(document.getElementById('tblPromotion'))
	{
		divGirl.id = "divGirl";
	}
	else
	{
		divGirl.id = "divGirl";
	}

    divGirl.innerHTML = "";

    if (document.getElementById('menuNavigationContent')) {
        document.getElementById('menuNavigationContent').appendChild(divGirl);
    }
	else if(document.getElementById('menuNavigationNotLogged'))
	{
		document.getElementById('menuNavigationNotLogged').appendChild(divGirl);
	}
}


/*****************************************/

var sIdImagePreview = "a#oucProductPictureViewer_lnkProductFrameLargerViewImage";
var initPictureZoom = false;

function _initImagePreview() {

    if (document.getElementById('oucProductPictureViewer_lnkProductFrameLargerViewImage') && !initPictureZoom) {
      $j(document).ready(function() {
        
        initPictureZoom = true;

        $j(sIdImagePreview).attr({ onclick: "" });

        var options = {
          zoomWidth: 512,
          zoomHeight: 512,
          xOffset: 5,
          yOffset: 0,
          position: "right",
          zoomType: "standard", // 'standard' , 'reverse'
          title: false,
          showEffect: "fadein", // 'show' , 'fadein'
          hideEffect: "hide", // 'hide' ,'fadeout'
          fadeinSpeed: "fast", // 'fast','slow','medium'
          //fadeoutSpeed: "fast", // 'fast','slow','medium')
          imageOpacity: 0.6,
          showPreload: false
        };

        $j(sIdImagePreview).jqzoom(options);
      });
};
}



/*************************************************/
/*********           COUNT DOWN          *********/

function _initCountDown() {

	var sEndDate;
	var sNowDate;


    if(document.getElementById('contentPageTopInformation') || document.getElementById('tblPromotion'))
    {

	if(document.getElementById('tblPromotion'))
	{
        	$j(document).ready(function() {
			
           		$j('.smallImageSettings').each(function(i){

				if($j(this).attr('CountDownDateNow'))
				{
					sEndDate = $j(this).attr('CountDownDatePromotionEnd');
   	    				sNowDate = $j(this).attr('CountDownDateNow');

					$j(this.offsetParent.offsetParent.offsetParent.getElementsByTagName('TD')[1]).find('.contentTextHighLightNow').countdown({
                				message: "This boutiques has ended. Missed!",
                				addZeros: true,
                				date: sEndDate,
   	       					now: sNowDate,
                				onTick: function(control, day, hrs, min, sec) {
                    					if (day > 1) {
									if(EcommercePageCulture == "en-US")
									{
										if(hrs > 1)
										{
											control.text(day + " days: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
										else
										{
											control.text(day + " days: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
									}
									else
									{
										if(hrs > 1)
										{
											control.text(day + " jrs: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
										else
										{
											control.text(day + " jrs: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
									}
                    			}
								else if(day == 1)
								{
									if(EcommercePageCulture == "en-US")
									{
										if(hrs > 1)
										{
											control.text(day + " day: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
										else
										{
											control.text(day + " day: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
									}
									else
									{
										if(hrs > 1)
										{
											control.text(day + " jour: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
										else
										{
											control.text(day + " jour: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
									}
								}else 
								{
									if(EcommercePageCulture == "en-US")
									{
										control.text(hrs + " hrs: " + min + " min: " + sec + " sec");
									}
									else
									{
										control.text(hrs + " h: " + min + " min: " + sec + " sec");
									}
                    			}
					
						}
            				});			  
				}


	    		});	   

        	});
	}

	if(document.getElementById('contentPageTopInformation'))
	{
		$j(document).ready(function() {

			sEndDate = CountDownDatePromotionEnd;
   	    		sNowDate = CountDownDateNow;

			$j('.divCountDownPromo').find('.contentTextHighlight').countdown({
                		message: "This boutiques has ended. Missed!",
                		addZeros: true,
                		date: sEndDate,
   	       			now: sNowDate,
                		onTick: function(control, day, hrs, min, sec) {
                    			if (day > 1) {
									if(EcommercePageCulture == "en-US")
									{
										if(hrs > 1)
										{
											control.text(day + " days: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
										else
										{
											control.text(day + " days: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
									}
									else
									{
										if(hrs > 1)
										{
											control.text(day + " jrs: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
										else
										{
											control.text(day + " jrs: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
									}
                    			}
								else if(day == 1)
								{
									if(EcommercePageCulture == "en-US")
									{
										if(hrs > 1)
										{
											control.text(day + " day: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
										else
										{
											control.text(day + " day: " + hrs + " hrs: " + min + " min: " + sec + " sec");
										}
									}
									else
									{
										if(hrs > 1)
										{
											control.text(day + " jour: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
										else
										{
											control.text(day + " jour: " + hrs + " h: " + min + " min: " + sec + " sec");	
										}
									}
								}else {
									if(EcommercePageCulture == "en-US")
									{
										control.text(hrs + " hrs: " + min + " min: " + sec + " sec");
									}
									else
									{
										control.text(hrs + " h: " + min + " min: " + sec + " sec");
									}
                    			}
					
				}
            		});


		});

	}
    }
}


function _initLoginPageForgotPassword() {
   /* var divPasswordForm = document.getElementById('contentPageLoginForgotPasswordForm'); 
    var divLoginMenu = document.getElementById('contentLoginPageMenuOptions');

    if (divPasswordForm)
    {
        topPos = divLoginMenu.offsetTop;
        divPasswordForm.style.top = topPos;
    }
*/
}

function loginPageForgotPasswordClick() {
    var divPasswordForm = document.getElementById('contentPageLoginForgotPasswordForm'); 
    
    
    if (divPasswordForm.style.display == 'block') {
        divPasswordForm.style.display = 'none';
    } else {
        divPasswordForm.style.display = 'block';
    }
}

/****************************************************
FUNCITON HIGHLIGHT PAGE

highlight the current page in the top navigation
******************************************************/
function _highlightPage()
{
	if(document.Form1 && document.getElementById("menuNavigationContent")) //if in a normal page of ecom and there is a main menu
	{
		var currentPage = document.Form1.action;
		if(currentPage.indexOf("?") > -1)
		{
			var currentPage = currentPage.substr(0, currentPage.indexOf("?"));
		}
		var menuLinks = document.getElementById("menuNavigationContent").getElementsByTagName("a");
		for(var i = 0; i < menuLinks.length; i++)
		{
			if(menuLinks[i].href.indexOf(currentPage) != -1)
			{
				menuLinks[i].style.backgroundPosition = "bottom";
			}
		}
		
		if(document.getElementById("productListingContainerKIS"))
		{
			document.getElementById("menuBoutiques").style.backgroundPosition = "bottom";
		}
	}
}

function changeCulture()
{
	if(EcommercePageCulture == "fr-CA")
	{
		window.location = _skCMSCurrentPage_enus;
	}
	else
	{
		window.location = _skCMSCurrentPage_frca;
	}
}

var clear="/ecom_theme/img/clear.gif" //path to clear.gif

function pngfix(){var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}}


function _fixLogin()
{
	if(document.Form1.action.indexOf("Login.aspx") > -1)
	{
		if(document.getElementById("contentPage"))
		{
			var content = document.getElementById("contentPage").firstChild;
			var newcontent = document.getElementById("pageAlign").appendChild(content);
			
			with(newcontent.style)
			{
				width = "680px";
				position="absolute";
				zIndex="2000";
				top="50%";
				left="50%";
				marginTop="-274px";
				marginLeft="-481px"
			}
			
			document.getElementById("contentShopSample").style.right = "0px";
			document.getElementById("contentShopSample").style.left = "239px";
		}
	}
}

function _fixFlyLeft()
{
	if(document.getElementById("leftMenuFly") && document.getElementById("leftMenu"))
	{
		var content = document.getElementById("flyProductLeftMenu")
		var target = document.getElementById("leftMenu").firstChild;
		
		if(target.className == "leftMenuAlign")
		{
			var newContent = target.appendChild(content);
			
			with(newContent.style)
			{
				position = "absolute";
				zIndex = "20000";
				marginLeft = "-20px";
				marginTop = "20px";
			}
		}
	}
}







