/***************************************************************************
 *				javascript.js
 *				-------------
 *	Cree le		: 16 Mai 2007
 *	Derniere modif.	: 5 Octobre 2007
 *	Auteur		: Agence ici - Asselin Benoit
 *	Site		: http://www.agenceici.com/
 *
 ***************************************************************************/



var v_menuActive;
function menuDisplay(p_id) {
	if (p_id == v_menuActive) {
		Doc.id(v_menuActive).className = 'normal';
		v_menuActive = '';
	} else {
		Doc.id(v_menuActive).className = 'normal';
		v_menuActive = p_id;
		Doc.id(v_menuActive).className = 'active';
	}
	return false;
}



var v_imageActive = '1';
function imageDisplay(p_inc, p_src) {
	if (v_imageActive != p_inc) {
		Doc.id('product-image-min-'+ v_imageActive).className = 'normal';
		v_imageActive = p_inc;
		Doc.id('product-image-min-'+ v_imageActive).className = 'active';
		
		if (Doc.id('product-image-max').style.filter) { /* ie6 */
			Doc.id('product-image-max').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ p_src +'\',sizingMethod=\'image\')';
		} else {
			Doc.id('product-image-max').src = p_src;
		}
	}
}



var v_finishActive;
function finishDisplay(p_id, p_mode) {
	if (v_finishActive != p_id) {
		if (Doc.id(v_finishActive)) {
			Doc.id(v_finishActive).style.display = '';
		}
		v_finishActive = p_id;
		if (Doc.id(v_finishActive)) {
			Doc.id(v_finishActive).style.display = p_mode ? 'none' : '';
		}
	}
}



function enquiryCartAdd(p_id) {
	var v_finish_all = '';
	var v_finish_ids = '';
	for (var v_i = 0; v_i < document.getElementsByName('finish').length; v_i++) {
		v_finish_all += (v_finish_all != '') ? ('|') : ('');
		v_finish_all += document.getElementsByName('finish')[v_i].value;
		
		if (document.getElementsByName('finish')[v_i].checked) {
			v_finish_ids += (v_finish_ids != '') ? ('|') : ('');
			v_finish_ids += document.getElementsByName('finish')[v_i].value;
		}
	}
	Doc.id('enquiry-cart-mode').value = 'add';
	Doc.id('enquiry-cart-product-id').value = p_id;
	Doc.id('enquiry-cart-finish-all').value = v_finish_all;
	Doc.id('enquiry-cart-finish-ids').value = v_finish_ids;
	Doc.id('enquiry-cart-form').submit();
	return false;
}



function enquiryCartDel(p_id) {
	Doc.id('enquiry-cart-mode').value = 'del';
	Doc.id('enquiry-cart-product-id').value = p_id;
	Doc.id('enquiry-cart-finish-all').value = '';
	Doc.id('enquiry-cart-finish-ids').value = '';
	Doc.id('enquiry-cart-form').submit();
	return false;
}



function enquiryCartAddLite(p_id) {
	Doc.id('enquiry-cart-mode').value = 'add';
	Doc.id('enquiry-cart-product-id').value = p_id;
	Doc.id('enquiry-cart-finish-all').value = '';
	Doc.id('enquiry-cart-finish-ids').value = '';
	Doc.id('enquiry-cart-form').submit();
	return false;
}



