﻿var root = "http://2009.princecraft.com/";
var isIE6 = false;
var isIE = false;


/* feed menu */
function feedPrd(link,image,text){
	var listItem = link.parentNode;
	var divCtnr = link.nextSibling.firstChild;
	var boxCtnt = '';
	if (image) boxCtnt += '<a href="' + link.href + '" class="hdrPrdImg"><img src="' + image + '" alt=""></a>';
	boxCtnt += '<span class="hdrPrdBtn"><a href="' + link.href + '"><img src="/medias/communs/mstr_placeholder.gif" alt=""></a></span>';
	boxCtnt += '<h1>'+ link.innerHTML + "</h1>";
	if (text) boxCtnt += '<p>' + text + '</p>';
	if (isIE6 || isIE) boxCtnt += '<iframe class="navMask"></iframe>';
	divCtnr.innerHTML = boxCtnt;
	link.onmouseover = null;
}


/* barre actions (print, refer, taille texte) */
function imprimer(lang){
	if (window.print) { window.print(); } 
	else if (lang == "fr") { alert("Votre navigateur n'est pas compatible avec l'impression directe.\n\nPour imprimer, allez dans le menu Fichier de votre navigateur et choisissez \"Imprimer\"."); }
	else { alert("Your browser does not support direct printing.\n\nTo print, go to the File menu of your browser and select \"Print\"."); }
}

function refer(lang){
    window.open(root + "content/" + lang + "/send2afriend.aspx?LanguageID=" + lang + "&RefererUrl=" + encodeURIComponent(location.href), "", "width=586,height=330");
    return false;
}

function swapStyle(){
	var currentStyle = getActiveStyleSheet();
	switch(currentStyle) {
		case "larger":
			setActiveStyleSheet("largest");
			break;    
		case "largest":
			setActiveStyleSheet("normal");
			break;
		default:
			setActiveStyleSheet("larger");
			break;
	}
}

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		&& a.getAttribute("rel").indexOf("alt") == -1
		&& a.getAttribute("title")
		) return a.getAttribute("title");
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


/* onglets fiche produit */
function toggleSub(element){
	var ulBg = document.getElementById('prdSubTabBg');
	var pPlan = document.getElementById('pPlan');	
	var pPhotos = document.getElementById('pPhotos');
	var pVideo = document.getElementById('pVideo');
	
	switch(element){
		case 1:
			ulBg.className = 'clearfix plan';
			pPlan.style.display = 'block';
			pPhotos.style.display = 'none';
			pVideo.style.display = 'none';
			break;
		case 2:
			ulBg.className = 'clearfix photos';
			pPlan.style.display = 'none';
			pPhotos.style.display = 'block';
			pVideo.style.display = 'none';
			initCarousel();
			break;
		case 3:
			ulBg.className = 'clearfix video';
			pPlan.style.display = 'none';			
			pPhotos.style.display = 'none';
			pVideo.style.display = 'block';
			break;
	}
}
