﻿// JScript File

/*
	Hache Burgers Slideshow JavaScript 
	----------------------------------------------------------------------
	Author  : Marc Watts
	Date    : 27/11/2007
	Website : www.hacheburgers.co.uk
	----------------------------------------------------------------------
	Details : Creates a slideshow of images
	----------------------------------------------------------------------
	History : 
			  27/11/2007 - JavaScript file created. Works within IE 7,
			  			   Moz Firefox 2.0.0.4, Opera 9.21.
	----------------------------------------------------------------------
*/

/* JavaScript Global Parameters*/

// page element - div tag
var slideShowDivId = "back";

// page element - image tag
var slideShowImageId = "front";

// transition time
var slideShowpause = 9000;

// pre load the pictures
var slideShowPics = new Array();

// speed
var slideShowspeed = 20;

// next 
var slideShowNext = 0;

// preload image array
var slideShowpreLoad = new Array();

var maxBannerImages = null;


/* JavaScript Global Parameters End */

function SetupBanner(folderName, numImages)
{
	maxBannerImages = numImages;
	
	// loop through the image urls
	for(var i=0; i < numImages; i++)
	{
		slideShowPics[i] = new Image();
		slideShowPics[i].src = "/images/"+folderName+"/" + i + ".jpg";
	}
	setTimeout("SlideShowInitiate()", slideShowpause);
}



/* main controlling function for the script */
function SlideShowInitiate()
{
	// assign the current image to the image
	var slideShownewimage = document.getElementById(slideShowImageId);
	slideShownewimage.src = slideShowPics[slideShowNext].src;
	
	// next number
	slideShowNext_img = slideShowNext+1;
	
	// make sure the num does exceed number of images
	if(slideShowNext_img >= maxBannerImages)
		slideShowNext_img = 0;
	
	// assign the next image to the div
	document.getElementById(slideShowDivId).style.backgroundImage = "url(" + slideShowPics[slideShowNext_img].src + ")";
	
	var slideShowlgr = slideShowPics[slideShowNext].src;
    
	// fade the image
	SlideShowFade();
	SlideShowChangeOpac(100, slideShowImageId);
	
	// assign the next
	slideShowNext = slideShowNext_img;
		
	// repeat
	setTimeout("SlideShowInitiate()", slideShowpause);
}

/* function to fade the image from the current to the next */
function SlideShowFade()
{
	// initiate timer variable
	var slideShowTimer = 0;
    // fade out image
    for(var slideShowI=100; slideShowI >= 0; slideShowI--,slideShowTimer++)
        setTimeout("SlideShowChangeOpac(" + slideShowI + ",'" + slideShowImageId + "')",(slideShowTimer * slideShowspeed));
	return;
}


/* change the opacity for different browsers */
function SlideShowChangeOpac(slideShowopacity, slideShowid) 
{
	// get the document object
    var slideShowobject = document.getElementById(slideShowid).style;
	// change the opacity
    slideShowobject.opacity = (slideShowopacity / 100);
	// change the mozilla opacity
    slideShowobject.MozOpacity = (slideShowopacity / 100);
	// change cross browser opacity
    slideShowobject.KhtmlOpacity = (slideShowopacity / 100);
	// change the filter setting of the image
    slideShowobject.filter = "alpha(opacity=" + slideShowopacity + ")";
	return;
}