function ClassFade(p_id, p_images) {
	this.id = p_id;
	this.imagesUrl = p_images;
	this.imagesLen = this.imagesUrl.length;
	this.imageFade = 0;
	this.imagesBgcolor = '#FFF';
	this.opacityStep = 2;
	this.opacityLevel = 100;
	this.timeNext = 0;
	this.timeMs = 10;
	this.firstRun = true;
	this.MsIE = (navigator.appName == 'Microsoft Internet Explorer') ? true : false;
	
	this.loadImages();
	this.zIndexCss();
	this.fade();
}
ClassFade.prototype = {
	addZero : function(nbr) {
		return (nbr < 10) ? ('0' + String(nbr)) : (String(nbr));
	},
	loadImages : function() {
		for (var v_i = 0; v_i < this.imagesLen; v_i++) {
			if (this.MsIE) {
				var v_img = window.document.createElement('img');
				v_img.src = this.imagesUrl[v_i];
				Doc.id(this.id + this.addZero(v_i) ).appendChild(v_img);
			} else {
				Doc.id(this.id + this.addZero(v_i) ).style.backgroundImage = 'url("' + this.imagesUrl[v_i] + '")';
				Doc.id(this.id + this.addZero(v_i) ).style.backgroundRepeat = 'no-repeat';
				Doc.id(this.id + this.addZero(v_i) ).style.backgroundPosition = 'center';
			}
		}
	},
	opacityCss : function() {
		var v_id = this.id + this.addZero(this.imageFade);
		
		if (this.MsIE) {
			Doc.id(v_id).style.opacity = (this.opacityLevel / 100);
			Doc.id(v_id).style.filter = 'alpha(opacity=' + this.opacityLevel + ')';
		} else {
			v_css = '';
			v_css += 'background: ' + this.imagesBgcolor + ' url("' + this.imagesUrl[this.imageFade] + '") no-repeat center; ';
			v_css += '-moz-opacity:' + ( this.opacityLevel / 100) + '; opacity:' + (this.opacityLevel / 100) + '; ';
			v_css += 'z-index:' + this.imagesLen + '; ';
			Doc.id(v_id).setAttribute('style', v_css, 'false');
		}
	},
	zIndexCss : function () {
		var v_Fade = this.imageFade;
		for (var v_zIndex = (this.imagesLen); v_zIndex > 0; v_zIndex--) {
			var v_id = this.id + this.addZero(v_Fade);
			if (this.MsIE) {
				Doc.id(v_id).style.zIndex = v_zIndex;
				Doc.id(v_id).style.opacity = '1';
				Doc.id(v_id).style.filter = 'alpha(opacity=100)';
			} else {
				v_css = '';
				v_css += 'background: ' + this.imagesBgcolor + ' url("' + this.imagesUrl[v_Fade] + '") no-repeat center; ';
				v_css += '-moz-opacity:1; opacity:1; ';
				v_css += 'z-index:' + v_zIndex + '; ';
				
				Doc.id(v_id).setAttribute('style', v_css, 'false');
			}
			
			v_Fade = ((v_Fade + 1) >= this.imagesLen) ? (0) : (v_Fade + 1);
		}
	},
	nextFade : function() {
		return (this.timeNext > 1) ? (this.timeNext) : (Math.random() * 20000);
	},
	fade : function() {
		this.opacityCss();
		
		var v_ms;
		if (this.firstRun) {
			this.firstRun = false;
			v_ms = this.nextFade();
			
		} else if (this.opacityLevel <= 0) {
			this.opacityLevel = 100;
				
			this.imageFade = ((this.imageFade + 1) >= this.imagesLen) ? (0) : (this.imageFade + 1);
			this.zIndexCss();
			
			v_ms = this.nextFade();
			
		} else {
			this.opacityLevel = this.opacityLevel - this.opacityStep;
			v_ms = this.timeMs;
		}
		
		setTimeout(this.fade._bind(this), v_ms);
	}
}



function noSpam(mt1, mt2, mt3) {
	var link = 'mailto:' + mt1 + '@' + mt2 + '.' + mt3;
	location.href = link;
	return false;
}



function protection(p_mode) {
	if(p_mode) {
		document.body.oncontextmenu = function() { return false; };
		document.body.ondragstart = function() { return false; };
		document.body.onselectstart = function() { return false; };
	} else {
		document.body.oncontextmenu = null;
		document.body.ondragstart = null;
		document.body.onselectstart = null;
	}
}



window.onload = function() {
	if (typeof(fadeLoad) == 'function') { fadeLoad(); }
	protection(true);
}


