var images = Array()

images[0] = "images/home_slide1.jpg"
images[1] = "images/home_slide2.jpg"
images[2] = "images/home_slide3.jpg"
images[3] = "images/home_slide4.jpg"
images[4] = "images/home_slide5.jpg"

var image
var pos
var width = 611
var currImage
var step = 2

// (http://www.clagnut.com/sandbox/imagefades/)
function setOpacity_old(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;
}

// (http://www.splintered.co.uk/experiments/65/)
function setOpacity(obj, opacity){
	if (obj.style) {
		if (obj.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			obj.style.MozOpacity = (opacity/100) - .001;
		} else if (obj.style.opacity!=null) {
			/* CSS3 compatible */
			obj.style.opacity = (opacity/100) - .001;
		} else if (obj.style.filter!=null) {
			/* IE's proprietary filter */
			obj.style.filter = "alpha(opacity="+opacity+")";
		}
	}
}

function loadImage(){
    image = document.getElementById("anim_img")
    image.src = images[currImage]
    image.style.position = "absolute"
    image.style.top = "0"
    pos = width
    image.style.left = pos + "px"
    setOpacity(image, 0)
}

var opacities = Array()

opacities[0] = 0
opacities[1] = 0
opacities[2] = 0
opacities[3] = 0
opacities[4] = 0

var intervalID

function fadeIn(){
    var image = document.getElementById("slot" + currImage)
    
    opacities[currImage] += 1;
    
    setOpacity(image, opacities[currImage])
    
    if (opacities[currImage] >= 100){
        currImage++
        if (currImage == 5){
            window.clearInterval(intervalID)
        }
    }
}

function loaded(){
    for (i = 0; i < 5; i++){
        var image = document.getElementById("slot" + i)
        setOpacity(image, 0)
    }

    var area = document.getElementById("slideshowarea")
    area.style.visibility = "visible"
    currImage = 0
    intervalID = window.setInterval("fadeIn()", 10)
}

function preload(){
    var image = new Image()
    for (i = 0; i < 5; i++){
        image.src = images[i]
    }
}

function startSlideShow(){
    preload()
    loaded()
}

function startSlideShow_old(){
    // hide the table
    var area = document.getElementById("slideshowarea")
    area.innerHTML = ""
    area.innerHTML = "<img id=\"anim_img\"/>"
    
    currImage = 0
    
    loadImage()
    
    window.setInterval("animateSlide()", 10)
    
    // animate each of the images (fade and slide?)
    
    // wash rinse repeat :)
}

function animateSlide(){
    if (image){
        if (pos > 0){
            pos -= step;
            image.style.left = pos + "px"
            setOpacity(image, 100 - ((pos/width) * 100))
        }else{
            currImage++
            if (currImage == images.length){
                currImage = 0
            }
            loadImage()
        }
    }
}

/********************* GOOGLE SLIDESHOW *******************************/
function g_load() {
  var samples = window.location.protocol + "//" + window.location.hostname + "/slideshow.xml";
  var options = {
    displayTime: 4000,
    transistionTime: 600,
    scale:true,
    fullControlPanel : false,
fullControlPanelSmallIcons : false,
	pauseOnHover : false,
    linkTarget : google.feeds.LINK_TARGET_BLANK
  };
  new GFslideShow(samples, "slideShow", options);

}
google.load("feeds", "1");
google.setOnLoadCallback(g_load);
