////NO need to edit beyond here/////////////

/***********************************************
* Ultimate Fade-In Slideshow (v1.5): © 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.
*
* ChangeLog
* 28/06/2007 - modified by luciorota (lucio_rota@tiscali.it)
* added: 'html content' support
* added: 'prev', 'next', 'play/stop' metods/functions
* 
* ----------------------------------------------
* 
* DESCRIPTION
* 
* OBJECT
* fadeshow(IMAGES_ARRAY_NAME, 'slideshow_width property value', 'slideshow_height property value', 'slideshow background property value', delay, fade_delay, pause (0=no, 1=yes), optionalRandomOrder ("R" or none))
*    IMAGES_ARRAY_NAME: an array like this IMAGES_ARRAY_NAME[n]=['content in html format','link','target']
*    'slideshow_css width property value': a string like "100px" or "80%" or ...
*    'slideshow_css height property value': a string like "100px" or "80%" or ...
*    'slideshow css background property value': a string like "black" or "#003366" "url('images/background.gif') no-repeat top left" or ...
*    delay: milliseconds between transitions
*    fade_delay: milliseconds for every fading step (10 steps), total fade time = (fade delay * 10) 
*    pause: pause if mouse over, 0=no, 1=yes
*    optionalRandomOrder: if it exists, slidoshow is in random order
* 
* USEFUL METODS
* .playstopcontent()
*    it plays or stops the slideshow
* .prevcontent()
*    it shows previous content
* .nextcontent()
*    it shows next content
* 
* USEFUL PROPERTIES
* .status=
*    1 = play or 0 = stop
* 
***********************************************/

var fadeshow_istances=new Array(); //array to cache fadeshow instances
var fadeshow_istances_slideshow_timers=new Array(); //array to cache corresponding clearinterval pointers
var fadeshow_istances_fading_timers=new Array(); //array to cache corresponding clearinterval pointers

var dom=(document.getElementById); //modern dom browsers
var iebrowser=document.all;

