var global_transitions=[
"progid:DXImageTransform.Microsoft.Fade()"
]

function flashyslideshow(setting){
this.wrapperid=setting.wrapperid
this.imagearray=setting.imagearray
this.pause=setting.pause
this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into el.filters.play()
this.currentimg=0
var preloadimages=[] //temp array to preload images
for (var i=0; i<this.imagearray.length; i++){
preloadimages[i]=new Image()
preloadimages[i].src=this.imagearray[i][0]
}
document.write('<div id="'+this.wrapperid+'"><div id="'+this.wrapperid+'_inner" style="width:100%">'+this.getSlideHTML(this.currentimg)+'</div></div>')
var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (contentdiv.filters){ //if the filters[] collection is defined on element (only in IE)
contentdiv.style.filter=global_transitions[effectindex] //define transition on element
this.pause+=setting.transduration //add transition time to pause
}
this.filtersupport=(contentdiv.filters && contentdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
var slideshow=this
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=1}, "mouseover")
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=0}, "mouseout")
setInterval(function(){slideshow.rotate()}, this.pause)
}

flashyslideshow.addEvent=function(target, functionref, tasktype){
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false);
else if (target.attachEvent)
target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

flashyslideshow.setopacity=function(el, degree){ //sets opacity of an element (FF and non IE browsers only)
if (typeof el.style.opacity!="undefined")
el.style.opacity=degree
else
el.style.MozOpacity=degree
el.currentopacity=degree
},

flashyslideshow.prototype.getSlideHTML=function(index){
var slideHTML=(this.imagearray[index][1])? '<table cellpadding=0 align=right cellspacing=0 style="border:2px #B1D8D8 solid; width:150px; cursor:hand; cursor:pointer; background-image:url('+this.imagearray[index][0]+')" onClick="location.href=\''+this.imagearray[index][1]+'\'" onMouseOver="document.getElementById(\'link\').style.display=\'none\';document.getElementById(\'link2\').style.display=\'none\';" onMouseOut="document.getElementById(\'link\').style.display=\'block\';document.getElementById(\'link2\').style.display=\'block\';"><tr><td height=40 valign=top>' : ''
slideHTML+=(this.imagearray[index][3])? '<div id=link><table cellpadding=0 align=right cellspacing=0 background="pics/layout/bg.png"><tr><td align=center class="s9" style="color:white;font-family:verdana">&nbsp;'+this.imagearray[index][2]+'&nbsp;</td></tr></table></div></td></tr><tr><td height=45 valign=bottom><div id=link2><table cellpadding=0 cellspacing=0 background="pics/layout/bg.png"><tr><td width=3></td><td align=center class="s9" style="color:white"><b>'+this.imagearray[index][3]+'</b></td><td width=3></td></tr></table></div></td></tr></table>' : ''
return slideHTML
}

flashyslideshow.prototype.rotate=function(){
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (this.isMouseover){ return }
this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
if (this.filtersupport){ contentdiv.filters[0].apply() }
else{ flashyslideshow.setopacity(contentdiv, 0)	}
contentdiv.innerHTML=this.getSlideHTML(this.currentimg)
if (this.filtersupport){ contentdiv.filters[0].play(this.transduration)	}
else{ contentdiv.fadetimer=setInterval(function(){
if (contentdiv.currentopacity<1)
flashyslideshow.setopacity(contentdiv, contentdiv.currentopacity+0.1)
else
clearInterval(contentdiv.fadetimer)
}, 50)
}
}


