var a2dRandom = Math.random();

/* Javascript - Virgin Presse */

/***** Sommaire *****/
// 00 - Variables
// 01 - Utiles
// 02 - rollOver
// 03 - Popup
// 04 - isFrance (Inscription - Adresse)
// 10 - Menu volet
// 15 - Sous Menu User
// 20 - Layer Essentiel
// 25 - Cover panier
// 30 - Marquee
// 35 - Layer bonus
// 40 - Ecriture des flashs
// 45 - Mail to friend
// 50 - Liens externes SWF
// 55 - Layer TG
// 60 - Onglet How
// 70 - Images covers
// 80 - Slider
// 75 - Subnav
// 99 - onLoad
/*******************/

/***** 00 - Variables *****/
disableDocumentDomainSet = true;
var actURL = document.location.href;
var timeLayer;
var timeSMenu;
var isOpera = (navigator.userAgent.indexOf('Opera') == 55 || navigator.userAgent.indexOf('Opera') == 36 || navigator.userAgent.indexOf('Opera') == 0)? true : false ;

/***** 02 - rollOver *****/
var rollPart = 'ro-';
var onAdd = '-on';
function swapImage(monImg){
	//Evenement onmouse out, pour empecher l'inversion si survol au chargement
	if(!monImg.onmouseout && monImg.src.indexOf(rollPart) != -1){
		monImg.onmouseout = function(){ swapImage(monImg); }
	}
	//Extension
	imgExt = monImg.src.substring(monImg.src.lastIndexOf('.'));
	//Dossier+Nom
	imgNom = monImg.src.substring(0,monImg.src.lastIndexOf('.'));
	//Images On / Off
	imgOn = imgNom+onAdd+imgExt;
	if(imgNom.indexOf(onAdd) != -1){
		imgNom = imgNom.substring(0,imgNom.length-onAdd.length);
	}
	imgOff = imgNom+imgExt;
	//Si etat On > RollOff
	if(monImg.src.indexOf(onAdd) != -1){
		monImg.src = imgOff;
	} else { // Sinon RollOn
		monImg.src = imgOn;
	}
}

/***** 03 - Popup *****/
function popThis(url,nom,w,h,o){
	if(url.charAt(0) == '/'){
		url = BaseUrl+url;
	}
    thisPop = window.open(url,nom,'width='+w+',height='+h+','+o);
    thisPop.focus();
}
/***** 03 - Popup - Ajout HDS au 28/06/2006 *****/
function popRefreshOpener(){
    window.opener.location.href=window.opener.location.href;
}
function popRefreshOpenerToHref(href){
    window.opener.location.href=href;
}


/***** 04 - isFrance *****/
function isFrance(val){
    for(i=0; i<3; i++){
        if(val == 'FR'){
            $("#tdFR" + i).css({ display: ""});
        } else {
			$("#tdFR" + i).css({ display: "none" });
        }
    }
}

/***** 10 - Menu volet *****/
function SH_sublist(id){
	//Affiche ou masque le sous menu
	if ($("#parent" + id).hasClass("show")) {
		swapImage($("#parent" + id+" img").get(0));
		$("#parent" + id).removeClass("show");
	} else {
		swapImage($("#parent" + id + " img").get(0));
		$("#parent" + id).addClass("show");
	}
}

/***** 15 - Sous menu user *****/
var lastSMenu = '';
function S_SMenu(id){
	if(lastSMenu != ''){
		H_SMenu(lastSMenu);
	}
	// Affichage
	$("#"+id).css({ visibility : "visible"});
	rescueFrame(id,14);
	lastSMenu = id;
}

function H_SMenu(id){
	// Masquage
	$("#" + id).css({ visibility: "hidden" });
	endRescueFrame();
	lastSMenu = '';
}

var progressInterval;
var displaySpeed = 15;
function progressiveMenu(){
    var maskHeight = $('#smenBasket').get(0).offsetHeight;
    var basketHeight = $('#detailBasket').get(0).offsetHeight;
    if((maskHeight+displaySpeed) < basketHeight){
        $('#smenBasket').css({ height:(maskHeight+displaySpeed)});
        $('#detailBasket').css({ top: ((maskHeight+displaySpeed)-basketHeight)});
        rescueFrame('smenBasket',14);
    } else {
		$('#smenBasket').css({ height: ($('#detailBasket').get(0).offsetHeight + 8) });
		$('#detailBasket').css({ top: 0});
        rescueFrame('smenBasket',14);
        clearInterval(progressInterval);
        timeSMenu = setTimeout('H_SMenu("smenBasket");',4000);
        lastSMenu = 'smenBasket';
    }
}

function progressiveMenuEfi(){
    var maskHeight = $('#smenBasketError').get(0).offsetHeight;
    var basketHeight = $('#detailBasketError').get(0).offsetHeight;
    if((maskHeight+displaySpeed) < basketHeight){
    	$('#smenBasketError').css({ height: (maskHeight + displaySpeed) });
    	$('#detailBasketError').css({ top: ((maskHeight + displaySpeed) - basketHeight) });
        rescueFrame('smenBasketError',14);
    } else {
		$('#smenBasketError').css({ height: ($('#detailBasketError').get(0).offsetHeight + 8)});
		$('#detailBasketError').css({ top: 0 });
        rescueFrame('smenBasketError',14);
        clearInterval(progressInterval);
        timeSMenu = setTimeout('H_SMenu("smenBasketError");',4000);
        lastSMenu = 'smenBasketError';
    }
}

/***** 20 - Layer essentiel *****/
var isEssent = false;
function S_essentiel(posx,posy,produit,type){
	if(posx < 245){
		posx = 245;
	}
	clearTimeout(timeLayer);
	frameES = $('#essent').get(0);
	if(!frameES.onmouseout){
		frameES.onmouseout = function(){ timeLayer = setTimeout('H_essentiel();',500); }
		frameES.onmouseover = function(){ clearTimeout(timeLayer); }
	}
	//Décalage
	posx -= 245;
	//Placement
	frameES.style.left = posx+'px';
	if($('#giftZone').get(0)){
	    frameES.style.left = (posx+85)+'px';
	}
	frameES.style.top = posy+'px';
	
	// Chargement de la page
	isEssent = true;
	if(type == undefined){
		if($('#freeMagZone').get(0)){
			window.essent.location = BaseUrl+'/Includes/Modules/Essential/free.aspx?Issue_Id='+produit;
		} else if($('#giftZone').get(0)){
			window.essent.location = BaseUrl+'/Includes/Modules/Essential/essentialGift.aspx?Publication_Id='+produit;
		} else if($('#books').get(0)){
			window.essent.location = BaseUrl+'/Includes/Modules/Essential/essential.aspx?Book_Id='+produit;
		} else {
			window.essent.location = BaseUrl+'/Includes/Modules/Essential/essential.aspx?Issue_Id='+produit;
		}
	} else {
		switch(type){
			case 3:
				window.essent.location = BaseUrl+'/Includes/Modules/Essential/essential.aspx?Book_Id='+produit;
			break;
			case 2:
			case -1:
			default:
				window.essent.location = BaseUrl + '/Includes/Modules/Essential/essential.aspx?Issue_Id=' + produit;
			break;
		}
	}

	//affichage
	frameES.style.visibility = 'visible';
}

var backEssent = false;
function H_essentiel(){
	frameES = $('#essent').get(0);
	//affichage
	frameES.style.visibility = 'hidden';
	isEssent = false;
	if(!isCoverflow){
		window.history.back(-1);
		//window.history.back(-1);
	} else {
		backEssent = true;
	}
}
function H_Free(){
	frameES = $('#essent').get(0);
	//affichage
	frameES.style.visibility = 'hidden';
	isEssent = false;
}

/***** 25 - Cover panier *****/
var lastCover = '';
function S_cover(id){
	if(lastCover != ''){
		H_cover(lastCover);
	}
	$('#' + id + 'cover').css({ display: 'block' });
	lastCover = id;
}
function H_cover(id){
	$('#' + id + 'cover').css({ display: 'none' });
	lastCover = '';
}

