﻿/**
 * chanel.js
 * @author Mazarine Digital
 */

/** STAT **/

jQuery.noConflict();
	
var orientation = window.orientation;

function scaleHorizontale(){
	//document.getElementById("view").setAttribute('content','initial-scale=1; minimum-scale=1.0; maximum-scale=1.0;');
}

function scaleVertical(){
	//document.getElementById("view").setAttribute('content','initial-scale=0.75; minimum-scale=0.75; maximum-scale=0.75;');
}

function orientationMove(orientation){
	switch(orientation){
		case 0:
			scaleVertical();
			break;
		case 90:
			scaleHorizontale();
			break;
		case -90:
			scaleHorizontale();
		break;
		case 180:
			scaleVertical();
			break;
	}
}

function loadFirst(){
	chanelFW.init();
	//chanelGallery.set('galerie', 'products', 1);
}

function windowResize(){
	chanelFW.pResize();
}

function goToLinkAlias() {
  chanelFW.goToLink();
}
	
window.onorientationchange = function(e){
	var orientation = window.orientation;
	orientationMove(orientation);
}
	
var urlToLoad = "";
var waitForWebtrends = function(url)
{
	urlToLoad = url;
	setTimeout( launchLink, 500 );
};

var launchLink = function()
{
	document.location.href=urlToLoad;
};

function stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,ch_scat1,ch_scat2,ch_prod,dl,pn_sku,tx_e){
	//alert('DCSext.ch_re",'+ch_re+',\r\n"DCSext.ch_lang",'+ch_lang+',\r\n"WT.cg_n",'+cg_n+',\r\n"WT.cg_s",'+cg_s+',\r\n"DCSext.ch_div",'+ch_div+',\r\n"DCSext.ch_cat",'+ch_cat+',\r\n"DCSext.ch_scat1",'+ch_scat1+',\r\n"DCSext.ch_scat2",'+ch_scat2+',\r\n"DCSext.ch_prod",'+ch_prod+',\r\n"WT.dl",'+dl+',\r\n"WT.pn_sku",'+pn_sku+',\r\n"WT.tx_e",'+tx_e+'');

	dcsMultiTrack("DCSext.ch_re",ch_re,"DCSext.ch_lang",ch_lang,"WT.cg_n",cg_n,"WT.cg_s",cg_s,"DCSext.ch_div",ch_div,"DCSext.ch_cat",ch_cat,"DCSext.ch_scat1",ch_scat1,"DCSext.ch_scat2",ch_scat2,"DCSext.ch_prod",ch_prod,"WT.dl",dl,"WT.pn_sku",pn_sku,"WT.tx_e",tx_e,"WT.clip_n",'',"WT.clip_ev",'');
    if ( ch_lang == "fr" ){
        /*if ( ch_scat2 == "W Register link" && ch_cat=="Fine Jewelry" ){
            trackingCode("129257");
        }
        if ( ch_scat2 == "W Register link" && ch_cat=="Watches" ){
            trackingCode("128440");
        }*/
        if ( ch_scat1 == "W Main Homepage" ){
            trackingCode("128439");
        }
        if ( ch_scat1 == "FJ Main Homepage" ){
            trackingCode("129256");
        }
    }
}

function trackingCode(idTrack){
	//console.log(idTrack);
	try
	{
		var oScript = document.createElement("SCRIPT");
		var ebRand = Math.random()+ ' ';
		ebRand = ebRand * 1000000;	
		var conversionURL = "HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&ActivityID=" + idTrack + "&rnd=" + ebRand;
		oScript.src = conversionURL;
		document.body.appendChild(oScript);
	}
	catch(e) {}
}

function openwin(name,myname,mywidth,myheight,mytool,mydir,mystatus,myscroll,myresize,mymenu) 
{
	mytop=Math.floor((screen.height/2) - (myheight/2));
	myleft=Math.floor((screen.width/2) - (mywidth/2));
	debute =window.open(name,myname,"toolbar="+mytool+",width="+mywidth+",height="+myheight+",directories="+mydir+",status="+mystatus+",scrollbars="+myscroll+",top="+mytop+",left="+myleft+",resizable="+myresize+",menubar="+mymenu)
}
function ShowPopupLegal(strLegalURL){
   openwin(strLegalURL,'legal',900,500,0,0,0,1,0,0);
}

// Fonction Stat2 