function fadeshow(thecontents, fadewidth, fadeheight, fadebg, delay, fadedelay, pause, displayorder)
	{
	if (typeof displayorder!="undefined")
		thecontents.sort(function() {return 0.5 - Math.random();}); //thanks to Mike (aka Mwinter) :)

	this.thecontents=thecontents;
	this.postcontents=new Array(); //preload images
	for (p=0;p<thecontents.length;p++){this.postcontents[p]=thecontents[p][0];}

	this.fadewidth=fadewidth;
	this.fadeheight=fadeheight;
	this.fadebg=((fadebg=='') || (fadebg.indexOf('transparent')>-1) ? 'white' : fadebg); // the css 'background' property value of fade area 

	this.delay=delay;
	this.fadedelay=fadedelay;
	this.status=1; // 1 = play or 0 = stop

	this.pausecheck=pause;
	this.mouseovercheck=0;

	this.degree=10; //initial opacity degree (10%)
	this.curcontentindex=0;
	this.nextcontentindex=1;

	fadeshow_istances[fadeshow_istances.length]=this; // this fadeshow istance
	this.slideshowid=fadeshow_istances.length-1;      // for exemple: = 0
	this.canvasbase="canvas"+this.slideshowid;        // for exemple: = canvas0
	this.curcanvas=this.canvasbase+"_0";              // for exemple: = canvas0_0

	if (iebrowser&&dom||dom) { //if IE5+ or modern browsers (ie: Firefox)
		document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+';height:'+fadeheight+';overflow:hidden;">');
		document.write('	<div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+';height:'+fadeheight+';top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;-khtml-opacity:10;background:'+this.fadebg+'">');
		document.write('	</div>');
		document.write('	<div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+';height:'+fadeheight+';top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;background:'+this.fadebg+'">');
		document.write('	</div>');
		document.write('</div>');
		}
	else { // in progress
		document.write('<div>'); // in progress
		document.write('	<img name="defaultslide'+this.slideshowid+'" src="'+this.postcontents[0].src+'">'); // in progress
		document.write('</div>'); // in progress
		} // in progress

	if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
		this.startit();
	else
		{
		this.curcontentindex++;
		fadeshow_istances_slideshow_timers[this.slideshowid]=setInterval("fadeshow_istances["+this.slideshowid+"].rotatecontent()", this.delay);
		}
	}



function setopacity(object,opacity) {
	if (object.filters&&object.filters[0]) {
		if (typeof object.filters[0].opacity=="number") object.filters[0].opacity = opacity; //if IE6+
		else                                            object.style.filter = "alpha(opacity="+opacity+")"; //else if IE5.5-
		}
	else if (object.style.MozOpacity)   object.style.MozOpacity = (opacity/101); // works in older versions of Mozilla and Phoenix/FireBird/FireFox
	else if (object.style.KhtmlOpacity) object.style.KhtmlOpacity = (opacity/100); // used by browsers that use teh KHTML rendering engine, namely Konquerer on Linux and Safari on MacOS
	else if (object.style.opacity)      object.style.opacity = (opacity/100); // official CSS3 method, at the moment it works in newer Mozilla versions
	}


/*
//source: Cross-browser BlendTrans Filter JavaScript
function setopacity(object, opacity) {
	object.style.opacity = (opacity / 100); // official CSS3 method, at the moment it works in newer Mozilla versions
	object.style.MozOpacity = (opacity / 100); // works in older versions of Mozilla and Phoenix/FireBird/FireFox
	object.style.KhtmlOpacity = (opacity / 100); // used by browsers that use teh KHTML rendering engine, namely Konquerer on Linux and Safari on MacOS
	object.style.filter = "alpha(opacity=" + opacity + ")"; // works only in MSIE
	}
*/


function fadepic(obj) {
	if (obj.degree<100)	{
		obj.degree+=10;
		setopacity(obj.tempobj,obj.degree);
		}
	else {
		obj.degree=100;
		setopacity(obj.tempobj,obj.degree);
		clearTimeout(fadeshow_istances_fading_timers[obj.slideshowid]);//
		fadeshow_istances_fading_timers[obj.slideshowid]=clearInterval(fadeshow_istances_fading_timers[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);
		// it loads the next slide content - start (removed by luciorota)
		//obj.populateslide(obj.tempobj, obj.nextcontentindex);
		// it loads the next slide content - end (removed by luciorota)
		obj.nextcontentindex=(obj.nextcontentindex<obj.postcontents.length-1)? obj.nextcontentindex+1 : 0;
		if (obj.status==1) {
			fadeshow_istances_slideshow_timers[obj.slideshowid]=setTimeout("fadeshow_istances["+obj.slideshowid+"].rotatecontent()", obj.delay);
			}
		}
	}



fadeshow.prototype.populateslide=function(obj, contentindex)
	{
	var slideHTML="";
	if (this.thecontents[contentindex][1]!="") //if associated link exists for content
		slideHTML='<a href="'+this.thecontents[contentindex][1]+'" target="'+this.thecontents[contentindex][2]+'">';
	slideHTML+='<div>'+this.postcontents[contentindex]+'</div>';
	if (this.thecontents[contentindex][1]!="") //if associated link exists for content
		slideHTML+='</a>';
	obj.innerHTML=slideHTML;
	}



fadeshow.prototype.playstopcontent=function() { // (by luciorota)
// it starts or stops the slideshow
	clearInterval(fadeshow_istances_fading_timers[this.slideshowid]); // reset fading timer
	clearTimeout(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	clearInterval(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	if (this.status==1) { // if play
		this.status=0; // it stops slideshow
		this.degree=100;
		fadepic(this);
		}
	else { // if stop
		this.status=1; // it starts slideshow
		if (iebrowser&&dom||dom) { //if IE5+ or modern browsers (ie: Firefox)
			this.startit();
			}
		else {
			this.curcontentindex++
			fadeshow_istances_slideshow_timers[this.slideshowid]=setInterval("fadeshow_istances["+this.slideshowid+"].rotatecontent()", this.delay)
			}
		}
	}
fadeshow.prototype.nextcontent=function() { // (by luciorota)
	clearInterval(fadeshow_istances_fading_timers[this.slideshowid]); // reset fading timer
	clearTimeout(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	clearInterval(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	this.rotatecontent(1);
	}
fadeshow.prototype.prevcontent=function() { // (by luciorota)
	clearInterval(fadeshow_istances_fading_timers[this.slideshowid]); // reset fading timer
	clearTimeout(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	clearInterval(fadeshow_istances_slideshow_timers[this.slideshowid]); // reset slideshow timers
	this.rotatecontent(-1);
	}



fadeshow.prototype.rotatecontent=function(direction) {
// direction = 1 -> forward  /  direction = -1 -> backward // in progress
	if (this.pausecheck==1) //if pause onMouseover enabled, cache object
		var cacheobj=this;

	if (this.mouseovercheck==1) {
		setTimeout(function(){cacheobj.rotatecontent()}, 100);
		}
	else {
		// it loads the next slide content - start (by luciorota)
		var crossobj=(iebrowser ? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas));
		if (direction==-1) 
			this.curcontentindex = (this.curcontentindex-1+this.postcontents.length-1) % (this.postcontents.length);
		this.populateslide(crossobj, this.curcontentindex);
		// it loads the next slide content - end (by luciorota)
	
		if (iebrowser&&dom||dom) { //if IE5+ or modern browsers (ie: Firefox)
			this.resetit();
			var crossobj=this.tempobj=(iebrowser ? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas));
			crossobj.style.zIndex++; // in questo modo zIndex continua a crescere indefinitamente ... poi? correggere qs baco!!!
			fadeshow_istances_fading_timers[this.slideshowid]=setInterval("fadepic(fadeshow_istances["+this.slideshowid+"])",this.fadedelay);
			this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"; // 
			}
		else { // in progress
			var ns4imgobj=document.images['defaultslide'+this.slideshowid]; // in progress
			ns4imgobj.src=this.postcontents[this.curcontentindex].src; // in progress
			} // in progress
		this.curcontentindex=((this.curcontentindex<this.postcontents.length-1)? this.curcontentindex+1 : 0);
		}
	}



fadeshow.prototype.resetit=function()
// inizialize fading cycle
	{
	this.degree=10; //initial opacity 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=obj.degree/100;
	}



fadeshow.prototype.startit=function()
	{
	// it loads the next slide content - start (removed by luciorota)
	//var crossobj=(iebrowser ? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas));
	//this.populateslide(crossobj, this.curcontentindex);
	// it loads the next slide content - end (removed by luciorota)
	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.rotatecontent();
	}