/***** 30 - Marquee *****/
var timeMarquee;
function texteDefil(){
	
	var txtDefil = $('#marqueeMSG').get(0);
	var txtPos = txtDefil.style.left.replace('px','');
	var txtTaille = txtDefil.offsetWidth;
	var masqueTaille = $('#botMSG').get(0).offsetWidth;
	
	if(txtTaille+10 < Math.abs(txtPos)){
		txtPos = masqueTaille;
	} else {
		txtPos -= 2;
	}
	txtDefil.style.left=txtPos+"px";
}

/***** 35 - Layer bonus ******/
var bonusTime;
function S_bonus(){
	$('#bonusList').css({ visibility: 'visible' });
}

function H_bonus(){
	$('#bonusList').css({ visibility: 'hidden' });
}

/***** 40 - Ecriture des flashs *****/
function writeFlash(url,id,w,h,o,target){
	var tempFlashContent = '';
	var flashOptionsTab = new Array();
	flashOptionsTab = o.split('|');
	tempFlashContent += '<object id="'+id+'" type="application/x-shockwave-flash" data="'+url+'" width="'+w+'" height="'+h+'">\n';
	tempFlashContent += '\t<param name="movie" value="'+url+'" />\n';
	for(i=0; i<flashOptionsTab.length; i++){
		var tempParam = flashOptionsTab[i].split('#')[0];
		var tempValue = flashOptionsTab[i].split('#')[1];
		tempFlashContent += '\t<param name="'+tempParam+'" value="'+tempValue+'" />\n';
	}
	tempFlashContent += '</object>\n';
	if (!target) {
		document.write(tempFlashContent);
	}
	else {
		return tempFlashContent;
	}
}

/* Fonction ajouté le 28/09/06 pour affichage banniere */
//Write flash for no validation behaviour   
function writeFlashRunContent(chem,w,h,opt)
{
	if (opt) opt = "?"+opt;
	else opt = "";
	
	var ch = '';
    
    ch+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" align="middle" VIEWASTEXT>';
	ch+='<param name="allowScriptAccess" value="sameDomain" />';
	ch+='<param name="movie" value="'+chem+opt+'" />';
	ch+='<param name="quality" value="high" />';
	ch+='<param name="wmode" value="transparent" />';
	ch+='<embed src="'+chem+opt+'" quality="high" wmode="transparent" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />';
	ch+='</object>';
    document.write(ch);
}

/***** 45 - Mail to friend *****/
function mailToFrien(textmail){
	textmail = (textmail.charAt(0) == ' ')? textmail.substr(1) : textmail;
	window.location = 'mailto:?'+textmail+window.location.href;
}

/***** 50 - Liens externes SWF *****/

/*OLD
function flSwfLink(){
	window.location = BaseUrl+'/Publications/Editorial/CommentCaMarche.aspx';
}
function adlSwfLink(){
	window.location = BaseUrl+'/Publications/Editorial/CommentCaMarche.aspx';
}
function homeLauchDemo(){
	popThis('/Publications/Editorial/tryout.aspx','Tryout',800,600);
}

function homeGoToTryout(){
	window.location = BaseUrl+'/Client/Inscription/Confirmation.aspx';
}
*/

/***** 55 - Layer TG *****/
var addTabs = new Array();
function addLayered(title,type,src,opt1,opt2){
    if(title && title != '' && type && type != '' && src && src != ''){
		this.title = title;
		this.type = type;
		this.src = src;
		if(type == 'img'){
	        var tempImg = new Image();
			tempImg.src = src;
		}
		this.opt1 = opt1;
		this.opt2 = opt2;
		addTabs[addTabs.length] = this;
	}
}

var addTimer;
function layeredAdd(title,type,src,opt1,opt2){
    clearInterval(addTimer);
    if(!$('#layeredAdd').get(0)){
        var newLayereredAdd = document.createElement('div');
        newLayereredAdd.setAttribute('id','layeredAdd');
        document.body.appendChild(newLayereredAdd);
        $('#layeredAdd').css({ position:"absolute", height:"0", overflow:"hidden", bottom:"0", zIndex:"30" });
    }
    var elem = $('#layeredAdd').get(0);
    elem.style.left = '50%';
    var tgCh = '<div class="boxSilver" id="layeredTg"><div class="head"><div class="rd" id="layeredTG"><h6>'+title+'</h6><a class="closer" href="javascript:hideAdd();"></a></div></div><div class="sid"><div class="side">\n';
    switch(type){
        case 'img':
            tgCh += '<a href="'+opt1+'" target="'+opt2+'"><img src="'+src+'" alt="'+title+'" /></a>\n';
        break;
        case 'swf':
	        tgCh += '<object id="'+title+'" type="application/x-shockwave-flash" data="'+src+'" width="'+opt1+'" height="'+opt2+'">\n';
	        tgCh += '\t<param name="movie" value="'+src+'" />\n';
		    tgCh += '\t<param name="wmode" value="transparent" />\n';
	        tgCh += '</object>\n';
        break;
    }
    tgCh += '</div></div><div class="bot"><div class="rd"></div></div></div>\n';
    elem.innerHTML = tgCh;
	if(type == "swf"){
		elem.style.width = (opt1+22)+'px';
		addTimer = setInterval('showAdd();',25);
    } else {
		elem.getElementsByTagName('img')[0].onload = function(){ launchAdd(elem,elem.getElementsByTagName('img')[0].offsetWidth); };
    }
}
function launchAdd(obj,width){
	obj.style.width = (width+22)+'px';
	addTimer = setInterval('showAdd();',25);
}

var addSpeed = 15;
function showAdd(){
	var maskHeight = $('#layeredAdd').get(0).offsetHeight;
	var addHeight = $('#layeredTg').get(0).offsetHeight;
    var tempAdd = (maskHeight+addSpeed < addHeight)? addSpeed : addHeight-maskHeight;
    if(maskHeight < addHeight){
    	$('#layeredAdd').css({ height: (maskHeight + tempAdd) });
    } else {
        $('#layeredAdd').css({ height: addHeight});
        clearInterval(addTimer);
    }
}
function hideAdd(){
	$('#layeredAdd').css({ visibility: 'hidden' });
}

function fieldCleaner(elem){
   var message = elem.parentNode.getElementsByTagName('input')[0].value;
   if(elem.value == message){
    elem.value = '';
   }
}

/***** 60 - Onglet How *****/
var oldHowZone = -1;
function showHowZone(id){
	if(oldHowZone != -1){
		$("#"+oldHowZone).removeClass("on");
		$('#' + oldHowZone + 'Cont').css({ display: 'none' });
		oldHowZone = -1;
	}
	$("#" + id).addClass("on");
	$('#' + id + 'Cont').css({ display: 'block' });
	oldHowZone = id;
}

var oldHowLine = -1;
function showHowLine(elem){
	if(oldHowLine != -1){
		oldHowLine.className = '';
		oldHowLine = -1;
	}
	elem.className = 'on';
	oldHowLine = elem;
}

/***** 70 - Images covers *****/
currentCover = 0;
var isCoverflow = false;
function changeCovers(li){
	var index = parseFloat(li.substr(11));
	$("#coverFlowUl li").get(currentCover).className = "";
	$("#coverFlowUl li").get(index).className = "on";
	var newSrc = $("#"+li+" img").get(0).src.replace("/ThumbSmall","/Bigs");
	$("#coverFlowImg").get(0).src = newSrc;
	currentCover = index;
}