function stats_home(arg1,arg2) {
//alert(arg1+"+"+arg2);
	if(arg1=="HJ"){ 
		if(arg2=="a"){
			var type = "FJ Discover Haute Joaillerie quick link";
			stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,type,$('ch_prod').value,50);
		}else {
			var type = "FJ Discover Baroque quick link";
			stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,type,$('ch_prod').value,50);
		}
	} 

	if(arg1=="HH "){ 
		if(arg2=="a"){
			type = "W Discover J12 quick link";
			stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,type,$('ch_prod').value,50);
		}else if(arg2=="b") {
			type = "W Discover première quick link";
			stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,type,$('ch_prod').value,50);
		}else {
			type = "W Discover J12 CHROMATIC quick link";
			stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,type,$('ch_prod').value,50);
		}
	}

}

function orientationDetect(){
	try{
		var badOrientation = ( window.orientation == "90" || window.orientation == "-90" );
		if( badOrientation ){ 
			$('mobileOrientationWarning').style.display = "block";
		}else{ 
			$('mobileOrientationWarning').style.display = "none";
		}
		return badOrientation;
	}catch(e){};
	
	return true;
}

function formatJapNumber(number){

		// var number = "#"+number;
		// var number = number+15418650650;
		var separator = separator || ",";
	
		number = number.toString()
			.split("").reverse().join("")
			.replace(/(\d{3})/g, "$1" + separator)
			.split("").reverse().join("");
			
		number = number.split("");
		number = number.join("");

		var firstV = number.split("");
		
		if( firstV[0] == ",")
		{
			firstV[0] = "";	
		}
		
		number = firstV.join("");
		
		return number;
	}

function stats_film(ch_prod_film){
	if($('cg_s') && $('cg_s').value != ""){cg_s=$('cg_s').value;}
	if($('ch_cat') && $('ch_cat').value != ""){ch_cat=$('ch_cat').value;}
	var ch_scat1 = $('ch_scat1').value
	var ch_scat2 = $('ch_scat2').value

	if(ch_prod_film == "start" || ch_prod_film == "end"){
		//alert('DCSext.ch_re",'+ch_re+',\r\n"DCSext.ch_lang",'+ch_lang+',\r\n"WT.cg_n",'+cg_n+',\r\n"WT.cg_s",'+cg_s+',\r\n"DCSext.ch_div",'+ch_div+',\r\n"DCSext.ch_cat",'+ch_cat+',\r\n"DCSext.ch_scat1",'+ch_scat1+',\r\n"DCSext.ch_scat2",'+ch_scat2+',\r\n"DCSext.ch_prod",'+ch_scat2+' '+ch_prod_film+',\r\n"WT.dl",50,\r\n"WT.clip_n",'+ch_scat2+',\r\n"WT.clip_ev",'+ch_prod_film+'');
		dcsMultiTrack("DCSext.ch_re",ch_re,"DCSext.ch_lang",ch_lang,"WT.cg_n",cg_n,"WT.cg_s",cg_s,"DCSext.ch_div",ch_div,"DCSext.ch_cat",ch_cat,"DCSext.ch_scat1",ch_scat1,"DCSext.ch_scat2",ch_scat2,"DCSext.ch_prod",ch_scat2+' video '+ch_prod_film,"WT.dl",50,"WT.clip_n",ch_scat2,"WT.clip_ev",ch_prod_film);
	}else{
		//alert('DCSext.ch_re",'+ch_re+',\r\n"DCSext.ch_lang",'+ch_lang+',\r\n"WT.cg_n",'+cg_n+',\r\n"WT.cg_s",'+cg_s+',\r\n"DCSext.ch_div",'+ch_div+',\r\n"DCSext.ch_cat",'+ch_cat+',\r\n"DCSext.ch_scat1",'+ch_scat1+',\r\n"DCSext.ch_scat2",'+ch_scat2+',\r\n"DCSext.ch_prod",'+ch_scat2+' '+ch_prod_film+',\r\n"WT.dl",50,\r\n"WT.clip_n",'+ch_scat2+'');
		dcsMultiTrack("DCSext.ch_re",ch_re,"DCSext.ch_lang",ch_lang,"WT.cg_n",cg_n,"WT.cg_s",cg_s,"DCSext.ch_div",ch_div,"DCSext.ch_cat",ch_cat,"DCSext.ch_scat1",ch_scat1,"DCSext.ch_scat2",ch_scat2,"DCSext.ch_prod",ch_scat2+' video '+ch_prod_film,"WT.dl",50,"WT.clip_n",'',"WT.clip_ev",'');
	}
}

