var t;
var timer_is_on=0;
var fadeimages=new Array();
var loadedImages=new Array();
var numImage=0;


function setScreenArray() {
//SET SCREEN IMAGE PATHS.
fadeimages[0]="http://www.swhowellcontractinginc.com/images/slideshow/mwS1.jpg";
fadeimages[1]="http://www.swhowellcontractinginc.com/images/slideshow/mwS2.jpg";
fadeimages[2]="http://www.swhowellcontractinginc.com/images/slideshow/mwS3.jpg";
fadeimages[3]="http://www.swhowellcontractinginc.com/images/slideshow/mwS4.jpg";
fadeimages[4]="http://www.swhowellcontractinginc.com/images/slideshow/mwS5.jpg";
}
function setContractingArray() {
//SET CONSTRUCTION IMAGE PATHS.
fadeimages[0]="http://www.swhowellcontractinginc.com/images/slideshow/mwC1.jpg";
fadeimages[1]="http://www.swhowellcontractinginc.com/images/slideshow/mwC2.jpg";
fadeimages[2]="http://www.swhowellcontractinginc.com/images/slideshow/mwC3.jpg";
fadeimages[3]="http://www.swhowellcontractinginc.com/images/slideshow/mwC4.jpg";
}



/*custom dinosaur
function preloadArray() {

	//if first run, load up first set of images
	if (loadedImages.length < 1){
	//loop through images, preloading array
	for (p=0;p<fadeimages.length;p++){
		loadedImages[p]=new Image();
		loadedImages[p].src=fadeimages[p];
	}
	}
	else
	{
		//not first run, append
		var startIndex = loadedImages.length - 1;
		//loop through images, preloading array
		for (p=0;p<fadeimages.length;p++){
			loadedImages.push(new Image());
			loadedImages.pop.src=fadeimages[p];
			}
	}
	
}*/

function clearFadeArray()
{
 fadeimages.length = 0; 
}



//Start it going in pageload
function initArray() {
	
	//SET Screen IMAGE PATHS.
	setScreenArray();

	//Preload slide images
	StartPreload();	
	
	//only execute fading AFTER preloading is complete...
	executeFade();
}

function executeFade()
{

	   //increment image
	   numImage++;	 

	   //if runout, return to zero
	   if (numImage==(fadeimages.length*1))
       {    
            numImage=0;

       }
	   //execute new slide after timeout
       t = setTimeout("executeFade2()",4000);	  
 
}

function executeFade2()
{
//only fade if not stopped
if (!timer_is_on)
  {
  timer_is_on=1;

     //do the real work
      blendimage('blenddiv', 'blendimage', fadeimages[numImage], 500);
	  executeFade();
	  }
	    timer_is_on=0;
}


//set slideshow to screens
function showScreens()
{
document.getElementById("mwInnerTextScreen").style.display = 'block';
document.getElementById("mwInnerTextContr").style.display = 'none';
document.getElementById("mwPointTxtL").style.color = '#333333';
document.getElementById("mwPointTxtR").style.color = 'white';

clearTimeout(t);
  timer_is_on=0;
  
//fadeimages.clear();
//fadeimages=null;
clearFadeArray();


/*SET RETRACTABLE SCREENS IMAGE PATHS.*/
setScreenArray();

//set the current image
document.getElementById("blendimage").src = fadeimages[0];
document.getElementById("blenddiv").style.backgroundImage = "url(" + document.getElementById("blendimage").src + ")";

numImage=0;
executeFade();
}

//set slideshow to contracting
function showContracting()
{
document.getElementById("mwInnerTextScreen").style.display = 'none';
document.getElementById("mwInnerTextContr").style.display = 'block';
document.getElementById("mwPointTxtL").style.color = 'white';
document.getElementById("mwPointTxtR").style.color = '#333333';

clearTimeout(t);
  timer_is_on=0;
  
//fadeimages.clear();
//fadeimages=null;
clearFadeArray();

//SET CONSTRUCTION IMAGE PATHS.
setContractingArray();

//set the current image as background
document.getElementById("blendimage").src = fadeimages[0];
document.getElementById("blenddiv").style.backgroundImage = "url(" + document.getElementById("blendimage").src + ")";

numImage=0;
executeFade();
}







function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	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++;
		}
	}
}

//change the opacity for different browsers
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 an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {

	var speed = Math.round(millisec / 100);
	var timer = 0;

	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}

}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function hideClass(theClass){
 var allTags = getElementsByTagName('*');
 for(i=0; i<allTags.length; i++){
  if(allTags[i].className == theClass) allTags[i].style.display = 'none';
 }
}

function showClass(theClass){
 var allTags = getElementsByTagName('*');
 for(i=0; i<allTags.length; i++){
  if(allTags[i].className == theClass) allTags[i].style.display = 'inline';
 }
}