function S_coverFlow(produit){
	frameCF = $('#coverFlowFrame').get(0);
	window.coverFlowFrame.location = BaseUrl+'/Publications/Sommaire.aspx?Issue_Id='+produit;
	frameCF.style.visibility = 'visible';
	if(!$('#coverFlowOuter').get(0)){
		var outerObj = document.createElement('div');
		var outerElement = document.body.appendChild(outerObj);
		outerElement.id = 'coverFlowOuter';
		outerElement.onclick = H_coverFlow;
	}
	isCoverflow = true;
}
function S_coverFlowBook(produit) {
    frameCF = $('#coverFlowFrame').get(0);
    window.coverFlowFrame.location = BaseUrl + '/Livres/Sommaire.aspx?Book_Id=' + produit;
    frameCF.style.visibility = 'visible';
    if (!$('#coverFlowOuter').get(0)) {
        var outerObj = document.createElement('div');
        var outerElement = document.body.appendChild(outerObj);
        outerElement.id = 'coverFlowOuter';
        outerElement.onclick = H_coverFlow;
    }
    isCoverflow = true;
}
function H_coverFlow(){
	frameCF = $('#coverFlowFrame').get(0);
	//affichage
	frameCF.style.visibility = 'hidden';
	isEssent = false;
	//window.history.back(-1);
	if($('#coverFlowOuter').get(0)){
		$('#coverFlowOuter').get(0).parentNode.removeChild($('#coverFlowOuter').get(0));
	}
	isCoverflow = false;
}

// 80 - Slider
function slBuilder(o){
	var li = $("#slider li");
	if(li.length > 4){
		$(o).addClass("slideIt");
		var ul = $("#slider ul").get(0);
		o.ul = ul;
		ul.style.width = (li[0].offsetWidth*li.length)+"px";
		// Add tools
		o.p = document.createElement("div");
		o.p.className = "slideP";
		o.parentNode.insertBefore(o.p,o);
		o.p.o = o;
		o.n = document.createElement("div");
		o.n.className = "slideN";
		o.parentNode.insertBefore(o.n,o);
		o.n.o = o;

		// Events
		o.p.onmouseover = function(){ slLeft(this); };
		o.n.onmouseover = function(){ slRight(this); };
		o.p.onmouseout = o.n.onmouseout = function(){ clearTimeout(slTimer); };
	}

}
var slSpeed = 10;
var slActive = null;
var slTimer;
function slLeft(b){
	slActive = (b)? b : slActive;
	var n = slActive.o.ul.offsetLeft+slSpeed;
	if(n < 0){
		slActive.o.ul.style.left = n+"px";
		slTimer = setTimeout("slLeft();",40);
	} else {
		slActive.o.ul.style.left = "0";
		clearTimeout(slTimer);
	}
}
function slRight(b){
	slActive = (b)? b : slActive;
	var n = slActive.o.ul.offsetLeft-slSpeed;
	var m = -1*(slActive.o.ul.offsetWidth-slActive.o.offsetWidth);
	if(n > m){
		slActive.o.ul.style.left = n+"px";
		slTimer = setTimeout("slRight();",40);
	} else {
		slActive.o.ul.style.left = m+"px";
		clearTimeout(slTimer);
	}
}

/***** 99 - onLoad *****/
$(document).ready(function() {
	
	if ($('#searchZone').get(0)) {
		$('#searchZone input').get(1).onfocus = function() { fieldCleaner(this); }
	}
	if ($('#newsZone').get(0)) {
		$('#newsZone input').get(1).onfocus = function() { fieldCleaner(this); }
	}

	//Tri des div
	var divTable = new Array();
	var layerTable = new Array();
	var coverTab = new Array();
	divTable = document.getElementsByTagName('div');
	for (i = 0; i < divTable.length; i++) {
		// 20 - Layer essentiel 
		if (divTable[i].className == 'addLayer' || divTable[i].className == 'caller') {
			layerTable[layerTable.length] = divTable[i];
		}
		// 25 - Cover panier
		if (divTable[i].className == 'apercu') {
			coverTab[coverTab.length] = divTable[i];
		}
	}

	//table des images du document
	var imgTable = document.images;
	for (i = 0; i < imgTable.length; i++) {
		//Mais uniquement sur les images requierant un Rolliover
		if (imgTable[i].src.indexOf(rollPart) != -1 && imgTable[i].src.indexOf(onAdd) == -1) {
			imgTable[i].onmouseover = function() { swapImage(this) };
		}
	}


	// 10 - Mise en place du menu dépliant
	if ($('#menuleft').get(0)) {
		var i = 0;
		$("#menuleft ol").each(function() {
			this.parentNode.id = "parentList" + i;
			$("a", this.parentNode).get(0).id = "List" + i;
			//Ajout de l'evenement d'appel
			$("a", this.parentNode).get(0).onclick = function() { SH_sublist(this.id) }
			i++;
		});
	}

	// 15 - Sous menu User
	//User
	var reactImg;
	var reactDiv;
	if ($('#customer_account').get(0) && $('#smenUser').get(0)) {
		reactImg = $('#menUser').get(0);
		reactDiv = $('#smenUser').get(0);
		// Evenements
		reactImg.onmouseover = function() { S_SMenu('s' + this.id); }
		reactImg.onmouseout = function() { timeSMenu = setTimeout('H_SMenu(\'smenUser\');', 100); }
		reactImg.onmousemove = reactDiv.onmousemove = function() { clearTimeout(timeSMenu); }
		reactDiv.onmouseout = function() { timeSMenu = setTimeout('H_SMenu(\'smenUser\');', 100); }
	}
	// Basket
	if ($('#customer_basket').get(0) && $('#smenBasket').get(0) && $('#menBasket').get(0)) {
		reactImg = $('#menBasket').get(0);
		reactDiv = $('#smenBasket').get(0);
		// Evenements
		reactImg.onmouseover = function() { S_SMenu('s' + this.id); }
		reactImg.onmouseout = function() { timeSMenu = setTimeout('H_SMenu(\'smenBasket\');', 100); }
		reactImg.onmousemove = reactDiv.onmousemove = function() { clearTimeout(timeSMenu); }
		reactDiv.onmouseout = function() { timeSMenu = setTimeout('H_SMenu(\'smenBasket\');', 100); }


		// Déploie si add
		if (isAddBasket) {
			$('#smenBasket').css({ height: 0, visibility: 'visible' });
			progressInterval = setInterval('progressiveMenu();', 25);
		}

		// Déploie si erreur add efi
		if (isEfiErrorBasket) {
			$('#smenBasketError').css({ height: 0, visibility: 'visible' });
			progressInterval = setInterval('progressiveMenuEfi();', 25);
		}


	}


	// 20 - Affichage des les layers
	for (i = 0; i < layerTable.length; i++) {
		setAddLayer(layerTable[i]);
	}

	// 25 - Cover panier
	for (i = 0; i < coverTab.length; i++) {
		//Attribution des ID
		coverTab[i].id = 'apercu' + i;
		if (coverTab[i].getElementsByTagName('div')[0]) {
			coverTab[i].getElementsByTagName('div')[0].id = 'apercu' + i + 'cover';
			coverTab[i].onmouseover = function() { S_cover(this.id); }
			coverTab[i].onmouseout = function() { H_cover(this.id); }
		}
	}

	// 30 - Activation du marquee si présent
	if ($('#botMSG').get(0)) {
		//Initialisation
		$('#marqueeMSG').css({ left: $('#botMSG').get(0).offsetWidth }); ;
		timeMarquee = setInterval('texteDefil();', 50);
		//Ajout des événements
		$('#botMSG').get(0).onmouseover = function() { clearInterval(timeMarquee); }
		$('#botMSG').get(0).onmouseout = function() { timeMarquee = setInterval('texteDefil();', 50); }
	}

	// 35 - Layer bonus
	var bonus = $("#bonus").get(0);
	var bonusList = $("#bonusList").get(0);
	if (bonus && bonusList) {
		bonus.onmouseover = function() { S_bonus(); };
		bonus.onmouseout = function() { H_bonus(); };
		bonusList.onmouseout = function() { H_bonus(); };
		if (bonusList.offsetHeight > 250) {
			$("ul", bonusList).get(0).style.height = '250px';
			$("ul", bonusList).get(0).style.overflow = 'auto';
		}
	}

	// Add layer
	if (addTabs.length > 0) {
		for (i = 0; i < addTabs.length; i++) {
			layeredAdd(addTabs[i].title, addTabs[i].type, addTabs[i].src, addTabs[i].opt1, addTabs[i].opt2);
		}
	}

	// 60 - Onglet How
	if ($('#howItWorks').get(0)) {
		var i = 0;
		$('#howItWorks ul:first-child li').each(function() {
			this.id = 'ong' + i;
			var div = $('#howItWorks div').get(i-1);
			if (div && i>0) {
				this.onclick = function() { showHowZone(this.id); }
				div.id = 'ong' + i + 'Cont';
				div.style.display = 'none';
			} else {
				this.onclick = function(){
					document.location = this.getElementsByTagName("a")[0].href;
				}
			}
			i++;
		});
		if (document.location.search.indexOf('idMain') != -1) {
			var search = document.location.search;
			var idGlobal = search.substr(search.indexOf('idMain=') + 7).split('_');
			var idMain = idGlobal[0];
			var idSub = (idGlobal[1]) ? idGlobal[1] : null;
			showHowZone('ong' + idMain);
			if (idSub != null && idMain == '1') {
				showHowLine($('#howItWorks ol:first-child li').get(idSub));
			}
		} else {
			showHowZone('ong1');
		}
		$('#howItWorks ol:first-child h5').each(function() {
			this.onclick = function() { showHowLine(this.parentNode); }
		});
	}

	// 70 - Images covers
	if ($("#coverFlow").get(0) && $("#coverFlow li").get(0)) {
		$("#coverFlow img").get(0).id = "coverFlowImg";
		$("#coverFlow ul").get(0).id = "coverFlowUl";
		var i = 0;
		$("#coverFlowUl li").each(function() {
			this.id = "coverFlowLi" + i;
			this.onmouseover = function() { changeCovers(this.id); }
			i++;
		});
		changeCovers('coverFlowLi0');
	}

	// 80 - Slider
	var s = $("#slider").get(0);
	if (s) {
		slBuilder(s);
	}

	// 50 - Tabs
	$('div.tabs').each(function() {
		var setActive = null;
		new tabGroup(this, null);
		this.id = 'tabs' + i;
		$("ul:first-child li a", this).each(function() {
			if (actURL == this.href) {
				setActive = j;
			}
			this.parentNode.onmouseover = function() { $(this).addClass('hover'); }
			this.parentNode.onmouseout = function() { $(this).removeClass('hover'); }
		});
	});

	$("#latest span.media").each(function() {
		var p = this.parentNode;
		p.t = this;
		var b = p.getElementsByTagName("strong")[0];
		if (b) {
			this.style.marginLeft = (b.offsetWidth + 5) + "px";
		}
		p.onmouseover = function() { this.t.style.visibility = "visible"; }
		p.onmouseout = function() { this.t.style.visibility = "hidden"; }
	});
	
	// HDS Visio
	$(".HDSVisio").each(function(){
		$.HDSVisio.callWS(this);
	});
	
	// HDS Kiosque
	$(".HDSKiosque").each(function(){
		$.HDSKiosque.callWS(this);
	});
	
	// HDS Library
	$(".HDSLibrary").each(function(){
		$.HDSLibrary.callWS(this);
	});
	
	// HDS Coverflow
	$(".HDSCoverflow").each(function(){
		$.HDSCoverflow.callWS(this);
	});
	
	// HDS Accordion
	$(".HDSAccordion").each(function(){
		$.HDSAccordion.build(this);
	});

	// Platforms
	$("#ways").each(function(){
		$.Platforms.build(this);
	});

	// Singlesubmit
	// $.SingleSubmit.parse();
	var complink = $('#compatibilityLink').get(0);
	var complist = $('#compatibility').get(0);
	if (complink && complist) {
		$(complink).click(function(){
			if($(complist).hasClass("viewedlist")){
				$(complist).removeClass("viewedlist");
			} else {
				$(complist).addClass("viewedlist");
			}
		}).removeAttr("href");
		$(".closer",complist).click(function(){
			$(complist).removeClass("viewedlist");
		});
	}

});