/**
 * IE detection
 * @returns true / false on IE or IE 6 detection
 * @type Boolean
 */
var isIE = /*@cc_on!@*/!1;

function isIpad(){
	
	if( navigator.userAgent.match(/iPad/i) != null ) 
		return true;
	else
		return false;
}

function isPhone(){
	if( navigator.userAgent.match(/iPhone/i) != null) 
		return true;
	else
		return false;
}

function isAndroid(){
	if( navigator.userAgent.match(/Android/i) != null) 
		return true;
	else
		return false;
}

function isBlackberry(){
	if( navigator.userAgent.match(/BlackBerry/i) != null) 
		return true;
	else
		return false;
}

function isPlayBook(){
	if( navigator.userAgent.match(/PlayBook/i) != null) 
		return true;
	else
		return false;
}

function isRIM(){
	if( navigator.userAgent.match(/RIM/i) != null) 
		return true;
	else
		return false;
}

function isMobile(){
	if( isIpad() || isPhone() || isAndroid() || isPlayBook() || isBlackberry() || isRIM() )
		return true;	
	else
		return false;
}

function ie6(){
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);

	if(strChMid.indexOf("MSIE 6") != -1) return true;
	else return false;
}

function ie7(){
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);

	if(strChMid.indexOf("MSIE 7") != -1) return true;
	else return false;
}

/**
 * REM : charger le statemanager.js avant chanel.js
 */
//var StateManager = EXANIMO.managers.StateManager; //DEEPLINK


/**
 * chanelFW
 * chanel FrameWork
 * @author Nad
 */

