 /***********************************************
* Ultimate Fade-In Slideshow (v1.51): � Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
 
//var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
//fadeimages[0]=["images/BAS.jpg", "", ""] //plain image syntax
//fadeimages[1]=["images/ACCUEIL-CONSOLIDATION-DYNAMITAGE.jpg", "http://www.cssdrive.com", ""] //image with link syntax
//fadeimages[2]=["images/ACCUEIL-ENVIRONNEMENT GODIN-ST-LAURENT.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax
 
var fadebgcolor = "white";

////NO need to edit beyond here/////////////
 
var bgfadearray = new Array(); //array to cache fadeshow instances
var bgfadeclear = new Array(); //array to cache corresponding clearinterval pointers
var bgslideclear = new Array(); //array to cache corresponding cleartimeout pointers
 
var dom = (document.getElementById); //modern dom browsers
var iebrowser=document.all;
 
function bgfadeshow(theimages, theelementid, delay, pause, displaydescription, displayorder)
{
	this.pausecheck = pause;
	this.mouseovercheck = 0;
	this.delay = delay;
	this.degree = 10; //initial opacity degree (10%)
	this.curimageindex = 0;
	this.nextimageindex=(this.curimageindex<theimages.length-1)? this.curimageindex+1 : 0
	bgfadearray[bgfadearray.length] = this;
	this.slideshowid = bgfadearray.length - 1;
	this.canvasbase = "canvas"+this.slideshowid;
	this.curcanvas = this.canvasbase + "_0";
	
	if(typeof displayorder != "undefined")
	{
		theimages.sort(function() {return 0.5 - Math.random();}); //thanks to Mike (aka Mwinter) :)
	}
	
	this.theimages=theimages;
	this.postimages=new Array(); //preload images
	
	for(p=0; p < theimages.length; p++)
	{
		this.postimages[p] = new Image();
		this.postimages[p].src = theimages[p][0];
	}
	 	
	this.theelement = iebrowser? iebrowser[theelementid] : document.getElementById(theelementid);
	var code = '<div id="master' + this.slideshowid + '" style="z-index:-10000;margin-bottom:-'+ String(this.theelement.offsetHeight)+'px;position:relative;top:0px; left:0px;width:' + String(this.theelement.offsetWidth)+'px;height:' + String(this.theelement.offsetHeight) + 'px;overflow:hidden;"><div id="' + this.canvasbase + '_0" style="position:absolute;width:' + String(this.theelement.offsetWidth) + 'px;height:' + String(this.theelement.offsetHeight) + 'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:' + fadebgcolor + '"></div><div id="' + this.canvasbase + '_1" style="position:absolute;width:' + String(this.theelement.offsetWidth) + 'px;height:' + String(this.theelement.offsetHeight) + 'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:' + fadebgcolor + '"></div>';
	if(displaydescription == 1)
		code += '<span id="ss_desc"></span>';
	code += '</div>';
	this.theelement.innerHTML = code + this.theelement.innerHTML;
	this.startit();
}

function bgfadepic(obj)
{
	if (obj.degree<100)
	{
		obj.degree+=10;
		if (obj.tempobj.filters&&obj.tempobj.filters[0])
		{
			if(typeof obj.tempobj.filters[0].opacity == "number") //if IE6+
				obj.tempobj.filters[0].opacity = obj.degree;
			else //else if IE5.5-
				obj.tempobj.style.filter = "alpha(opacity=" + obj.degree+")";
		}
		else if(obj.tempobj.style.MozOpacity)
			obj.tempobj.style.MozOpacity=obj.degree/101;
		else if(obj.tempobj.style.KhtmlOpacity)
			obj.tempobj.style.KhtmlOpacity=obj.degree/100;
		else if(obj.tempobj.style.opacity && !obj.tempobj.filters)
			obj.tempobj.style.opacity=obj.degree/101;
	}
	else
	{
		clearInterval(bgfadeclear[obj.slideshowid])
		obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
		obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
				
		obj.populateslide(obj.tempobj, obj.nextimageindex)
		
		var currentImg = (obj.curimageindex == 0) ? obj.theimages.length - 1 : obj.curimageindex - 1
		var prevImg = (currentImg == 0) ? obj.theimages.length - 1 : currentImg - 1
		var oldmenu = iebrowser? iebrowser["ss_menu_" + String(prevImg)] : document.getElementById("ss_menu_" + String(prevImg))
		if(oldmenu)
		{
			oldmenu.className = "ss_menu"
		}
		var menu = iebrowser? iebrowser["ss_menu_" + String(currentImg)] : document.getElementById("ss_menu_" + String(currentImg))
		if(menu)
		{
			menu.className = "ss_menu_selected"
		}
		
		
		var oldThumb = iebrowser? iebrowser["ss_thumb_" + String(prevImg)] : document.getElementById("ss_thumb_" + String(prevImg))
		if(oldThumb)
		{
			oldThumb.className = "ss_thumb"
		}

		var thumb = iebrowser? iebrowser["ss_thumb_" + String(currentImg)] : document.getElementById("ss_thumb_" + String(currentImg))
		if(thumb)
		{
			thumb.className = "ss_selected"
		}
		
		var desc = iebrowser? iebrowser["ss_desc"] : document.getElementById("ss_desc")
		if(desc)
		{
			desc.innerHTML = obj.theimages[currentImg][1]
		}
	
		obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
		bgslideclear[obj.slideshowid] = setTimeout("bgfadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
	}
}
 
bgfadeshow.prototype.populateslide=function(picobj, picindex)
{
	var slideHTML=""
	slideHTML+='<img style="float:right" src="'+this.postimages[picindex].src+'">'
	picobj.innerHTML=slideHTML
}
 
 
bgfadeshow.prototype.rotateimage=function()
{
	if (this.pausecheck==1) //if pause onMouseover enabled, cache object
		var cacheobj=this
	if (this.mouseovercheck==1)
	{
		bgslideclear[this.slideshowid] = setTimeout(function(){cacheobj.rotateimage()}, 100)
	}
	else
	{
		this.resetit()
		var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
		crossobj.style.zIndex++
		bgfadeclear[this.slideshowid]=setInterval("bgfadepic(bgfadearray["+this.slideshowid+"])",50)
		this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
				this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
	}
	
	
}

bgfadeshow.prototype.resetit=function()
{
	this.degree=10
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	if (crossobj.filters&&crossobj.filters[0])
	{
		if (typeof crossobj.filters[0].opacity=="number") //if IE6+
			crossobj.filters(0).opacity=this.degree
		else //else if IE5.5-
			crossobj.style.filter="alpha(opacity="+this.degree+")"
	}
	else if (crossobj.style.MozOpacity)
		crossobj.style.MozOpacity=this.degree/101
	else if (crossobj.style.KhtmlOpacity)
		crossobj.style.KhtmlOpacity=this.degree/100
	else if (crossobj.style.opacity&&!crossobj.filters)
		crossobj.style.opacity=this.degree/101
}
 
 
bgfadeshow.prototype.startit=function()
{
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	this.populateslide(crossobj, this.curimageindex)
	if (this.pausecheck==1)
	{ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
		var cacheobj=this
		var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
		crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
		crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
	}
	this.rotateimage()
}

bgfadeshow.prototype.drawmenu=function(){
	document.write('<span id="ss_menu_span">')
	for (p=0;p<this.theimages.length;p++){
		if(p != 0)
			document.write(' | ' )
			
	document.write('<a class="ss_menu" id="ss_menu_' + String(p) + '" href="javascript:bggotopic(bgfadearray['+String(this.slideshowid)+'], ' + String(p) + ')">'+String(p+1)+'</a>' )
	}

	document.write('</span>')
}

function bggotopic(obj, picNo){
	clearInterval(bgfadeclear[obj.slideshowid])
	clearTimeout(bgslideclear[obj.slideshowid])
	var nextImg = (picNo<obj.postimages.length-1)? picNo+1 : 0
	//var prevImg = (currentImg == 0) ? obj.theimages.length - 1 : currentImg - 1
	//		alert(picNo)
	//alert(prevImg)
	//alert(currentImg)
	var oldImg = (obj.curimageindex == 0) ? obj.postimages.length-1 : obj.curimageindex-1
	obj.curimageindex = picNo
	obj.nextimageindex = nextImg
	obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
	obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
	obj.populateslide(obj.tempobj, picNo)
	var menu = iebrowser? iebrowser["ss_menu_" + String(oldImg)] : document.getElementById("ss_menu_" + String(oldImg))
		if(menu)
		{
			menu.className = "ss_menu"
		}
	
	var thumb = iebrowser? iebrowser["ss_thumb_" + String(oldImg)] : document.getElementById("ss_thumb_" + String(oldImg))
			if(thumb)
			{
				thumb.className = "ss_thumb"
					//thumb.style.color = "red"
			}
	
	
	obj.rotateimage()
}

bgfadeshow.prototype.setthumbhref=function(){

	for (p=0;p<this.theimages.length;p++)
	{
		var thumb = iebrowser? iebrowser["ss_thumb_" + String(p)] : document.getElementById("ss_thumb_" + String(p)) 
		if(thumb)
		{
			
			thumb.className = 'ss_thumb';
			thumb.href = 'javascript:bggotopic(bgfadearray['+String(this.slideshowid)+'],' + p.toString() + ');';
		}
	}
}