/**
 *
 * @author	Benoit Asselin <benoit(at)agenceici(dot)com
 * @version	javascript.js, 2009/03/23
 * @link	http://www.agenceici.com/
 *
 */


var v_previous = '';
function smenu(p_id) {
	if(v_previous != p_id && v_previous) {
		Doc.id(v_previous).style.display = 'none';
	}
	v_previous = p_id;
	if(p_id) {
		Doc.id(p_id).style.display = 'block';
	}
}



function ClassFade(p_id) {
	this.id = Doc.id(p_id);						/* readonly - getElementById() */
	this.images = this.id.getElementsByTagName('img');		/* readonly - Images */
	this.imageFade = 0;						/* readonly - Integer */
	this.opacityStep = 4;						/* min: 1 // max: 100 */
	this.opacityLevel = 100;					/* 0 or 100 */
	this.timeNext = 0;						/* 0 = random // xxx = fix */
	this.timeMs = 20;						/* speed transition  */
	this.firstRun = true;						/* Boolean */
	
	this.csszIndex();
	this.fade();
}
ClassFade.prototype = {
	/* private */
	cssOpaticy : function() {
		this.images.item(this.imageFade).parentNode.style.opacity = (this.opacityLevel / 100);
		this.images.item(this.imageFade).parentNode.style.mozOpacity = (this.opacityLevel / 100);
		this.images.item(this.imageFade).parentNode.style.filter = 'alpha(opacity=' + this.opacityLevel + ')';
	},
	csszIndex : function () {
		var v_Fade = this.imageFade;
		for(var v_zIndex = this.images.length; v_zIndex > 0; v_zIndex--) {
			this.images.item(v_Fade).parentNode.style.zIndex = v_zIndex;
			this.images.item(v_Fade).parentNode.style.opacity = '1';
			this.images.item(v_Fade).parentNode.style.mozOpacity = '1';
			this.images.item(v_Fade).parentNode.style.filter = 'alpha(opacity=100)';
			v_Fade = ((v_Fade + 1) >= this.images.length) ? (0) : (v_Fade + 1);
		}
	},
	nextFade : function() {
		return (this.timeNext > 1) ? (this.timeNext) : (Math.random() * 10000);
	},
	fade : function() {
		this.cssOpaticy();
		
		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.images.length) ? (0) : (this.imageFade + 1);
			this.csszIndex();
			
			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, subject) {
	var link = 'mailto:' + mt1 + '@' + mt2 + '.' + mt3;
	if(subject !== undefined) { link += '?subject=' + encodeURIComponent(subject); }
	window.location.href = link;
	return false;
}