var chanelFW = {

	defaultDocSize : 1256, lastDocSize : 0, actualDocSize : null, resVersion : null,
	anchors: [], deepL:[],
	init : function()
	{
		// si js active et URL sans deeplink alors on redirige vers le deeplink
		/*if(decodeURIComponent(location.href.split('#')[0]) != basehref + siteloc)
		{
			var fragment = decodeURIComponent(location.href).split('#')[0].replace(basehref+siteloc,"");
			top.location.href = basehref+siteloc+"#"+fragment;
		}*/ //DEEPLINK

		if(isIE && $('noflash'))
			if(location.href.split('#')[1] == "" || location.href.indexOf('#') == -1)
				$('noflash').style.display = 'none';

		this.screenSize();
		//this.anchorProcess(); //DEEPLINK
		this.pResize();
	},
	screenSize : function()
	{
		var screenWidth = screen.width;
		var screenHeight = screen.height;

		if(screenWidth<this.defaultDocSize || isMobile())
		{
			var changeTo ='small';
			this.actualDocSize = 1000;
			this.resVersion = "Small";
		}
		else
		{
			var changeTo ='wide';
			this.actualDocSize = 1256;
			this.resVersion = "Big";
		}
		
		if (this.lastDocSize!=this.actualDocSize)
		{
			/*StateManager.initialize();
			StateManager.defaultStateID = 'defaultState';*/ //DEEPLINK

			this.changeLayout(changeTo);
			this.lastDocSize=this.actualDocSize;

			_$('loading').style.display = 'block';
			_$('loading').style.display = 'none';
			//eventListener('accueil',true); //DEEPLINK
			
			eventListener(document.getElementById('pagename').value,true);
			/*
			var params = new Array();
			params['page'] = document.getElementById('pagename').value;
			document.getElementById('chargement').style.display = "none";
			eventListener(params['page'],true,target);
			 */
		}
	},
	/* page resize */
	pResize : function(){
		
		var docWidth = document.body.offsetWidth || document.documentElement.offsetWidth;
		var docHeight = window.innerHeight || document.documentElement.clientHeight;
		
		if(this.actualDocSize == 1256){
			if(docWidth<1256 || isMobile() ) {
				if( isMobile() ){
					$('globaldiv').style.left = "0px";
					$('globaldiv').style.marginLeft = "auto";
				}else{
					$('globaldiv').style.left = "0px";
					$('globaldiv').style.marginLeft = "0px";
				}
			} else {	
				$('globaldiv').style.left = "50%";
				$('globaldiv').style.marginLeft = "-628px";
			}
			if(docHeight<768 || isMobile() ) {
				$('globaldiv').style.top = "0px";
				$('globaldiv').style.marginTop = "0px";
			} else {
				$('globaldiv').style.top = "50%";
				$('globaldiv').style.marginTop = "-384px";
			}
		}else{
			if(docWidth<1000 || isMobile() ) {
				if( isMobile() ){
					$('globaldiv').style.left = "0px";
					$('globaldiv').style.marginLeft = "auto";
				}else{
					$('globaldiv').style.left = "0px";
					$('globaldiv').style.marginLeft = "0px";
				}
			} else {
				$('globaldiv').style.left = "50%";
				$('globaldiv').style.marginLeft = "-500px";
			}
			if(docHeight<582 || isMobile() ) {
				$('globaldiv').style.top = "0px";
				$('globaldiv').style.marginTop = "0px";
			} else {
				$('globaldiv').style.top = "50%";
				$('globaldiv').style.marginTop = "-291px";
			}
		}
	},

	/* changement du styles des elements concernes */
	applyChange: function(cstyle)
	{
		_$('centerdiv').className = cstyle;
		_$('productlist').className = cstyle;

		var li1 = _$('galerie').getElementsByTagName('li');
		var img1 = _$('galerie').getElementsByTagName('img');
		var img2 = _$('products').getElementsByTagName('img');
		for(var i=0;i<img1.length; i++)
		{//positionnement <li>
			li1[i].className = cstyle;
			img1[i].className = cstyle;
			img2[i].className = cstyle;
		}
	},

	// changeLayout is based on setActiveStyleSheet function by Paul Sowdon
	// http://www.alistapart.com/articles/alternate/
	changeLayout: function(description)
	{
	   var links = document.getElementsByTagName('link');
	   for(var n = 0; n < links.length; n++)
	   {
		   	if(links[n].getAttribute('rel').indexOf('style') != -1 && links[n].getAttribute('title'))
		   	{
		   		links[n].disabled = true;
		   		if(links[n].getAttribute('title') == description){ 
					links[n].disabled = false;
				}
		   	}
	   }
	},

	/* Appel des pages en Ajax */
	geAjaxtContent: function(val,target)
	{
		document.getElementById('chargement').style.display = "block";

		var contenuDetail = RemoteListe;
		contenuDetail.init('targetElement', target);
		var page = val;
		//alert('Vincent'+val);
		var ajaxTab = new Array;
		//alert("TEST PAGE" + page);
		
		ajaxTab['ajaxoutput']	= 'true';
		contenuDetail.methodToUse = 'GET';
		
		if( isIE ){
			var comp = page.split(basehref);
			var tmpSplit = comp[1].split("/");
			for(i=0; i<tmpSplit.length; i++){
				tmpSplit[i] = encodeURIComponent(tmpSplit[i]);
			}
			page = basehref;
			page += tmpSplit.join("/");
			// alert(page);
		}
		
		contenuDetail.getXmlList(page, ajaxTab);

		contenuDetail.completeTsk = function()
		{// cette fonction doit etre presente qd on appelle complete()

			loadFirst();
			var params = new Array();
			params['page'] = document.getElementById('pagename').value;
			document.getElementById('chargement').style.display = "none";
			eventListener(params['page'],true,target);
		}
		contenuDetail.complete();
	},


	/* appropriation des liens et modificiation pour le deep link et actions js speciales */
	anchorProcess: function()
	{
		this.anchors = [];
		if(this.anchors.length < 1)
		{
		}

		this.anchors = window.document.getElementsByTagName('a');

		var currentAnchor;

		for(var i = 0; i < this.anchors.length; i++)
		{
			currentAnchor = this.anchors[i];
			if(currentAnchor.name != '' && currentAnchor.name.indexOf('|') != -1)
			{
				currentAnchor.pos 						= i;
				currentAnchor.link 						= decodeURIComponent(currentAnchor.href);
				currentAnchor.functiononclick = currentAnchor.onclick;
				currentAnchor.style.cursor 		='pointer';
				currentAnchor.onTarget 				= currentAnchor.name.split('|');

				var parseURL 	= currentAnchor.link.split("?");
				var getParam 	= "?"+parseURL[1];
				var dlTitle 	= parseURL[0].replace(basehref,'').replace(siteloc,'');
				var newTitle 	= dlTitle.replace(' ','-');

				this.deepL[newTitle] = currentAnchor;

				/*if (i==0)
				{
					StateManager.defaultStateID = newTitle;
				}*/ //DEEPLINK

				if (currentAnchor.onTarget[0] == 'js')
				{
					currentAnchor.href = currentAnchor.link;
					eval(currentAnchor.onTarget[1]);

					return false;
				}
				else
				{// deep link
					currentAnchor.onclick = function()
					{
						var parseURL = decodeURIComponent(this.href).split("?");
						var getParam = "?"+parseURL[1];
						var dlTitle = parseURL[0].replace(basehref,'').replace(siteloc,'');
						
						// Cause un problème de stack Overflow sur IE
						if(this.functiononclick != undefined)
						{
							this.functiononclick();
						}
						
						/*
						if(this.functiononclick == undefined)
						{
							this.functiononclick();
						}*/
						chanelFW.goToLink(dlTitle.replace(' ','-'));
						return false;
					}
				}
				currentAnchor.name = "";
			}
			else if(currentAnchor.className == "lien_news" && isIE)
		   {
					currentAnchor.onclick = function() { window.location.href = this.href; window.location.reload(); }
		   }
		}

		return;
	},
	goToLink: function(n)
	{
		//alert('test');
		if(this.deepL[n])
		{
			//alert('ancre'+n);
			//StateManager.setState(n); //DEEPLINK
			chanelFW.geAjaxtContent(this.deepL[n].link, this.deepL[n].onTarget[1]);
		}
		else
		{
			
			if(n)
			{		    
				//n=decodeURIComponent(n);
				
				
				if(n.substring(0,1) == "/")
				{
					n = n.substring(1);
				}

				var params = n.split("/");

				//StateManager.setState(n.replace(basehref,'').replace(siteloc,'')); //DEEPLINK
				//alert(basehref+siteloc+decodeURIComponent(n));
				//alert(2);
				chanelFW.geAjaxtContent(basehref+siteloc+n, "centerdiv");
				
			}
			else
			{			
			//alert(3);
				chanelFW.geAjaxtContent(basehref+siteloc, "centerdiv");
				// StateManager.setState("defaultState");
			}

		}
	}
}

