
 var currentImg;
 var alpha;
 var targetImage;
 var _me;
	
 function setBGImage(id){
	_me.src = imgs[id];
	fixBGSize();
 }
 function fixBGSize(){
	/****************
	original image sizes, may come from db later			
	*****************/
	var origWidth = 1024;
	var origHeight = 834;
	/*****************/
	var windowWidth;
	var windowHeight;
	var scaleFactor;
	
	if(isIE){
		windowWidth = document.body.offsetWidth;
		windowHeight = document.body.offsetHeight;
	}else{
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	}
	var factorX = windowWidth/origWidth;
	var factorY = windowHeight/origHeight;
	if(factorX > factorY){
		scaleFactor = factorX;
	}else{			
		scaleFactor = factorY;
	}
	_me.width = scaleFactor*origWidth;
	_me.height = scaleFactor*origHeight;
	_me.style.left = (windowWidth-_me.width)/2;
	_me.style.top = (windowHeight-_me.height)/2;
 }
 function switchImg(){
	
	targetAlpha = 0;
 }
 function nextImage(){
	currentImg++;
	if(currentImg == imgs.length){
		currentImg = 0;
	}	
	setBGImage(currentImg);
 }
 function upKeep(){
	var process = false;
	if(alpha > targetAlpha){
		alpha -= 20;
		process = true;
	}else if(alpha < targetAlpha){
		alpha += 20;
		process = true;
	}else if(targetAlpha == 0){
		targetAlpha = 100;
		nextImage();
	}
	if(process){
		if(isIE){
			_me.filters.item("DXImageTransform.Microsoft.Alpha").opacity = alpha;
		}else{
			_me.style.opacity = alpha/100;
		}
	}
 }
 function init(){	imgs = imgs.split(",");
	_me = document.getElementById("homepageImageTag");

	currentImg = Math.floor(Math.random()*imgs.length);
	//alpha = 100;
	//targetAlpha = 100;
	nextImage();
	 
	window.onresize = fixBGSize;
	
	//setInterval(switchImg, 10000);
	//setInterval(upKeep, 33);
	
 }
