/***********************************************
* Fade-in image slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/	

var ie4 = document.all;
var dom = document.getElementById;
var arr_fade_images = new Array();
var slideshow_dropslide = new Array();

function FaddingImage(slideshow_name, fade_images, width, height, pause, slideshow_id, slideshow_style) {

	var slideshow_width		= width;	//SET IMAGE WIDTH
	var slideshow_height	= height;	//SET IMAGE HEIGHT
	var slideshow_pause		= pause;	//SET slideshow_pause BETWEEN SLIDE (3000=3 seconds)
	var preloadedimages		= new Array();

	for(p = 0; p < fade_images.length; p++) {
		preloadedimages[p] = new Image();
		preloadedimages[p].src = fade_images[p][0];
	}	

	if(ie4||dom) {
		document.write('<div style="position:relative;width:' + slideshow_width +
			';height:' + slideshow_height +
			';overflow:hidden"><div id="' + slideshow_name + '0" style="float:left;position:absolute;width:' + slideshow_width +
			';height:' + slideshow_height +
			';top:0px;left:0px;filter:alpha(opacity=10);-moz-opacity:10;"></div><div id="' + slideshow_name + '1" style="float:left;position:absolute;width:' + slideshow_width +
			';height:' + slideshow_height + 
			';top:0px;left:0px;filter:alpha(opacity=10);-moz-opacity:10;visibility: hidden"></div></div>')		
	} else {
		document.write('<img name="defaultslide" src="' + fade_images[0][0] + '">');
	}

	var curpos			= 10;
	var curpostwo		= 90;
	var curcanvas		= slideshow_name + "0";
	var curimageindex	= 0;
	var nextimageindex	= 1;
	document.write("<input type='hidden' id='id_" + slideshow_name + "_curpos' value='" + curpos + "'>");
	document.write("<input type='hidden' id='id_" + slideshow_name + "_curpostwo' value='" + curpostwo + "'>");
	document.write("<input type='hidden' id='id_" + slideshow_name + "_curcanvas' value='" + curcanvas + "'>");
	document.write("<input type='hidden' id='id_" + slideshow_name + "_curimageindex' value='" + curimageindex + "'>");
	document.write("<input type='hidden' id='id_" + slideshow_name + "_nextimageindex' value='" + nextimageindex + "'>");
	document.write("<input type='hidden' id='id_" + slideshow_name + "_slideshow_style' value='" + slideshow_style + "'>");
	arr_fade_images[slideshow_id] = fade_images;
	slideshow_startit(slideshow_name, slideshow_id, slideshow_pause);
}

function GetSlideshowPrefInt(slideshow_name, pref) {
	var intPref = parseInt(document.getElementById("id_" + slideshow_name + "_" + pref).value);
	return intPref;
}

function WriteSlideshowPref(slideshow_name, pref, pref_value) {
	document.getElementById("id_" + slideshow_name + "_" + pref).value = pref_value;
}

function GetSlideshowPrefStr(slideshow_name, pref) {
	var strPref = document.getElementById("id_" + slideshow_name + "_" + pref).value;
	return strPref;
}


function slideshow_fadepic(slideshow_name, slideshow_id, slideshow_pause){
	var fade_images = arr_fade_images[slideshow_id];
	var slideshow_style = GetSlideshowPrefInt(slideshow_name, "slideshow_style");
	var curpos = GetSlideshowPrefInt(slideshow_name, "curpos");
	var curpostwo = GetSlideshowPrefInt(slideshow_name, "curpostwo");
	var curcanvas = GetSlideshowPrefStr(slideshow_name, "curcanvas");
	var nextimageindex = GetSlideshowPrefInt(slideshow_name, "nextimageindex");
	var tmp_slideshow_name = slideshow_name + "0";
	var nextcanvas = (curcanvas == tmp_slideshow_name)? slideshow_name + "0" : slideshow_name + "1";
	curcanvas = (curcanvas == tmp_slideshow_name)? slideshow_name + "1" : slideshow_name + "0"
	var tempobj2=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
	var tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)

	if (curpostwo > 0) {
		curpostwo -= 10
		if(tempobj.filters) {
			tempobj2.filters.alpha.opacity=curpostwo
		} else if (tempobj2.style.MozOpacity) {
			tempobj2.style.MozOpacity=curpostwo/101
		}		
		if(slideshow_style == 1) {
			curpos += 10
			if(tempobj.filters) {
				tempobj.filters.alpha.opacity=curpos
			} else if (tempobj.style.MozOpacity) {
				tempobj.style.MozOpacity=curpos/101
			}
		}
	} else if(curpos < 100 && slideshow_style != 1) {
		curpos += 10
		if(tempobj.filters) {
			tempobj.filters.alpha.opacity=curpos
		} else if (tempobj.style.MozOpacity) {
			tempobj.style.MozOpacity=curpos/101
		}
	} else {
		clearInterval(slideshow_dropslide[slideshow_id])
		tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
		tempobj.innerHTML=slideshow_insertimage(nextimageindex, slideshow_name, slideshow_id)
		
		nextimageindex=(nextimageindex<fade_images.length-1)? nextimageindex+1 : 0
		
		tempobj2.style.visibility="hidden"
		setTimeout("slideshow_rotateimage('" + slideshow_name + "', " + slideshow_id + ", " + slideshow_pause + ")", slideshow_pause)		
	}
	WriteSlideshowPref(slideshow_name, "nextimageindex", nextimageindex);
	WriteSlideshowPref(slideshow_name, "curpos", curpos);
	WriteSlideshowPref(slideshow_name, "curpostwo", curpostwo);
}

function slideshow_insertimage(i, slideshow_name, slideshow_id) {
	var fade_images = arr_fade_images[slideshow_id]; 
	var slideshow_style = GetSlideshowPrefInt(slideshow_name, "slideshow_style");

	if(slideshow_style == 1) {
		var tempcontainer = '<a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_one + '" border="0" width="585"></a>';
	} else if(slideshow_style == 2) {
		var tempcontainer = '<table width="430" cellspacing="0" cellpadding="5">' +
			'<tr>' +
				'<td align="right" width="310" valign="top"><p align="right" class="secondhead"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_one + '" border="0"></a></p></td>' +
				'<td>&nbsp;</td>' +
			'</tr>' +
			'<tr>' +
				'<td width="310" align="right" valign="top"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_three + '" border="0"></a></td>' +
				'<td align="center" width="120"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_two + '" border="0" width="108"></a></td>' +
			'</tr>' +
			'</table>';
	} else if(slideshow_style == 3) {
		var tempcontainer = '<table width="430" cellspacing="0" cellpadding="5">' +
			'<tr>' +
				'<td align="right" width="310" valign="top"><p align="right" class="secondhead"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_one + '" border="0"></a></p></td>' +
				'<td align="center" width="120" rowspan="2"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_two + '" border="0" width="108"></a></td>' +
			'</tr>' +
			'<tr>' +
				'<td width="310" align="right" valign="top"><a href="' + fade_images[i].href_link + '"><img src="' + fade_images[i].img_three + '" border="0"></a></td>' +				
			'</tr>' +
			'</table>';
	}
	return tempcontainer;
}

function slideshow_rotateimage(slideshow_name, slideshow_id, slideshow_pause) {
	var fade_images = arr_fade_images[slideshow_id];
	var curcanvas = GetSlideshowPrefStr(slideshow_name, "curcanvas");	
	var curimageindex = GetSlideshowPrefInt(slideshow_name, "curimageindex");
	var tempobj;

	if(ie4||dom) {
		slideshow_resetit(curcanvas, slideshow_name)
		var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
		crossobj.style.zIndex++
		tempobj.style.visibility="visible"
		var temp = setInterval("slideshow_fadepic('" + slideshow_name + "', " + slideshow_id + ", " + slideshow_pause + ")", 50);
		slideshow_dropslide[slideshow_id] = eval(temp)
		var tmp_slideshow_name = slideshow_name + "0";
		curcanvas = (curcanvas == tmp_slideshow_name)? slideshow_name + "1" : slideshow_name + "0"
	} else {
		document.images.defaultslide.src=fade_images[curimageindex][0];curimageindex=(curimageindex<fade_images.length-1)? curimageindex+1 : 0
	}	
	WriteSlideshowPref(slideshow_name, "curimageindex", curimageindex);
	WriteSlideshowPref(slideshow_name, "curcanvas", curcanvas);
}

function slideshow_resetit(what, slideshow_name) {
	var curpos=10
	var curpostwo=90
	var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
	if(crossobj.filters) {
		crossobj.filters.alpha.opacity=curpos
	} else if (crossobj.style.MozOpacity) {
		crossobj.style.MozOpacity=curpos/101
	}
	WriteSlideshowPref(slideshow_name, "curpos", curpos);
	WriteSlideshowPref(slideshow_name, "curpostwo", curpostwo);
}

function slideshow_startit(slideshow_name, slideshow_id, slideshow_pause) {	
	var curcanvas = GetSlideshowPrefStr(slideshow_name, "curcanvas");
	var curimageindex = GetSlideshowPrefInt(slideshow_name, "curimageindex");
	var crossobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas);		
	crossobj.innerHTML = slideshow_insertimage(curimageindex, slideshow_name, slideshow_id);
	slideshow_rotateimage(slideshow_name, slideshow_id, slideshow_pause);
}

function slideshow_option(href_link, img_one, img_two, img_three) {
	this.href_link	= href_link;
	this.img_one	= img_one;
	this.img_two	= img_two
	this.img_three	= img_three
}