/**
 * add Event
 * @author John Resig http://ejohn.org/blog/flexible-javascript-events/
 */
function addEvent( obj, type, fn )
{
	if (obj.addEventListener){
		obj.addEventListener( type, fn, false );
	}
	else if (obj.attachEvent  )
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		//console.log("on"+type );
		//console.log(obj[type+fn]);
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/**
 * getElementById
 */
function _$(id)
{
	return document.getElementById(id);
}


/**
 */
function getActual(o, type){
	if (type=='height') return (parseFloat((isIE)? o.currentStyle.height : getComputedStyle(o, null).height));
	if (type=='left') return (parseFloat((isIE)? o.currentStyle.left : getComputedStyle(o, null).left));
	if (type=='top') return (parseFloat((isIE)? o.currentStyle.top : getComputedStyle(o, null).top));
	if (type=='bottom') return (parseFloat((isIE)? o.currentStyle.bottom : getComputedStyle(o, null).bottom));
	if (type=='width') return (parseFloat((isIE)? o.currentStyle.width : getComputedStyle(o, null).width));
	if (type=='owidth') return parseFloat(o.offsetWidth);
	if (type=='margin') return (parseFloat((isIE)? o.currentStyle.margin : getComputedStyle(o, null).marginLeft));
	if (type=='bgimg') return ((isIE)? o.currentStyle.backgroundImage : getComputedStyle(o, null).backgroundImage);
}

/**
 */
var loadingDiv = {
	loadCall : 0,
	get : function(n){
		_$('loading').style.display = 'none';
		this.loadCall = this.loadCall + n;
		for (var i=0; i<this.loadCall;i++){
			_$('loading').style.display = 'block';
		}
	}
}

/**
 */
var chanelDetail = {
	btdetail : null, spans : null, alink : null,
	set : function(){
		if (_$('btdetail')==undefined) return false;
		this.btdetail = _$('btdetail');
		this.alink = this.btdetail.href;
		this.btdetail.removeAttribute('href');
		this.btdetail.onclick = this.openSide;
		this.spans = this.btdetail.getElementsByTagName('span');
	},
	openSide : function(){
		if (chanelDetail.spans[1].className=='off') {//open
			_$('productSheet').className = 'opened';
			chanelDetail.spans[0].className = 'off';
			chanelDetail.spans[1].className = '';
			chanelFW.geAjaxtContent(chanelDetail.alink, 'productdetail');
		} else {//close
			_$('productSheet').className = '';
			chanelDetail.spans[0].className = '';
			chanelDetail.spans[1].className = 'off';
		}
//		StateManager.setState('detail')
	},
	end: false
}

function ie6png(img){

	img.style.display = 'block';
	var imgName = img.src.toUpperCase();
	if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : "";
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		var imgStyle = "display:inline-block;" + img.style.cssText;
		if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		if (img.align == "right") imgStyle = "float:right;" + imgStyle;
//		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle	+ " style=\"width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='image');\"></span>";
		img.outerHTML = strNewHTML;
	}
	return;
}

