// JavaScript Document
var slideShowSpeed = 10000

// Duration of crossfade (seconds)
var crossFadeDuration = 10

// Specify the image files
var Pic = new Array() 
Pic[0] = 'x4mainImage_1.jpg'
Pic[1] = 'x4mainImage_6.jpg'
Pic[2] = 'x4mainImage_3.jpg'
Pic[3] = 'x4mainImage_4.jpg'
Pic[4] = 'x4mainImage_5.jpg'
Pic[5] = 'x4mainImage_2.jpg'
Pic[6] = 'x4mainImage_7.jpg'



// =======================================
// do not edit anything below this line
// =======================================
var t
var j = 0
var p = Pic.length
var loc = "images/x4mainImages/"

//randomize a number to start with
j = Math.floor(Math.random() * p);


var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = loc + Pic[i]
}

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 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 <= 99; i++)
{
setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
timer++;
}
}

function RunSlideShow(divid,imageid,displaySecs)
{

changeOpac(0, imageid);
blendimage(divid,imageid,preLoad[j].src,1000);

setTimeout("RunSlideShow('"+divid+"','"+imageid+"',"+displaySecs+")",displaySecs*1000);
   j = j + 1
   if (j > (p-1)) j=0

}



















/*
function runSlideShow(){	



   if (document.all){
      document.images.center.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.center.filters.blendTrans.Apply()   
   }
   else
   {
		document.getElementById('center').style.opacity = 0;
		shiftOpacity('center',1000);
	}
    
		//set the image
	document.images.center.src = preLoad[j].src

	

   if (document.all){
	  document.images.center.filters.blendTrans.Play()
   }
   
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

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 fadeIn(objId,opacity) {
       if (document.getElementById) {
               obj = document.getElementById(objId);
               if (opacity <= 100) {
                       setOpacity(obj, opacity);
                       opacity += 20;
                       window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
               }
       }
}
function fadeOut(objId,opacity) {
       if (document.getElementById) {
               obj = document.getElementById(objId);
               if (opacity >= 0) {
                       setOpacity(obj, opacity);
                       opacity -= 20;
                       window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
               }
       }
}
function setOpacity(obj, opacity) {
       opacity = (opacity == 100)?99.999:opacity;
       // IE/Win
       if ( obj.style.filter )
       {
         obj.style.filter = "alpha(opacity:"+opacity+")";
       }
       // Safari<1.2, Konqueror
       else if ( obj.style.KHTMLOpacity )
       {
         obj.style.KHTMLOpacity = opacity/100;
       }
       // Older Mozilla and Firefox
       else if ( obj.style.MozOpacity )
       {
         obj.style.MozOpacity = opacity/100;
       }
       // Safari 1.2, newer Firefox and Mozilla, CSS3
       else 
       {
         obj.style.opacity = opacity/100.0;
       }
}
*/
