var num = -1;
var timeDelay;
var imagePreload = new Array()

for (i=0;i<image.length;i++) {
	imagePreload[i]=new Image()
	imagePreload[i].src=image[i]
}


function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
	else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

String.prototype.replaceAll = function(strTarget,strSubString){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	while (intIndexOfMatch != -1){
		strText = strText.replace( strTarget, strSubString )
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	return( strText );
}

function blendimage(divid, imageid, imagefile, millisec, title, largephoto, TheLink, TheWidth, TheHeight) {
	if (imagefile != '../Assets/Images/Blank.gif'){
		var speed = Math.round(millisec / 40);
		var timer = 0;
		
		
		var WidthStr = "";
		var HeightStr = "";
		document.getElementById(divid).style.visibility = "visible"
		if (TheWidth != ""){
			WidthStr = " width:" + TheWidth + "px;"
			document.getElementById(divid).style.width = TheWidth + "px"
		}
		
		if (TheHeight != ""){
			HeightStr = " height:" + TheHeight + "px;"
			document.getElementById(divid).style.height = TheHeight + "px"
		}
		
		changeOpac(0, imageid);
		
		if (TheLink==''){
			if (largephoto==''){
				document.getElementById(divid).innerHTML = '<img src="' + imagefile + '" style=""filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;' +WidthStr + HeightStr + '" id="blendimage" title="' + title + '"  border="0" />';
			}
			else{
				document.getElementById(divid).innerHTML = '<a href="javascript:EnlargeImage(\'' + largephoto + '\',\'' + title.replaceAll("<br>"," - ") + '\')"><img src="' + imagefile + '" style="filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;' +WidthStr + HeightStr + '" id="blendimage" title="' + title.replaceAll("<br>","\n") + '" border="0" /></a>'
			}
		}
		else{
			document.getElementById(divid).innerHTML = '<a href="' + TheLink + '" target="_blank"><img src="' + imagefile + '" style="filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;' +WidthStr + HeightStr + '" id="blendimage" title="' + title.replaceAll("<br>","\n") + '" border="0" /></a>'		
		}
		
		for(i = 0; i <= 100; i++) {
			setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
			timer++;
		}
		//document.getElementById("PhotoTitle").innerHTML = title;
	}
	else {
		//document.getElementById("PhotoTitle").innerHTML = title;
	}
}

function currentOpac(id, opacEnd, millisec) {
	var currentOpac = 100;
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	opacity(id, currentOpac, opacEnd, millisec)
}

function StartSlideShow() {
	if (num<image.length) {
		num = num + 1
		if (image.length > 1){
			if (num==image.length) 
			num=0
			timeDelay=setTimeout("StartSlideShow()",4000) 
			blendimage('blenddiv','blendimage', image[num],500, titles[num], largephoto[num], outerlinks[num], widths[num], heights[num])
		}
		else{
			blendimage('blenddiv','blendimage', image[num],500, titles[num], largephoto[num], outerlinks[num], widths[num], heights[num])
		}
	}
}