function scrollHorizontal(value, element, slider) {
    element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth));
}

function scrollVertical(value, element, slider) {
    element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
}

Element.addMethods({
	removeAllClass: function(element) {
		var classArray = element.classNames().toArray();
		for (var index = 0, len = classArray.size(); index < len; ++index) {
			element.removeClassName(classArray[index]);
		}
		return element;
	}
});

function isMouseLeaveOrEnter(e, handler)
{
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler); // && typeof reltg != 'undefined'
}

function openSharePuzzle(){
	 new Ajax.Updater(
		'popin',
		basehref+siteloc+"?page=popin_puzzle_partager&ajaxoutput=true",
		{
			method: 'post',
			parameters: { collection: $('collectionRef').value, category: $('categoryRef').value },
			onSuccess: function(){
				$('popin').removeAllClass();
				$('popin').addClassName('partagerPopin');
				$('inline_popup').style.display = 'block';
			},
			onComplete: function(){
				if($('closePopinBtn')){
					Event.observe(
						'closePopinBtn',
						'click',
						function(e){
							$('inline_popup').style.display = 'none';
							Event.stop(e);
						},
						false
					);
				}
				eventListener("partager",false,"popin");
				loadFirst();
			}
		}
	);
	return false;
 }

function gotoAjax(arg){
	chanelFW.goToLink(arg);
	return false;
}

function ClosePuzzle(){
	$('inline_popup').style.display = 'none';
}

function getStats(arg, type){

	stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,$('ch_scat1').value+' Universe link','',50);	
	if( type == 0 )
	{
		chanelFW.goToLink(arg);
	}
	else if( type == 2 )
	{
		location.href = arg;
	}
	else
	{
		window.open(arg,"");
	}
	return false;
}
	
function goToLinkFlash(arg){
	
	var startTime = 0;

	if(arg == "right"){
		$('ch_scat2').value="FJ State of Mind";
		stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,'FJ State of Mind link','',50);
		film_id = 'Chanel_JOA_savoirfaire'; //esprit
	}else if(arg == "left"){
		$('ch_scat2').value="FJ The Collection";
		stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,'FJ The Collection link','',50);
		film_id = 'JOA_mixage_son'; //collection
	}else if(arg == "edition_exclu"){
		film_id = 'HH_collection_mixageson'; //edition exclusive
	}else if(arg.split(',')[0] == "expertise_horlo"){
		film_id = 'HH_expertise'; //expertise horlo
		startTime = arg.split(',')[1];
	}else if(arg.split(',')[0] == "audace"){
		film_id = 'Chanel_JOA_savoirfaire'; //expertise horlo
		startTime = arg.split(',')[1];
	}

	new Ajax.Updater(
		'popin',
		basehref+sitelocEncoded+"?page=popin_player_hj&film_id="+film_id+"&size="+chanelFW.resVersion+"&ajaxoutput=true",
		{
			method: 'post',
			parameters: {referer: window.location.href },
			onSuccess: function(){
				
			},
			onComplete: function(){
				var closelink = document.getElementById('closePopinBtn').cloneNode(true);
				document.getElementById('noflash').removeChild(document.getElementById('closePopinBtn'));
				//alert(encodeURIComponent(basehref+siteloc+"?page=popin_player_hj&film_id="+film_id+"&size="+chanelFW.resVersion+"&referer=")+escape(window.location.href)+encodeURIComponent("&ajaxoutput=true"));+"&referer="+window.location.href
				// Fonctionne en FR
				var seourlPlayer= encodeURIComponent(basehref+decodeURIComponent(siteloc)+"?page=popin_player_hj&film_id="+film_id+"&size="+chanelFW.resVersion+"&ajaxoutput=true");
				//var seourlPlayer= basehref+siteloc+"?film_id="+film_id+"&amp;page=popin_player_hj&amp;size="+chanelFW.resVersion+"&amp;ajaxoutput=true";
				//alert(seourlPlayer);
					
				if($('flashcontent')){
					var params = {
						quality: "high",
						scale: "noscale",
						wmode: "transparent",
						allowFullScreen: "true",
						allowscriptaccess: "always",
						bgcolor: "#000000"
					};
					var flashvars = {
						branch: "index/nav/home",
						seourl: seourlPlayer,
						siteXML: path_site+"_xml/site.xml",
						lang:siteloc.split('/')[0],
						startTime: startTime
					};
					var attributes = {
						id: "flashcontent",
						name: "flashcontent"
					};
					swfobject.embedSWF(path_site+"_swf/main.swf", "flashcontent", $('centerdiv').offsetWidth, $('centerdiv').offsetHeight, "9.0.124", path_site+"_swf/expressInstall.swf", flashvars, params, attributes);
				}
				$('popin').appendChild(closelink);

				if(!swfobject.getFlashPlayerVersion().major){
					$('alternateContent').style.display = 'none';
				}

				if($('closePopinBtn')){
					Event.observe(
						'closePopinBtn',
						'click',
						function(e){
						
							if( savech_scat1 != "" ) $("ch_scat1").value = savech_scat1;
							if( savech_scat2 != "" ) $("ch_scat2").value = savech_scat2;
							if( savech_prod != "" ) $("ch_prod").value = savech_prod;
							
							$('inline_popup').style.display = 'none';
							$('popin').innerHTML="";
																		
							Event.stop(e);
						},
						false
					);
				}
				
				$('popin').removeAllClass();
				$('popin').addClassName('playerPopin');
				$('inline_popup').style.display = 'block';
			}
		}
	);
	return false;
}

