// First Attempt to fix IE preloader problem
//create your own image cache, by creating an array of image objects
//where the source index is the image index, the use image.src



function getImg_onerror(ss,img)
{
    return function(e)
    {
	if (img.seen)
	{
		
	
	
	var source = img.getAttribute("src").split("/")
	
	var t = source.length
	var i = parseInt(Source[t-1].split(".")[0])
	if(ss.limit != -1)
	{
	var i = ss.limit 
	}
	//check to see if last image is an error (if it is remove it (set ss.limit -= 1)
	//var newsrc = new Array()
	//var j = 0
	//for(;j < t-1; j++)
	//{
	//	newsrc[j] = source[j]
	//}
	//newsrc[j+1] = "img"+String(i-1)+".jpg"
	
	//img.src = newsrc.join("/");
	//img.seen = true;
	//img.onload()
	
	img.onload = null
	img.onerror = null
	}
  }
}
    
function getImg_onload(ss,loadUntil,img)
{
    return function(e)
    {
	if(!img.complete)
	    
	    {
	    setTimeout(img.onload,100)
	    }
	    
	else
	{
	    //if it was complete, then move on to the next one
	    
		var gotill = loadUntil
	    //if limit has been set, then set the onload handler to null
		var source = img.getAttribute("src").split("/")
		var t = source.length
		var i = parseInt(source[t-1].split(".")[0])
		var m = document.createElement("img");
		var s = document.createAttribute("src")
		var w = document.createAttribute("height")
		w.value = parseInt(ss.height)
		s.value = source.join("/")
		m.setAttributeNode(s)
		m.setAttributeNode(w)
		if(!(m.width < 500))
		{
			ss.images.push(m)
			var i = i + 1
			
			
			if (i == gotill)
			{
			//alert ("setup is called")
		
		    		ss.setup()
		    		
		    		
			}
		
			img.setAttribute("src",ss.dir+String(i)+"."+ss.ext)
			//alert(ss.dir+String(i)+"."+ss.ext)
				
		}
		
		else
		
		{ 
			//a blank image is loaded so dont do anything with it
		}
	}
    }
}

function trigerFlop(ss)
{
    return function()
    {  
	var source = ss.imageView.getAttribute("src").split("/")
	var t = source.length
	var i = parseInt(source[t-1].split(".")[0]); 
	var len = ss.images.length
	var replace = ss.images[i].cloneNode(false)
	
	ss.fade.HTMLNode.replaceChild(replace,ss.imageLoad) //.setAttribute("src",source.join("/"));
	ss.imageLoad = replace
	ss.fade.setStyle("opacity","1")
	
	//set the view image (ie the image faded to) to the next image in the
	//slide show
	//alert(ss.dir+String(i%(ss.limit))+"."+ss.ext)

	
	replace = ss.images[(i+1)%len].cloneNode(false)
	ss.view.HTMLNode.replaceChild(replace,ss.imageView)//.setAttribute("src",ss.dir+String((i+1)%ss.limit)+"."+ss.ext);
	ss.imageView = replace
    }
}

function nextSlide(ss)
{
    return function()
    {
	//var source = ss.imageLoad.getAttribute("src").split("/")
	//var t = source.length
	//var i = parseInt(source[t-1].split(".")[0])
	//i = (i + 1)%ss.limit
	//ss.imageView = ss.images[i].src//.setAttribute("src", ss.dir + i + "." + ss.ext)
	//ss.hndl.HTMLNode.replaceChild(ss.images[i],ss.imageView)
	//ss.imageView = ss.images[i]
	//start fade animation here for the fade elemeint
	//call swap at end of animation to restet opacity
	//and the image source to the "view" source which acts
	//like a background
	
	var anim = new Animation({element:ss.fade,style:"opacity",to:"0",behavior:getPredefBehavior("EASEOUT",30),f29:trigerFlop(ss)})
	GLOBAL["ANIMATOR"].registerAnimation(anim);
    }
}


function SlideShow(container,directory,extension,xcoord,ycoord,w,h,parentNode)
{
    this.dir = directory
    this.ext = extension
    this.left = xcoord
    this.top = ycoord
    this.width = w
    this.height = h
    this.parent = parentNode
    this.limit = -1
    this.current = -1
    this.timer = -1
    this.images = new Array()
    //specify the over all container
    this.hndl = container;
    
    this.fade = new DOMNode("div",this.hndl)
    this.view = new DOMNode("div",this.hndl)
    this.view.setStyleByObject({width:"100%",
			        height:"100%",
				overflow:"hidden",
				position:"absolute",
				top:"0px",
				left:"0px",
				opacity:"0",
				backgroundColor:this.hndl.parent.style.backgroundColor,
				zIndex:"1000",
				textAlign:"center"})
    
    this.fade.setStyleByObject({width:"100%",
			        height:"100%",
				overflow:"hidden",
				position:"absolute",
				top:"0px",
				left:"0px",
				opacity:"0",
				backgroundColor:this.hndl.parent.style.backgroundColor,
				zIndex:"1001",
				textAlign:"center"})
    //this.fade.setInnerText("<img id='ss_fade' src='"+this.dir+"0."+this.ext+"'>")
    //this.view.setInnerText("<img id='ss_view' src='"+this.dir+"1."+this.ext+"'>")
    this.imageView = document.createElement("img"); var s = document.createAttribute("src"); s.value = this.dir+"0."+this.ext;
    this.imageView.setAttributeNode(s);
    
    this.imageLoad = document.createElement("img"); var s = document.createAttribute("src"); s.value = this.dir+"1."+this.ext;
    this.imageLoad.setAttributeNode(s);

    this.fade.HTMLNode.appendChild(this.imageLoad)
    this.view.HTMLNode.appendChild(this.imageView)
    
    this.imageLoad.onerror = getImg_onerror(this,0,this.imageLoad)
    this.imageLoad.onload = getImg_onload(this,12,this.imageLoad)
    this.imageLoad.setAttribute("src",this.dir+"0."+this.ext)
    
    this.IE_fix_multiple_setup_calls = false; 
    this.setup = function() 
    { 
      if(this.IE_fix_multiple_setup_calls) 
      { 
        this.setup = null; 
        
        
        //alert ("null")
        return; 
      }
	     
	    
	    
	   } 
	    
      this.IE_fix_multiple_setup_calls = true; //alert ("true") 
      this.imageLoad.setAttribute("src",this.dir+"0."+this.ext)
      this.view.setStyle("opacity","1")
      window.setInterval(nextSlide(this),5000);
      
      
    
}
