//configure the below five variables to change the style of the scroller
var faderdelay='4000' //delay between msg scrolls. 3000=3 seconds.
var fadeRunning = 0;
var fadeStopped = 0;
var blendDone=true;
var fadeIndex=0;
var tableHeight='38px';

function fade(){
	if (!blendDone){
		setTimeout("fade()",1)
	}else{
		setTimeout("fade()",faderdelay);
		if (fadeIndex==top_images.length-1){
			fadeIndex=0;
		}else{
			fadeIndex++;
		}
		blendimage(fadeIndex);
	}
}

function startfade(){
	// make sure function doesn't fun twice
	if (fadeRunning != 0){
		return;
	}
	fadeIndex=top_images.length-1;
	fadeRunning++
//	document.getElementById('slideshow_text').style.height=tableHeight;
//	document.getElementById("slideshow_text").innerHTML=top_images[0].split("|")[2];
	for(var j=0;j<top_images.length;j++){
		MM_preloadImages("../../images/features/slide_"+top_images[fadeIndex].split("|")[0]);
	}
	fade();
}

function blendimage(theIndex) {
	blendDone=false;
    var speed = 6;
    var timer = 0;
    
    //set the current image as background
    document.getElementById('blenddiv').style.backgroundImage = "url(" + document.getElementById('blendimage').src + ")";
    
    //make image transparent
    changeOpac(0, 'blendimage');
    
    //make new image
    document.getElementById('blendimage').src = "../../images/features/slide_"+top_images[theIndex].split("|")[0];
    document.getElementById('blendimage').alt = top_images[theIndex].split("|")[1];
    //fade in image
    for(var t = 0; t <= 100; t++) {
        setTimeout("changeOpac(" + t + ",'blendimage')",(timer * speed));
        timer++;
        if(t==100){
	        blendDone=true;
        }
    }
//	document.getElementById("slideshow_text").innerHTML=top_images[theIndex].split("|")[2];
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
	opacity = (opacity == 100)?99.999:opacity;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
document.write('<div style="background-image: url(../../images/features/slide_'+top_images[0].split("|")[0]+'); background-repeat: no-repeat; width: 409px; height: 252px;" id="blenddiv">');
document.write('<img src="../../images/features/slide_'+top_images[0].split("|")[0]+'" alt="'+top_images[0].split("|")[1]+'" width="409" height="252" border="0" id="blendimage" style="filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;">')
document.write('</div>');
document.write('<div style="visibility:hidden;position:absolute;top:0px;left:0px;"><table cellpadding="0" cellspacing="0" border="0" width="409">');
document.write('<tr valign="top"><td><table cellspacing="0" cellpadding="0" border="0" width="409">');
// document.write('<tr valign="top"><td class="slideshow_text" id="slideshow_text_sizing"></td></tr>');
document.write('</table></td></tr></table>');
/* for(var slides=0;slides<top_images.length;slides++){
	document.getElementById("slideshow_text_sizing").innerHTML=top_images[slides].split("|")[2];
	var theTd=document.getElementById("slideshow_text_sizing");
	var theHeight=theTd.offsetHeight;
	if(theHeight>parseInt(tableHeight)){
		tableHeight=theHeight+"px";
	}
}*/