function shareMail(elmtFlash){
	$(elmtFlash).pauseVideo();
	document.getElementById('chargement').style.display = "block";
	new Ajax.Updater(
		'popin',
		encodeURI(basehref+siteloc+"?page=popin_mediaplayer_partager&ajaxoutput=true"),
		{
			method: 'post',
			parameters: { collection: $('level1').value, category: $('level2').value },
			onSuccess: function(){
				stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,$('ch_scat2').value,$('ch_scat2').value+' Film email link',50);
				$('popin').removeAllClass();
				$('popin').addClassName('partagerPopin');
				$('inline_popup').style.display = 'block';
				document.getElementById('chargement').style.display = "none";
			},
			onComplete: function(){
				if($('closePopinBtn')){
					Event.observe(
						'closePopinBtn',
						'click',
						function(e){
							$('inline_popup').style.display = 'none';
							Event.stop(e);
						},
						false
					);
				}
				eventListener("partager",false,"popin");
				loadFirst();
			}
		}
	);
	return false;
}

function shareBlog(urlFLV){
	new Ajax.Updater(
		'popin',
		encodeURI(basehref+siteloc+"?page=popin_mediaplayer_integrer&ajaxoutput=true"),
		{
			method: 'post',
			onSuccess: function(){
				stats(ch_re,ch_lang,cg_n,cg_s,ch_div,ch_cat,$('ch_scat1').value,$('ch_scat2').value,$('ch_scat2').value+' Film embed link',50);
				$('popin').removeAllClass();
				$('popin').addClassName('integrerPopin');
				$('inline_popup').style.display = 'block';
			},
			onComplete: function(){
				if($('closePopinBtn')){
					Event.observe(
						'closePopinBtn',
						'click',
						function(e){
							$('inline_popup').style.display = 'none';
							Event.stop(e);
						},
						false
					);
				}

				var playerVersion = 4;
				if(section == "joail"){
					if(ch_lang == "fr"){
						playerVersion = 1;
					}else if(ch_lang == "en-gb" || ch_lang == "en-us" ){
						playerVersion = 2;
					}else{
						playerVersion = 3;
					}
				}

				//$('codeMedia').value=$('mediaplayer_image_'+slider_mediaplayer.value).innerHTML;
				$('codeMedia').value=$('codeMedia').value.replace('%urlFLV%',urlFLV).replace('%playerVersion%',playerVersion).replace('%logo%',playerVersion);

				$('codeMedia').onclick = function(){
					this.select();
				}

				if($('media_copierBtn')){
					Event.observe(
						'media_copierBtn',
						'click',
						function(e){
							$('codeMedia').focus();
							$('codeMedia').select();
							CopiedTxt = document.selection.createRange();
							CopiedTxt.execCommand("Copy");
							Event.stop(e);
						},
						false
					);
				}
			}
		}
	);
	return false;
}

