/***********************************************
* Fading text slideshow - modified from:
*
* Ultimate Fade-In Slideshow (v1.51): ? Dynamic Drive (http://www.dynamicdrive.com)
***********************************************/

var fadebgcolor="transparent"

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
 
function fadeshow(thetext, fadewidth, fadeheight, delay, randomorder)
{
	this.delay=delay
	this.degree=0 //initial opacity degree (10%)
	this.slideindex=0
	this.nextslideindex=1
	fadearray[fadearray.length]=this
	this.slideshowid=fadearray.length-1
	this.canvasbase="canvas"+this.slideshowid
	this.curcanvas=this.canvasbase+"_0"
	if (randomorder) thetext.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
	this.thetext=thetext
	this.postimages=new Array() //preload images

	for (p=0;p<thetext.length;p++)
	{
		this.postimages[p]=new String()
		this.postimages[p]=thetext[p]
	}
	 
	if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
		document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+	'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'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:'+fadewidth+'px;height:'+fadeheight+'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>')
	else
		document.write('<div class="quote_text">'+'"'+this.postimages[textindex][0]+'" - '+this.postimages[textindex][1]+'</div>')
	 
	if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
		this.startit()
	else
	{
		this.slideindex++
		setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
	}
}

function setopacity(subject, degree)
{
	if (subject.tempobj.filters&&subject.tempobj.filters[0])
	{
		if (typeof subject.tempobj.filters[0].opacity=="number") //if IE6+
		subject.tempobj.filters[0].opacity=degree
		else //else if IE5.5-
		subject.tempobj.style.filter="alpha(opacity="+degree+")"
	}
	else if (subject.tempobj.style.MozOpacity)
	subject.tempobj.style.MozOpacity=degree/101
	else if (subject.tempobj.style.KhtmlOpacity)
	subject.tempobj.style.KhtmlOpacity=degree/100
	else if (subject.tempobj.style.opacity&&!subject.tempobj.filters)
	subject.tempobj.style.opacity=degree/101
}

function fadetext(obj)
{
	if (obj.degree<100)
	{
		obj.degree+=10
		setopacity(obj, obj.degree)
	}
	else
	{
		clearInterval(fadeclear[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.nextslideindex)
		setopacity(obj, 0) //new canvas starts invisible
		obj.nextslideindex=(obj.nextslideindex<obj.postimages.length-1)? obj.nextslideindex+1 : 0
		setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
	}
}
 
fadeshow.prototype.populateslide=function(textobj, textindex)
{
	var slideHTML=""
	slideHTML+='<div id="speech_bubble">'
	slideHTML+='<div id="quote_open">"</div>'
	slideHTML+='<div id="quote_text">'
	slideHTML+=this.postimages[textindex][0]
	slideHTML+='</div>' //end quote text
	slideHTML+='<div id="quote_close">"</div>'
	slideHTML+='<div id="quotee"> - '
	if(this.postimages[textindex].length>1&&this.postimages[textindex][1]!="")
	{
		if (this.postimages[textindex].length>2&&this.postimages[textindex][2]!="")	//link
			slideHTML+='<a href="'+this.postimages[textindex][2]+'" target="_blank">'
		slideHTML+=this.postimages[textindex][1]	//quotee
		if (this.postimages[textindex].length>2&&this.postimages[textindex][2]!="")	//end link
			slideHTML+='</a>'
	}
	else
		slideHTML+='Anon'
	slideHTML+='</div>' //end quotee	
	slideHTML+='</div>' //end speech bubble

	textobj.innerHTML=slideHTML
}
 
fadeshow.prototype.rotateimage=function()
{
	if (iebrowser&&dom||dom)
	{
		this.resetit()
		var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
		crossobj.style.zIndex++
		fadeclear[this.slideshowid]=setInterval("fadetext(fadearray["+this.slideshowid+"])",50)
		this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
	}
	else
	{
		var ns4imgobj=document.images['defaultslide'+this.slideshowid]
		ns4imgobj.src=this.postimages[this.slideindex].src
	}
	this.slideindex=(this.slideindex<this.postimages.length-1)? this.slideindex+1 : 0
}
 
fadeshow.prototype.resetit=function()
{
	this.degree=0
	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
}
 
fadeshow.prototype.startit=function()
{
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	this.populateslide(crossobj, this.slideindex)
	this.rotateimage()
}