function setAddLayer(item){
	var r = (item.className == "addLayer") ? item : item.getElementsByTagName("img")[0];
	// Récupération de l'ID
	idProduit = item.getElementsByTagName('a')[0].rel;
	// Events
	var pI = (item.className == "addLayer") ? /*r.parentNode.parentNode.parentNode.className*/false : r.parentNode.parentNode.parentNode.parentNode.className;
	if (pI != false) {
		var type = (pI.indexOf("MagItem") != -1) ? 2 : 3;
	} else {
		var type = -1;
	}
	r.id = idProduit;
	r.type = type;
	if (!r.onclick) {
		item.getElementsByTagName('a')[0].style.cursor = "pointer";
		r.onclick = function() { S_essentiel($(this).offset().left, $(this).offset().top, this.id, this.type); }
	}
}

function resizeWindows2000 () {
	if(document.location.href.indexOf("os=windows2000")!=-1) {
		window.resizeTo(850,750);
	}
}

/************************** Ajout 13/03/2007 ***************************/
var actURL = document.location.href;
var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;
var isIE8 = (navigator.userAgent.indexOf('MSIE 8') != -1)? true : false ;
var isW2000 = (navigator.userAgent.indexOf('Windows NT 5.0') != -1)? true : false;
var isSafari = (navigator.userAgent.indexOf('AppleWebKit') != -1)? true : false;

function rescueFrame(){
	if(isIE && !isIE7){
		var rsFrame = $('#rescueFrame').get(0);
		if (!rsFrame) {
			var rescueObj = document.createElement('iframe');
			var rescueElement = document.body.appendChild(rescueObj);
			rescueElement.id = 'rescueFrame';
			rescueElement.src = '/HDSDigital_Root/dummy.htm';
			rescueElement.style.position = 'absolute';
			rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '0';
			rescueElement.frameborder = '0';
		}
		var rescuedObj = $("#"+arguments[0]).get(0);
		$(rsFrame).css({
			zIndex: arguments[1],
			top: ($("#" + arguments[0]).offset().top + 8),
			left: $("#" + arguments[0]).offset().left,
			width: (rescuedObj.offsetWidth - 1),
			height: (rescuedObj.offsetHeight - 8),
			visibility: 'visible'
		});
	}
}
function endRescueFrame(){
	if(isIE && !isIE7){
		$('#rescueFrame').css({ visibility : 'hidden'});
	}
}

function rFrame(){
	if(isIE && !isIE7){
		var o = arguments[0];
		var parent = o.parentNode;
		var elem = $('iframe.rescue',parent).get(0);
		if(!elem){
			var frame = document.createElement('iframe');
			elem = parent.insertBefore(frame,arguments[0]);
			if(elem){
				elem.className = 'rescue';
				elem.style.position = 'absolute';
				elem.style.filter = 'alpha(opacity=0);';
			}
		}
		if(elem){
			elem.style.left = arguments[0].offsetLeft+'px';
			elem.style.top = arguments[0].offsetTop+'px';
			elem.style.width = arguments[0].offsetWidth+'px';
			elem.style.height = arguments[0].offsetHeight+'px';
		}
	}
}
function rFrameEnd(){
	if(isIE && !isIE7){
		var parent = arguments[0].parentNode;
		var frame = $('iframe.rescue',parent).get(0);
		var elem = parent.removeChild(frame);
	}
}

/****** 50 - Tabs *****/
var tabGroups = new Array();
function tabGroup(elem,current){
	this.elem = elem;
	this.current = current;
	tabGroups[tabGroups.length] = this;
}

function changeTab(index,tab){
	if(tabGroups[index].current != null && tabGroups[index].current != tab){
		piS('add',_('tabs'+index+'_'+tabGroups[index].current),'off');
		piS('del',_('tabs'+index,'ul',0,'li',tabGroups[index].current),'on');
	}
	piS('del',_('tabs'+index+'_'+tab),'off');
	piS('add',_('tabs'+index,'ul',0,'li',tab),'on');
	tabGroups[index].current = tab;
}


