/**
 * Chameleon Javascript Library
 * Script: cs.slideshow.js
 *
 * Notes:
 * -> Fade only works in IE5.5+
 * -> Other browsers will have a slide show without the fade
 **/

// ================// Script Variables //============================================================ //

// Set the start time
var start_time = 100;

// Set the fade speed
var fade_speed = 5;

// set the time to pause on default image
var default_pause = 100;

// set the time to pause on the ad
var ad_pause = 6000;

// Specify which images to use:
var Pic = new Array();
var imagefolder = '/images/slides';

Pic[0] = imagefolder + '/1.jpg';
Pic[1] = imagefolder + '/2.jpg';
Pic[2] = imagefolder + '/3.jpg';
Pic[2] = imagefolder + '/4.jpg';

// ================// End Script Variables //======================================================== //

var i = 0;

var imageId = 'slide';

var p = Pic.length;
var preLoad = new Array();
for (j = 0; j < p; j++){
   preLoad[j] = new Image();
   preLoad[j].src = Pic[j];
}

function initImage() {
	
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  image.src=preLoad[i].src;
  window.setTimeout("fadeIn(0)", start_time);
}

function fadeIn(opacity) {
  if (document.getElementById) {
    obj = document.getElementById(imageId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn("+opacity+")", fade_speed);
    } else {
	  window.setTimeout("fadeOut(100)", ad_pause);
	}
  }
}

function fadeOut(opacity) {
  if (document.getElementById) {
    obj = document.getElementById(imageId);
    if (opacity >= 0) {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut("+opacity+")", fade_speed);
    } else {
	  i++;
	  if (i==preLoad.length) i = 0;
 	  obj.src=preLoad[i].src;
	  window.setTimeout("fadeIn(0)", default_pause);
	}
  }
}

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;
}

window.onload = function() {initImage()}

