// ----------------------------------------------------------------------
// GLOBAL VALUES
// ----------------------------------------------------------------------
var current = 0				// Current Image number
var rotate_delay = 5000;	// Delay in milliseconds
var IMGMAX = 2;				// Number of banners
/*var productLink = [
//'http://www.healthy-america.com/Scripts/default.asp?utm_source=banner&utm_campaign=W9K3HA17&emCode=P78',
//'http://www.healthy-america.com/Scripts/default.asp?utm_source=banner&utm_campaign=W9L3HTGS18&emCode=R51',
'http://www.healthy-america.com/Scripts/prodView.asp?idproduct=1359&utm_source=banner&utm_campaign=W9K1HVS8&emCode=P48',
'http://www.healthy-america.com/Scripts/prodView.asp?idproduct=1258&utm_source=banner&utm_campaign=W9D4HRC30&emCode=R89'];*/
var bannerImg = ['../Scripts/images/winter_sales_event.gif','../Scripts/images/shipping_banner.gif'];  
var timer;					// TIMER FOR SLIDESHOW
var status;					// STATUS: PLAY OR STOP
var imgObj;



function init(){
	current = 0;
	status = "stop";
	imgObj = new Image();
	ap();
}


/*function chgPhoto(num){*/
function chgPhoto(){
	imageId = 'spacephoto';

	image = document.getElementById(imageId);
	image.src = bannerImg[current];
/*	document.getElementById(imageId).style.background = "'url("+ bannerImg[current] +") no-repeat left top'";
	document.getElementById('plink').href = productLink[current];*/

	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function rotate(){
	if(status=="play"){
		current = (current == IMGMAX-1) ? 0 : current+1;
		chgPhoto();
		timer = window.setTimeout("rotate()", rotate_delay);
	}else{
		clearTimeout(timer);
	}
}

function ap(){
	
	status = (status == "stop") ? "play" : "stop";
	//document.getElementById("function").src = (status == "stop") ? "../UserMods/images/play.gif" : "../UserMods/images/stop.gif";
	rotate();
}
function next(){
	//if(status == "play") {status = "stop";}
	//document.getElementById("function").src = (status == "stop") ? "../UserMods/images/play.gif" : "../UserMods/images/stop.gif";
	clearTimeout(timer);

	if ((current + 1) < IMGMAX){
		current = current + 1;
		chgPhoto();
	}else{
		first();
	}
}
// Privious
function previous() {
	//if(status == "play") {status = "stop";}
	//document.getElementById("function").src = (status == "stop") ? "../UserMods/images/play.gif" : "../UserMods/images/stop.gif";
	clearTimeout(timer);
	
	if (current-1 >= 0) {
		current = current - 1;
		chgPhoto();
	}else{
		last();
	}
}
// First
function first() {
	current = 0;
	chgPhoto();
}
// Last
function last() {
	current = IMGMAX-1;
	chgPhoto();
}
function stopRotate(){
	clearTimeout(timer);
}