// ******************** HDS Visio * Start ******************** //
(function($) {
	$.extend({
		HDSVisio: {
			callWS: function(holder) {
				// Store config
				$.store(holder);

				// AJAX
				$(holder).addClass('HDSLoading').css({ opacity: 0 }).animate({ opacity: 1 }, parseInt(holder.params.opening));
				$.ajax({
					type: "POST",
					url: BaseUrl+"/Includes/WebServices/FrontPage.asmx/GetViewers",
					data: "{ ispress:"+holder.params.ispress+", isportal:"+holder.params.isportal+", ishome:"+holder.params.ishome+"}",
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data) {
						// Remove loader
						$(holder).removeClass('HDSLoading');
						var data = JSON.parse(data.d);
						$.HDSVisio.build(holder, data);
					},
					error: function(data) {
						// Remove loader
						$(holder).removeClass('HDSLoading').addClass('HDSError').html("<div class=\"message\">Erreur de chargement !</div>");
					}
				});
			},
			build: function(holder, data) {
				if(data.item.length > 0){
					
					document.visio = holder;
					holder.current = null;
					holder.data = data;
					
					// Create medias zone
					holder.medias = document.createElement("div");
					holder.medias.className = "medias";
					holder.appendChild(holder.medias);
					
					// Create thumbs zone
					if(data.item.length > 1){
						holder.thumbs = document.createElement("div");
						holder.thumbs.className = "thumbs";
						holder.appendChild(holder.thumbs);
					}
					
					// Create thumbs & media
					holder.items = new Array();
					for(var i = 0; i<data.item.length; i++){
						
						var index = holder.items.length;
						var item = new Object();
						
						// Thumb
						if(data.item.length > 1){
							if(data.config.thumbs.type == "image"){
								item.thumb = document.createElement("img");
								item.thumb.src = data.config.site+data.item[i].thumb;
							} else {
								item.thumb = document.createElement("div");
								item.thumb.innerHTML = i+1;
							}
							$(item.thumb).css({ opacity:0 }).delay(index*200).animate({ opacity:1}, holder.params.transition/4);
							item.thumb.index = index;
							item.thumb.holder = holder;
							item.thumb.onclick = function(){ $.HDSVisio.swap(this.holder,this.index); };
							holder.thumbs.appendChild(item.thumb);
						}
						
						// Media
						item.media = document.createElement("div");
						item.media.className = "media";
						$(item.media).css({ opacity:0 });
						if(data.item[i].swf == "true" || data.item[i].swf == true){
							item.media.innerHTML = $.flashobject(data.config.site+data.item[i].media, holder.params.width, holder.params.height,{wmode:"transparent"});
						} else {
							var img = document.createElement("img");
							img.src = data.config.site+data.item[i].media;
							item.media.appendChild(img);
						}
						// If has link
						if(data.item[i].link && data.item[i].link != "" && data.item[i].link != "#0"){
							var link = document.createElement("a");
							link.className = "link";
							link.setAttribute("href",data.item[i].link);
							if(data.item[i].target && data.item[i].target != ""){
								link.setAttribute("target",data.item[i].target);
							}
							item.media.appendChild(link);
						}
						item.media.index = index;
						item.media.holder = holder;
						holder.medias.appendChild(item.media);
						
						// Store item
						holder.items.push(item);
					}
					
					// Init auto swap vars and events
					if(holder.items.length > 1){
						holder.auto = true;		
						holder.timer = null;
						holder.onmouseover = holder.onmousemove = function(){ $.HDSVisio.stopswap(this); }
						holder.onmouseout = function(){ $.HDSVisio.startswap(this); }
					}
					
					// Display first
					$.HDSVisio.swap(holder,0);
				} else {
					$(holder).addClass('HDSError').html("<div class=\"message\">Aucun &eacute;l&eacute;ment &agrave; afficher.</div>");
				}
			},
			swap: function(holder,index){
				var holder = (!holder)? document.visio : holder;
				// Clear auto swapper
				clearTimeout(holder.timer);
				// Hide previous item if has
				if(holder.current != null){
					$(holder.items[holder.current].thumb).removeClass("active");
					$(holder.items[holder.current].media).animate({ opacity:0 }, holder.params.transition, function(){ $(this).css({ visibility:"hidden" }); });
				}
				// Show new item
				$(holder.items[index].media).css({ visibility:"visible" }).animate({ opacity:1 }, holder.params.transition);
				$(holder.items[index].thumb).addClass("active");
				holder.current = index;
				// Launch auto swap if enabled
				if(holder.auto == true && holder.items.length > 1){
					$.HDSVisio.autoswap(holder);
				}
			},
			autoswap: function(holder){
				var next = (holder.current+1 >= holder.items.length)? 0 : holder.current+1;
				holder.timer = setTimeout("$.HDSVisio.swap(null,"+next+");",holder.data.item[holder.current].duration*1000);
			},
			startswap: function(holder){
				holder.auto = true;
				$.HDSVisio.autoswap(holder);
			},			
			stopswap: function(holder){
				holder.auto = false;
				clearTimeout(holder.timer);
			}
		}
	});
})(jQuery);
// ******************** HDS Visio * End ******************** //

// ******************** HDS Kiosque * Start ******************** //
(function($) {
	$.extend({
		HDSKiosque: {
			callWS: function(holder) {
				// Store config
				$.store(holder);

				// AJAX
				$(holder).addClass('HDSLoading').css({ opacity:0 }).animate({ opacity: 1 }, parseInt(holder.params.opening));
				$.ajax({
					type: "POST",
					url: BaseUrl+"/Includes/WebServices/FrontPage.asmx/GetALaUne",
					data: "{ }",
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data) {
						// Remove loader
						$(holder).removeClass('HDSLoading');
						var data = JSON.parse(data.d);
						$.HDSKiosque.build(holder, data);
					},
					error: function(data) {
						var data = {
							config:{
								site:"http://www.relay.com",
								page:"/HDSDInternational-dev1/Front.Web.Relay/a-la-une.html",
								speed:"0.5",
								delay:"1"
							},
							texts:{
								title:"Zoom sur les \"Triple Play\"",
								subtitle:"&nbsp;",
								intro:"Le tarif uniforme des 29.90€ a fait son temps, entrez dans une nouvelle ère ! Capital décortique les nouveaux forfaits illimités à moins de 20€ et analyse les bagarres entre opérateurs. En attendant la prochaine guerre… celle des forfaits très haut débit."
							},
							mag:[
								{ id:"19277", img:"/Covers/Mediums/19277.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19285", img:"/Covers/Mediums/19285.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"17267", img:"/Covers/Mediums/17267.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19198", img:"/Covers/Mediums/19198.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19141", img:"/Covers/Mediums/19141.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"18926", img:"/Covers/Mediums/18926.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" }
							]
						}
						// Remove loader
						//$(holder).removeClass('HDSLoading').addClass('HDSError').html("<div class=\"message\">Erreur de chargement !</div>");
						$(holder).removeClass('HDSLoading');
						$.HDSKiosque.build(holder, data);
					}
				});
			},
			build: function(holder, data) {
				
				holder.data = data;
				
				// Contents
				var title = document.createElement("h1");
				title.className = "title";
				title.innerHTML = "<strong>&Agrave; la une :</strong> "+holder.data.texts.title;
				holder.appendChild(title);
				
				var text = document.createElement("div");
				text.className = "text";
				var string = (holder.data.texts.subtitle != "")? "<strong>"+holder.data.texts.subtitle+"</strong><br />" : "";
				string += holder.data.texts.intro+"<br />";
				text.innerHTML = string;
				holder.appendChild(text);
				
				
				// Build mags if has
				if(holder.data.mag.length > 0){
					
					// Products
					holder.mags = new Array();
					holder.current = null;
					
					holder.medias = 0;
					holder.loaded = 0;
					holder.built = false;
					
					var items = document.createElement("div");
					items.className = "items";
					holder.appendChild(items);
					// Mags
					for(var i = 0; i<holder.data.mag.length; i++){
						var random = Math.round(Math.random()*10000000);
						
						// Mag
						var mag = document.createElement("div");
						mag.index = i;
						mag.className = "mag";
						
						// Cover
						var cover = document.createElement("div");
						cover.className = "cover";
						var link = document.createElement("a");
						link.setAttribute("href",holder.data.mag[i].url);
						
						// Media
						mag.img = document.createElement("img");
						holder.medias ++;
						mag.img.mag = mag;
						mag.img.onload = function(){
							$.HDSKiosque.checkload(holder);
							// Default style
							$(this.mag).css({ width:0, opacity:0 });
							$(this).css({ width:0 });
						}
						mag.img.setAttribute("src",holder.data.config.site+holder.data.mag[i].img+"?r="+random);
						
						link.appendChild(mag.img);
						cover.appendChild(link);
						mag.appendChild(cover);
						
						// Caller
						var caller = document.createElement("div");
						caller.className = "addLayer";	
						caller.setAttribute("id",holder.data.mag[i].id);
						var lnk = document.createElement("a");
						lnk.setAttribute("href","#"+holder.data.mag[i].id);
						
						// Media
						mag.picto = document.createElement("img");
						holder.medias ++;
						mag.picto.onload = function(){
							$.HDSKiosque.checkload(holder);
							// Default style
							$(this).css({ width:0 });
						}
						mag.picto.setAttribute("src","/Relay_Root/RetailShops/Relay/fr-FR/Images/puces/layer.gif?r="+random);
						
						lnk.appendChild(mag.picto);
						caller.appendChild(lnk);
						mag.appendChild(caller);
						
						// Final
						items.appendChild(mag);
						holder.mags.push(mag);
						
						// Default style
						$(mag).css({ visibility:"hidden" });
						
						// Event
						setAddLayer(caller);
					}
					holder.built = true;
					
					// Launch first if all load
					if(holder.loaded == holder.medias){
						$.HDSKiosque.show(holder,0);
					}
					
					// Add tools if needed
					if(i > 1){
						// Style
						$(holder).addClass("HDSKiosqueTools");
						// Prev
						var prev = document.createElement("div");
						prev.className = "prev";
						holder.appendChild(prev);
						prev.onclick = function(){ $.HDSKiosque.prev(this.parentNode); }
						// Next
						var next = document.createElement("div");
						next.className = "next";
						holder.appendChild(next);
						next.onclick = function(){ $.HDSKiosque.next(this.parentNode); }
					}
					
				} else {
					$(holder).addClass("HDSKiosqueEmpty");
				}
				
			},
			show: function(holder,index){
				// If has current
				if(holder.current != null){
					var old = holder.mags[holder.current];
					$(old).animate({ marginLeft:0, width:0, opacity:"0" },holder.params.transition, function(){ $(this).css({ visibility:"visible" }); });
					$(old.img).animate({ width:0 },holder.params.transition);
					$(old.picto).animate({ width:0 },holder.params.transition);
				}
				var mag = holder.mags[index];
				$(mag).css({ visibility:"visible" }).delay(holder.params.transition/2).animate({ marginLeft:"-57px", width:"117px", opacity:"1" },holder.params.transition);
				$(mag.img).delay(holder.params.transition/2).animate({ width:"115px" },holder.params.transition);
				$(mag.picto).delay(holder.params.transition/2).animate({ width:"30px" },holder.params.transition);
				// Store current
				holder.current = index;
			},
			checkload:function(holder){
				holder.loaded ++;
				if(holder.built && holder.loaded == holder.medias){
					$.HDSKiosque.show(holder,0);
				}
				
			},
			prev:function(holder){
				var prev = (holder.current == 0)? holder.mags.length-1 : holder.current-1;
				$.HDSKiosque.show(holder,prev);
			},
			next:function(holder){
				var next = (holder.current == holder.mags.length-1)? 0 : holder.current+1;
				$.HDSKiosque.show(holder,next);
			}
		}
	});
})(jQuery);
// ******************** HDS Kiosque * End ******************** //

