

/*
1/. Read array
2/. set left margin to == width
3/. load image into background
4/. reduce left-margin to 0
5/. set background image of real back to that of slide
6/ repeat until array is empty


*/

var slideshow={
counter: 0,
repeat: true, //true / false flag to set repeatability of cycle
transition: 'fade', //transition type - currently 'fade' or 'slide'
startdelay: 2000, //delay before slideshow starts
transitiondelay: 2000, //delay between transition starts
transitiontime: 1800, //time taken by transition - should be less than transition delay

start: function()
{
if (document.getElementById("imageBoxSlideshow") && document.getElementById("bannerImages") && $("#bannerImages img").length>0)
{
window.setTimeout("slideshow[slideshow.transition]()",slideshow.startdelay);
slideshow.div = $("#imageBoxSlideshow");
slideshow.imageArray=$("#bannerImages img");
}
},


slide: function()
{
var array=slideshow.imageArray;
var div=slideshow.div;
div.css("marginLeft",div[0].parentNode.offsetWidth);
div.css("backgroundImage","url("+array[slideshow.counter].src+")");
slideshow.counter++;
div.animate({marginLeft: 0},slideshow.transitiontime,slideshow.next);
},

fade: function()
{
//console.debug("starting fade");
var array=slideshow.imageArray;
var div=slideshow.div;
div.css("opacity",0);
div.css("backgroundImage","url("+array[slideshow.counter].src+")");
slideshow.counter++;
div.animate({opacity: 1},slideshow.transitiontime,slideshow.next);
},

reset: {
	slide: function(div,bckgrnd)
	{
	div.style.marginLeft=bckgrnd.clientWidth;
	},
	
	fade: function(div)
	{
	$(div).css("opacity",0);
	}
},

next: function()
{
	var imagebx=document.getElementById("imageBox");
	var slideshw=document.getElementById("imageBoxSlideshow");
	imagebx.style.backgroundImage=slideshw.style.backgroundImage;
	imagebx.style.backgroundPosition="0 0";
	imagebx.style.backgroundRepeat="no-repeat";
	slideshow.reset[slideshow.transition](slideshw,imagebx);
	slideshw.style.marginLeft=imagebx.clientWidth;
	if (slideshow.counter<slideshow.imageArray.length || slideshow.repeat==true) //repeat if iterating through array for the first time, or repeat is true
	{
		//console.debug("starting next transition");
		if (slideshow.counter>=slideshow.imageArray.length && slideshow.repeat==true)
		{
			slideshow.counter=0;
		}
		window.setTimeout("slideshow[slideshow.transition]()",slideshow.transitiondelay);
	}
}


};


$(window).ready(function(){
slideshow.start();

});

