//set globals for js
var q=0;
var run=0;
var z=0;
var currentimage="";
var object="";
var object2="";
var object3="";
//change the opacity for different browsers
function changeOpac(opacity) {
    object = document.getElementById("mainimage").style;
	
    object.opacity = ((100-opacity)/100);
	/*
    object.MozOpacity = ((100-opacity)/100);
    object2.MozOpacity = ((100-opacity)/100);
    object3.MozOpacity = ((100-opacity)/100);
	
    object.KhtmlOpacity = ((100-opacity)/100);
    object2.KhtmlOpacity = ((100-opacity)/100);
    object3.KhtmlOpacity = ((100-opacity)/100);*/
	
    object.filter = "alpha(opacity=" + (100-opacity) + ")";
	} 

function changeOpac2(opacity) {
    object = document.getElementById("mainimage").style;
    object.opacity = (opacity/100);
	/*
    object.MozOpacity = (opacity/100);
    object2.MozOpacity = (opacity/100);
    object3.MozOpacity = (opacity/100);
	
    object.KhtmlOpacity = (opacity/100);
    object2.KhtmlOpacity = (opacity/100);
    object3.KhtmlOpacity = (opacity/100);*/
	
    object.filter = "alpha(opacity=" + opacity + ")";
	
} 

function blendimage(imageid) {
blendrunning=1;
	if (imageid==currentimage) {
		if (myimages[q].complete) {
	    	var speed = 10;
	    	var timer = 0;
	
	//set the new image as background
   	document.getElementById("maindiv").style.backgroundImage = "url(" + mainarray[q] + ")";
	//document.getElementById(currentdiv2).style.backgroundImage = "url(" + currentarray2[q] + ")";
    //fade out old image
	    	for(i = 0; i <= 100; i++) {
				if (i>75) {  // change link now
				document.getElementById("maintext").href=textarray[q];
			 	}
				if (run==1) {
					// dont do this for IE
					var browserName=navigator.appName; 
					if (browserName!="Microsoft Internet Explorer") {
		    	    setTimeout("changeOpac(" + i + ")",(timer * speed));
					}
				}
	        	timer++;
	    	}
			timer++;
			setTimeout("wrr('"+imageid+"')",(timer*speed));
		} else { 
		keepblendimage(imageid)
		}
	}
blendrunning=0;
}

function keepblendimage(imageid) {
	if (blendrunning==0) {
		blendimage(imageid)
	} else { 
		setTimeout("keepblendimage('"+imageid+"')",100);
	}
}
	
function wrr(imageid) {
	z=0;
	if (imageid==currentimage) {
	   //old image is faded out make new image and set opacity back
		document.getElementById("mainimage").src = mainarray[q];
		var speed = 10;
    	var timer = 0;
		for(i = 0; i <= 100; i++) {
    	    setTimeout("changeOpac2(" + i + ")",(timer * speed));
    	    timer++;
    	}
		q++;
		if (q == mainarray.length) {
			q=0;
		}
	//wash rinse repeat
		if (imageid==currentimage) {
			setTimeout("blendimage('"+imageid+"')",((timer*speed)+3000));
		}
	}
}

var myimages = new Array();
var timer;
blendrunning=0;
function startswap(imagename){
// set globals up for this set
// changetype states whether we change image, background, text, forms etc
 currentimage=imagename;
 q=1;
 run=1;
 //document.getElementById(currentdiv).background = currentarray[0];
 //preload the images
 for (i=0;i<(mainarray.length);i++) {
	myimages[i] = new Image();
	myimages[i].src = mainarray[i];
 }
 var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
 if (IE6 == false) {
 setTimeout("blendimage('" + imagename + "')", 3000);
 }
}