// ******************** HDS Library * Start ******************** //
(function($) {
	$.extend({
		HDSLibrary: {
			callWS: function(holder) {
				// Store config
				$.store(holder);

				// AJAX
				$(holder).addClass('HDSLoading');
				$.ajax({
					type: "POST",
					url: BaseUrl+"/Includes/WebServices/FrontPage.asmx/GetBookSeller",
					data: "{ }",
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data) {
						// Remove loader
						$(holder).removeClass('HDSLoading');
						var data = JSON.parse(data.d);
						$.HDSLibrary.build(holder, data);
					},
					error: function(data) {
						var data = {
							config:{
								site:"http://www.relay.com",
								speed:"0.5",
								delay:"1"
							},
							book:[
								{ id:"19277", author:"Rochette", img:"/Covers/Mediums/19277.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19285", author:"Gérard Huguenin", img:"/Covers/Mediums/19285.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"17267", author:"Jocelyne Ravenne-Fraysse", img:"/Covers/Mediums/17267.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19277", author:"Rochette", img:"/Covers/Mediums/19277.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"19285", author:"Gérard Huguenin", img:"/Covers/Mediums/19285.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" },
								{ id:"17267", author:"Jocelyne Ravenne-Fraysse", img:"/Covers/Mediums/17267.jpg", url:"http://relay.hds.localhost.actis.loc/HDSDInternational-dev1/Front.Web.Relay/capital/les-gaspillages-des-elus-locaux-numero-221-economie-finances-18310.html" }
							]
						}
						// Remove loader
						//$(holder).removeClass('HDSLoading').addClass('HDSError').html("<div class=\"message\">Erreur de chargement !</div>");
						$(holder).removeClass('HDSLoading');
						$.HDSLibrary.build(holder, data);
					}
				});
			},
			build: function(holder, data) {
				
				holder.data = data;
				
				// Build books if has
				if(holder.data.book.length > 0){
					
					// Products
					holder.books = new Array();
					holder.current = null;
					
					holder.medias = 0;
					holder.loaded = 0;
					holder.built = false;
					
					// Books
					for(var i = 0; i<holder.data.book.length; i++){
						var random = Math.round(Math.random()*10000000);
						
						// Mag
						var book = document.createElement("div");
						book.index = i;
						book.className = (i%2)? "book bookright" : "book bookleft";
						
						// Texts
						var texts = document.createElement("div");
						texts.className = "texts";
						
						// Title
						var title = document.createElement("a");
						var titletxt = document.createTextNode(holder.data.book[i].title);
						title.appendChild(titletxt);
						texts.appendChild(title);
						title.setAttribute("href",holder.data.book[i].url);
						
						// Authors
						var strong = document.createElement("strong");
						texts.appendChild(strong);
						var authors = holder.data.book[i].author.split(",");
						for(var j=0; j<authors.length; j++){
							var sep = (j == 0)? "" : ", ";
							var author = document.createElement("a");
							var authortxt = document.createTextNode(sep+authors[j]);
							author.appendChild(authortxt);
							strong.appendChild(author);
							var search = authors[j].split(" ").join("+");
							author.setAttribute("href",holder.data.config.site+"/recherche-livre-auteur/resultat-pour-"+search+".html");
						}
						
						book.appendChild(texts); 
						
						// Cover
						var cover = document.createElement("div");
						cover.className = "cover";
						var link = document.createElement("a");
						link.setAttribute("href",holder.data.book[i].url);
						
						// Media
						book.img = document.createElement("img");
						holder.medias ++;
						book.img.book = book;
						book.img.onload = function(){
							$.HDSLibrary.checkload(holder);
						}
						book.img.setAttribute("src",holder.data.config.site+holder.data.book[i].img+"?r="+random);
						
						link.appendChild(book.img);
						cover.appendChild(link);
						book.appendChild(cover);
						
						// Caller
						var caller = document.createElement("div");
						caller.className = "caller";	
						caller.setAttribute("id",holder.data.book[i].id);
						var lnk = document.createElement("a");
						lnk.setAttribute("href","#"+holder.data.book[i].id);
						
						// Media
						book.picto = document.createElement("img");
						holder.medias ++;
						book.picto.onload = function(){
							$.HDSLibrary.checkload(holder);
						}
						book.picto.setAttribute("src","/Relay_Root/RetailShops/Relay/fr-FR/Images/puces/layer.gif?r="+random);
						
						lnk.appendChild(book.picto);
						caller.appendChild(lnk);
						book.appendChild(caller);
						
						// Preview
						book.preview = document.createElement("div");
						book.preview.className = "preview";
						var open = document.createElement("a");
						open.className = "imaged";
						open.setAttribute("href","javascript:S_coverFlowBook("+holder.data.book[i].id+");");
						book.preview.appendChild(open);
						book.appendChild(book.preview);
						
						// Final
						holder.appendChild(book);
						holder.books.push(book);
						
						// Default style
						$(book).css({ left:"315px" });
						
						// Event
						setAddLayer(caller);
					}
					holder.built = true;
					
					// Launch first if all load
					if(holder.loaded == holder.medias){
						$.HDSLibrary.show(holder,0);
					}
					
					// Add tools if needed
					if(holder.books.length > 2){
						// Style
						$(holder).addClass("HDSLibraryTools");
						// Prev
						holder.prev = document.createElement("div");
						holder.prev.className = "prev";
						holder.appendChild(holder.prev);
						holder.prev.onclick = function(){ $.HDSLibrary.prev(this.parentNode); }
						$(holder.prev).css({ left:"-30px" });
						// Next
						holder.next = document.createElement("div");
						holder.next.className = "next";
						holder.appendChild(holder.next);
						holder.next.onclick = function(){ $.HDSLibrary.next(this.parentNode); }
					}
					
				} else {
					$(holder).addClass("HDSLibraryEmpty");
				}
			},
			checkload:function(holder){
				holder.loaded ++;
				if(holder.built && holder.loaded == holder.medias){
					$.HDSLibrary.show(holder,0);
				}
				
			},
			show: function(holder,index){
				// If has current
				if(holder.current != null){
					if(index > holder.current){
						// If has right
						if(index+1 < holder.books.length){
							var right = holder.books[index+1];
							$(right).css({ left:"445px" }).animate({ left:"155px" },holder.params.transition);
						}
						// Old right
						var oright = holder.books[holder.current+1];
						$(oright).css({ left:"155px" }).animate({ left:"-135px" },holder.params.transition);
						// Old
						var old = holder.books[holder.current];
						$(old).css({ left:"25px" }).animate({ left:"-265px" },holder.params.transition);
						// New
						var book = holder.books[index];
						$(book).css({ left:"315px" }).animate({ left:"25px" },holder.params.transition);
					} else {
						// If has right
						if(index+1 < holder.books.length){
							var right = holder.books[index+1];
							$(right).css({ left:"-135px" }).animate({ left:"155px" },holder.params.transition);
						}
						// Old right
						var oright = holder.books[holder.current+1];
						$(oright).css({ left:"155px" }).animate({ left:"445px" },holder.params.transition);
						// Old
						var old = holder.books[holder.current];
						$(old).css({ left:"25px" }).animate({ left:"315px" },holder.params.transition);
						// New
						var book = holder.books[index];
						$(book).css({ left:"-265px" }).animate({ left:"25px" },holder.params.transition);
					}
				} else {
					// First launch
					var book = holder.books[index];
					$(book).css({ left:"-135px" }).animate({ left:"25px" },holder.params.transition);
					// If has right
					if(index+1 < holder.books.length){
						var right = holder.books[index+1];
						$(right).css({ left:"315px" }).animate({ left:"155px" },holder.params.transition);
					}
				}
				// Store current
				holder.current = index;
			},
			prev:function(holder){
				if(holder.current > 0){
					$(holder.next).animate({ right:"2px" },holder.params.transition);
					if(holder.current-2 == 0){
						$(holder.prev).animate({ left:"-30px" },holder.params.transition);
					}
					$.HDSLibrary.show(holder,holder.current-2);
				}
			},
			next:function(holder){
				if(holder.current+2 < holder.books.length){
					$(holder.prev).animate({ left:"2px" },holder.params.transition);
					if(holder.current+4 >= holder.books.length){
						$(holder.next).animate({ right:"-30px" },holder.params.transition);
					}
					$.HDSLibrary.show(holder,holder.current+2);
				}
			}
		}
	});
})(jQuery);
// ******************** HDS Library * End ******************** //

