// PRELOAD these images
image1 = new Image(529,350);
image1.src = "img/pic1.jpg";
image2 = new Image(760,506);
image2.src = "img/pic2.jpg";
image3 = new Image(335,244);
image3.src = "img/pic3.jpg";
image4 = new Image(350,233);
image4.src = "img/pic4.jpg";

function loopy (s) {
	var time = (Number(s) * 1000); // set into milliseconds for setInterval();
	setInterval ('run()', time);
}

cur = 1;
max = 4;

function run () {
	cur = (cur == max) ? 1 : cur + 1;
	swapImage ("billboard", "blender", "image"+cur);
}

// SWAP IMAGE FUNCTION for MinInfo
// (C) 2005 Panic, Inc. / Cabel Sasser
//
// Cross-fade between the two images, and swap out the thumbnail with the highlighted thumbnail

function swapImage(divID, imageID, imageToSwap) {

  globalDivID = divID;
  globalImageID = imageID;

  if (document.getElementById(imageID).src.indexOf(eval(imageToSwap+".src")) == -1) {

  	// Set the background image to the currently displaying image
    // This is now done on HTML render and when fade is complete
  	// document.getElementById(divID).style.backgroundImage = "url(" + document.getElementById(imageID).src + ")";
  
  	// Set the top image to invisible
  	setOpacity(0, imageID);

  	// Set the top image to the target image
  	document.getElementById(imageID).src = eval(imageToSwap+".src");
    
  	// Slowly fade in the top image back to visible
  	fadeElementSetup(imageID, 0, 100, 20);

  } else {

	 // alert("Already Set");

  }
}

// FADE ITEM function
// (C) 2005 Panic, Inc.
//
// Ex: href="javascript:fadeElementSetup('testimg',100,0,10)"
// Because we can't accruately get the opacity of an item (it's always zero),
// we must force a start and an end (it can't be computed on the fly).
// So, call this as a normal function.
//
// Pass opacity values from 1 - 100.

function fadeElementSetup(theID, fdStart, fdEnd, fdSteps) {
  fadeSteps = fdSteps;
  fadeCurrent = 0;
  fadeAmount = (fdStart - fdEnd) / fadeSteps;
  fadeTimer = setInterval("fadeElement('"+theID+"')", 50);
}

function fadeElement(theID) {
  fadeCurrent++;
  // Set the opacity depending on if we're adding or subtracting (pos or neg)
  if (fadeAmount < 0) {
    setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);
  } else {
    setOpacity(100 - (fadeCurrent * fadeAmount), theID);
  }
  if (fadeCurrent == fadeSteps) {
    // We're done, so clear
    clearInterval(fadeTimer);

    // Here's "mininfo" specific code, that sets the background to be prepared for the next fade
    // Set the background image to the currently displaying image
    document.getElementById(globalDivID).style.backgroundImage = "url(" + document.getElementById(globalImageID).src + ")";

  }
}

function setOpacity(opacity, theID) { 

  var object = document.getElementById(theID).style;

  // If it's 100, set it to 99 for Firefox.

  if (navigator.userAgent.indexOf("Firefox") != -1) {
    if (opacity == 100) { opacity = 99.999; } // This is majorly retarded
  }

  // Multi-browser opacity setting

  object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
  object.KhtmlOpacity = (opacity / 100);            // Safari 1.1 or lower, Konqueror
  object.MozOpacity = (opacity / 100);              // Older Mozilla+Firefox
  object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}