var timer;
function slideshow(imageOn) {
	if(imageOn==1){
		if($('image_1')){
			if( $('image_2')){
				new Effect.Fade('image_1', {
					duration: 0.5 ,
					afterFinish: function(){
						new Effect.Appear('image_2', {
							duration: 1.0,
							afterFinish: function(){
								setTimeout("slideshow(2)",4000);
							}
						});
					}
				});
			}
		}
	}else if(imageOn==2){
		if($('image_2')){
			if($('image_3')){
				new Effect.Fade('image_2', {
					duration: 0.5 ,
					afterFinish: function(){
						new Effect.Appear('image_3', {
							duration: 1.0,
							afterFinish: function(){
								setTimeout("slideshow(3)",4000);
							}
						});
					}
				});
			}else{
				new Effect.Fade('image_2', {
					duration: 0.5 ,
					afterFinish: function(){
						new Effect.Appear('image_1', {
							duration: 1.0,
							afterFinish: function(){
								setTimeout("slideshow(1)",4000);
							}
						});
					}
				});
			}
		}
	}else if(imageOn==3){
		if($('image_3')){
			new Effect.Fade('image_3', {
				duration: 0.5 ,
				afterFinish: function(){
					new Effect.Appear('image_1', {
						duration: 1.0,
						afterFinish: function(){
							setTimeout("slideshow(1)",4000);
						}
					});
				}
			});
		}
	}
}

if( isIE ){
	var oldtitle = document.title;
	var newtitle ;
	
	document.onpropertychange = function(){
		if(newtitle != null && typeof newtitle!="undefined" && newtitle.indexOf('#')!=-1){
			newtitle=newtitle.substring(0,newtitle.indexOf('#'));
		}
		if(oldtitle != newtitle && newtitle != '' && newtitle != null && typeof newtitle!="undefined"){
			oldtitle = newtitle;
			document.title = newtitle;
		}else if(oldtitle != newtitle && newtitle == ''){
		document.title = oldtitle;
		}
	}
}

function consolelog(txt){
	
	try{
		console.log(txt);
	}catch(e){
		return false;
	}
	
	return true;
}
var no_gt = "";
var trackChromatic = {
	"landing" : "156191",
	"univers" : "156192",
	
	"H2978" : "156193",
	"H2978_print" : "156194",
	
	"H2979" : "156195",
	"H2979_print" : "156196",
	
	"H2934" : "156197",
	"H2934_print" : "156198",
	
	"H2565" : "156199",
	"H2565_print" : "156200",
	
	"H2566" : "156201",
	"H2566_print" : "156202",
	
	"H2912" : "156203",
	"H2912_print" : "156204",
	
	"H2913" : "156205",
	"H2913_print" : "156206"
};



/* document.onload */
jQuery(document).ready(function(){
	
	if( isMobile() ){
		//orientationMove(orientation);
		ipad = false;
		/*ipad = new setIpad();
		orientationDetect();
		window.onorientationchange = orientationDetect;*/
	}
	
	jQuery.ajax({
		type: "GET",
		url: "http://www-staging.chanel.com/vk/no_gt/headerMaz.php",
	
		user:"chanelStagingGlobal",
		password:"la31ks!s",
		crossdomain:true,
		success: function(data){
			no_gt = encodeURIComponent(data);
			loadFirst();
		},
		error: function(jqXHR, textStatus, errorThrown){
			loadFirst();
		}
	});

	
	windowResize();
	
    jQuery('#list_link').mouseenter(function(){
        jQuery('ul', this).css('visibility', 'visible');
    });

    jQuery('#list_link').mouseleave(function(){
        jQuery('ul', this).css('visibility', 'hidden');
    });
	
	
});

function openPopin3(href){
	
	$('inline_popup3').style.display = 'block';
	$('contentPopin3').innerHTML = '<iframe src="'+href+'" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>';
	
	return false;
}
	
function closePopin3(){
	$('inline_popup3').style.display = 'none';	
	$('contentPopin3').innerHTML = "";
	
	return false;
}

function ebConversionTracker(conv) { 
	if( ch_lang == "en-us" ){
		try{console.log(conv);}catch(e){}
		var ebConversionImg = new Image(); 
		var ebConversionURL = "HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?"; 
		ebConversionURL += "cn=as&ActivityID="+conv+"&ns=1"; 
		ebConversionImg.src = ebConversionURL;
	}
}