// ******************** HDS Coverflow * Start ******************** //
(function($) {
	$.extend({
		HDSCoverflow: {
			callWS: function(holder) {
				// Store config
				$.store(holder);

				// AJAX
				$(holder).addClass('HDSLoading').css({ opacity:0 });
				$.ajax({
					type: "POST",
					url: BaseUrl+"/Includes/WebServices/FrontPage.asmx/GetCoverFlow",
					data: "{ ItemId:"+holder.params.id+", IsBook:"+holder.params.book+"}",
					contentType: "application/json; charset=utf-8",
					dataType: "json",
					success: function(data) {
						// Remove loader
						var data = JSON.parse(data.d);
						$.HDSCoverflow.build(holder, data);
					},
					error: function(data) {
						var data = {
							covers:[
								{imgBig:"/Relay_Root/Excludes/Images/Covers/BigPopup/18367.jpg",imgSmall:"/Relay_Root/Excludes/Images/Covers/ThumbPopup/18367.jpg"},
								{imgBig:"/Relay_Root/Excludes/Images/Covers/Summary/BigPopup/18367_1.jpg",imgSmall:"/Relay_Root/Excludes/Images/Covers/Summary/ThumbPopup/18367_1.jpg"}
							]
						}
						// Remove loader
						//$(holder).removeClass('HDSLoading').addClass('HDSError').html("<div class=\"message\">Erreur de chargement !</div>");
						$.HDSCoverflow.build(holder, data);
					}
				});
			},
			build: function(holder, data) {
				
				holder.data = data;
				
				// Build books if has
				if(holder.data.covers.length > 0){
					var random = Math.round(Math.random()*10000000);
					
					// Products
					holder.covers = new Array();
					holder.thumbs = new Array();
					holder.current = null;
					
					holder.medias = 0;
					holder.loaded = 0;
					holder.built = false;
					
					// View
					holder.view = document.createElement("div");
					$(holder.view).css({ position:"relative", width:holder.params.width+"px",height:holder.params.height+"px",overflow:"hidden",border:"1px solid #000000" });				
					holder.view.className = "view";
					holder.appendChild(holder.view);
					var media = document.createElement("img");
					holder.view.appendChild(media);
					holder.medias ++;
					media.onload = function(){
						//$("#debug").get(0).innerHTML += "Loaded : View<br />";
						$(media).css({ position:"absolute", top:"0", left:"0" });
						$.HDSCoverflow.checkload(holder);
					}
					media.setAttribute("src",holder.data.covers[0].imgBig+"?r="+random);
					holder.covers[0] = media;
					
					// Covers
					if(holder.data.covers.length > 1){
						
						var thumbs = document.createElement("div");
						thumbs.className = "thumbs";
						$(thumbs).css({ padding:"10px 0 0 0" });
						holder.appendChild(thumbs);
						
						for(var i = 0; i<holder.data.covers.length; i++){
							
							// Thumbs
							var img = document.createElement("img");
							if(i == 0){
								img.className = "on";
							}
							holder.medias ++;
							img.index = i;
							img.holder = holder;
							img.onload = function(){
								//$("#debug").get(0).innerHTML += "Loaded : "+this.index+"<br />";
								$.HDSCoverflow.checkload(holder);
							}
							img.setAttribute("src",holder.data.covers[i].imgSmall+"?r="+random);
							thumbs.appendChild(img);
							$(img).css({ cursor:"pointer", margin:"0 2px 0 0" });
							holder.thumbs.push(img);
							// Events
							img.onclick = function(){ $.HDSCoverflow.load(this.holder,this.index); }
						}
						
						holder.built = true;
						
						// Launch first if all load
						if(holder.loaded == holder.medias){
							$.HDSCoverflow.load(holder,0);
						}
						
						// Add tools if needed
						if(holder.data.covers.length > 1){
							// Style
							$(holder).addClass("HDSCoverflowTools");
							// Prev
							holder.prev = document.createElement("div");
							holder.prev.className = "prev";
							holder.appendChild(holder.prev);
							holder.prev.onclick = function(){ $.HDSCoverflow.prev(this.parentNode); }
							$(holder.prev).css({ left:"-40px" });
							// Next
							holder.next = document.createElement("div");
							holder.next.className = "next";
							holder.appendChild(holder.next);
							holder.next.onclick = function(){ $.HDSCoverflow.next(this.parentNode); }
						}
					}
					
				} else {
					$(holder).addClass("HDSCoverflowEmpty");
				}
			},
			load:function(holder,index){
				if(!holder.covers[index]){
					
					var media = document.createElement("img");
					var random = Math.round(Math.random()*10000000);
					media.setAttribute("src",holder.data.covers[index].imgBig+"?r="+random);
					media.onload = function(){
						$.HDSCoverflow.show(holder,index);
						$(media).css({ position:"absolute", top:"0", left:"0" });
					}
					holder.covers[index] = media;
					holder.view.appendChild(media);
					
				} else if(holder.current != index){
					
					$.HDSCoverflow.show(holder,index);
					
				}
			},
			checkload:function(holder){
				holder.loaded ++;
				//$("#debug").get(0).innerHTML += "Check : "+holder.loaded+" / "+holder.medias+"<br />";
				if(holder.built && holder.loaded == holder.medias){
					$.HDSCoverflow.load(holder,0);
				}
			},
			show: function(holder,index){
				if($(holder).hasClass('HDSLoading')){
					$(holder).removeClass('HDSLoading').animate({ opacity: 1 }, parseInt(holder.params.opening));
				}
				if(index != holder.current){
					if(index > holder.current){
						// Old
						$(holder.covers[holder.current]).css({ left:"0" }).animate({ left:"-503px" },holder.params.transition);
						//New
						$(holder.covers[index]).css({ left:"503px" }).animate({ left:"0" },holder.params.transition);
						// Buttons
						$(holder.prev).animate({ left:"5px" },holder.params.transition);
						if(index+1 >= holder.data.covers.length){
							$(holder.next).animate({ right:"-40px" },holder.params.transition);
						}
					} else {
						// Old
						$(holder.covers[holder.current]).css({ left:"0" }).animate({ left:"503px" },holder.params.transition);
						//New
						$(holder.covers[index]).css({ left:"-503px" }).animate({ left:"0" },holder.params.transition);
						// Buttons
						$(holder.next).animate({ right:"5px" },holder.params.transition);
						if(index-1 < 0){
							$(holder.prev).animate({ left:"-40px" },holder.params.transition);
						}
					}
					//$("#debug").get(0).innerHTML += "Old : "+holder.covers[holder.current]+"<br />";
					//$("#debug").get(0).innerHTML += "New : "+holder.covers[index].src+"<br />";
				}
				$(holder.thumbs[holder.current]).removeClass("on");
				$(holder.thumbs[index]).addClass("on");
				// Store current
				holder.current = index;
			},
			prev:function(holder){
				if(holder.current > 0){
					$.HDSCoverflow.load(holder,holder.current-1);
				}
			},
			next:function(holder){
				if(holder.current+1 < holder.data.covers.length){
					$.HDSCoverflow.load(holder,holder.current+1);
				}
			}
		}
	});
})(jQuery);
// ******************** HDS Coverflow * End ******************** //

// Create flash object
(function($) {
	$.extend({
		flashobject:function(data,width,height,params){
			var string = "<object type=\"application/x-shockwave-flash\" data=\""+data+"\" width=\""+width+"\" height=\""+height+"\">\n";
			string += "\t<param name=\"movie\" value=\""+data+"\" />\n";
			if(params){
				for(var i in params){
					string += "\t<param name=\""+i+"\" value=\""+params[i]+"\" />\n";
				}
			}
			string += "</object>\n";
			return string;
		}
	});
})(jQuery);

// Get params
(function($) {
	$.extend({
		store: function(object) {
			if(!object.params){
				object.params = new Object();
				object.params.length = 0;
			}
			var cssclass = object.className.split(" ");
			// Create object entries
			for (var i = 0; i < cssclass.length; i++) {
				if (cssclass[i].indexOf(":") != -1) {
					// Store params
					var key = cssclass[i].split(":")[0];
					var value = cssclass[i].split(":")[1];
					object.params[key] = value;
					// Has at least one param stored
					object.params.length++;
					// Remove class
					$(object).removeClass(cssclass[i]);
				}
			}
			return object.params;
		},
		addparam:function(key,value,object){
			if(!object.params){
				object.params = new Object();
				object.params.length = 0;
			}
			object.params[key] = value;
			object.params.length++;
		}
	});
})(jQuery);

(function($) {
	$.extend({
		HDSAccordion:{
			build:function(object){
				// Parse & store childs
				object.items = new Array();
				object.current = null;
				var i = 0;
				$(">.item",object).each(function(){
					// Add closer
					this.closer = document.createElement("div");
					this.closer.className = "closer";
					var text = document.createTextNode("Fermer");
					this.closer.appendChild(text);
					this.appendChild(this.closer);
					// Add params
					this.index = i;
					this.head = $(".title",this).get(0);
					this.content = $(".cont",this).get(0);
					this.main = object;
					this.head.item = this.closer.item = this;
					// Style
					$(this.closer).css({ cursor:"pointer", position:"absolute", top:"5px", right:"10px" });
					$(this.head).css({ cursor:"pointer", paddingRight:$(this.closer).outerWidth(true)+"px" });
					$(this).css({ position:"relative" });
					// Default
					if($(this).hasClass("on") && object.current == null){
						object.current = this;
					} else {
						$.HDSAccordion.fold(this);
					}
					// Events
					this.head.onclick = function(){ $.HDSAccordion.unfold(this.item); }
					this.closer.onclick = function(){ $.HDSAccordion.fold(this.item); }
					
					object.items[object.items.length] = this;
					i++;
				});
				// Defautl opened
				/*if(object.current == null){
					$.HDSAccordion.unfold($(".item",object).get(0)); 
				}*/
			},
			unfold:function(_this){
				if(_this != _this.main.current){
					if(_this.main.current != null){
						$.HDSAccordion.fold(_this.main.current);
					}
					$(_this.content).stop(true,false).slideDown("slow");
					$(_this.closer).stop(true,false).fadeIn("slow");
					_this.main.current = _this;
				}
			},
			fold:function(_this){
				$(_this.content).slideUp("slow");
				$(_this.closer).fadeOut("slow");
				_this.main.current = null;
			}
		}
	});
})(jQuery);

// Plaforms
(function($) {
	$.extend({
		Platforms:{
			build:function(object){
				// Default
				var active = null;
				var linkszone = $("ul",object).get(0);
				$.addparam("linkszone",linkszone,object);
				$.addparam("current",null,object);
				var links = new Array();
				// Parse & store info
				var platforms = $("ul li",object).each(function(){
					$.store(this);
					$.addparam("parent",object,this);
					$.addparam("mention",this.title,this);
					this.removeAttribute("title");
					// Show content
					if($(this).hasClass("on")){
						active = this;
					}
					// Event
					$(this).click(function(){
						$.Platforms.show(this);
					});
					links.push(this);
				});
				$.addparam("links",links,object);
				// Prepare display zone
				var head = document.createElement("div");
				head.className = "otherways";
				$(object.parentNode).prepend(head);
				// List
				head.ul = document.createElement("ul");
				head.appendChild(head.ul);
				// Title
				head.text = document.createElement("h2");
				head.appendChild(head.text);
				$.addparam("head",head,object);
				// Activation
				if(active){
					$.Platforms.show(active);
				} else {
					$.Platforms.show($("ul li",object).get(0));
				}
			},
			show:function(_this){
				// Hide current
				var parent = _this.params.parent;
				if(parent.params.current){
					$("#"+parent.params.current.params.contentid).removeClass("showed");
					parent.params.current = null;
				}
				var mention = $("#waymention").get(0);
				if(mention){
					if(_this.params.mention){
						$(mention).html(_this.params.mention).show();
					} else {
						$(mention).hide();
					}
				}
				// Show new
				parent.params.current = _this;
				var text = $("#"+_this.params.contentid).addClass("showed").attr("title");
				$(parent.params.head.text).html(text);
				// Move active node
				var links = parent.params.links;
				var linkszone = parent.params.linkszone;
				var headul = parent.params.head.ul;
				for(var i=0; i<links.length; i++){
					if(links[i].params.contentid == _this.params.contentid){
						headul.appendChild(links[i]);
					} else {
						linkszone.appendChild(links[i]);
					}
				}
			}
		}
	});
})(jQuery);
