// JavaScript Document

var objBannerImages = {
	Images	: {
		 0 : {
		 	File : ""
			}
	}
	,CurrentImage 	: 0
	,CurrentLayer	: 0
	,NextImage		: null
	,NextLayer		: null
	,Initialised	: false
	,Interval	: {
		 Swap	: null
		,Fade	: null
		,SwapTime 	: 2
		,FadeInterval: 50
		,FadeAmount : 10
	}
	,CurrentFade	: 0
	,Layer			: {
		 0 : null
		,1 : null
	}
	,Root			: ""
	,Folder			: ""
	,ResizePath		: "includes/getimage.asp"
	,ImageCount 	: 0
	,Add			: function (strImage) {
		this.ImageCount ++
		this.Images[this.ImageCount] = {
			 	File : strImage
			}
	}
	,ThumbNails	: {
		 Show : true
		,Width : 50
		,Height : 30
		,ContainerHeigth : 215
	}
	,Init		: function () {
		if (!this.Initialised) {
			this.Initialised = true
			var strFirstImage = hex.$("banner_image").style.backgroundImage;
			if (strFirstImage != "" && this.ImageCount > 0) {
				this.Layer[0] = hex.$("banner_image_1");
				this.Layer[1] = hex.$("banner_image_2");
				if (this.Layer[0] != null && this.Layer[1] != null) {
					this.CurrentImage = 0
					strFirstImage = strFirstImage.replace(this.Root,"");
					strFirstImage = strFirstImage.replace(this.Folder,"");
					strFirstImage = strFirstImage.replace(/url\(|(\)|\")/gi,"");
					//var arrFirstImage = strFirstImage.split("/")
					//strFirstImage = arrFirstImage[arrFirstImage.length-1]
					this.Images[0].File = strFirstImage;
					hex.$("banner_image").style.backgroundImage = "none";
					this.Layer[this.CurrentLayer].style.backgroundImage = "url(" + this.Root + this.Folder + this.Images[this.CurrentImage].File +")"
					
					this.LoadNextLayer()
					this.StartSwapTimer()
					//this.Interval.Swap = window.setInterval(function () {objBannerImages.DoFadeSwap()},(this.Interval.SwapTime*1000))
				}
			}
			
		}
	}
	,LoadNextLayer	: function () {
		var intNextLayer = (this.CurrentLayer == 0) ? 1 : 0;
		var intNextImage = this.CurrentImage +1;
		if (intNextImage > this.ImageCount) intNextImage = 0;
		this.Layer[intNextLayer].style.opacity = 0
		this.Layer[intNextLayer].style.filter = "Alpha(Opacity='0')"
		this.Layer[intNextLayer].style.backgroundImage = "url(" + this.Root + this.Folder + this.Images[intNextImage].File +")"
		this.NextLayer = intNextLayer
		this.NextImage = intNextImage
	}
	,StartSwapTimer		: function () {
		window.clearInterval(this.Interval.Swap)
		this.Interval.Swap = window.setTimeout(function () {objBannerImages.DoFadeSwap()},(this.Interval.SwapTime*1000))
	}
	,DoFadeSwap			: function () {
		window.clearInterval(this.Interval.Swap)
		this.CurrentFade 	= 100
		this.Interval.Fade 	=  window.setInterval(function () {objBannerImages.DoFade();},this.Interval.FadeInterval)
		
	}
	,ShowImage			: function (intIndex) {
		window.clearInterval(this.Interval.Swap);
		window.clearInterval(this.Interval.Fade);
		if (intIndex != this.CurrentImage) {
			this.CurrentLayer = 0;
			this.CurrentImage = intIndex;
			this.Layer[this.CurrentLayer].style.opacity =1
			this.Layer[this.CurrentLayer].style.filter = "Alpha(Opacity='100')"
			this.Layer[this.CurrentLayer].style.backgroundImage = "url(" + this.Root + this.Folder + this.Images[this.CurrentImage ].File +")"
			this.LoadNextLayer()
		}
	}
	,ResumeSwap			: function () {
		this.StartSwapTimer()
	}
	,DoFade				: function () {
		this.CurrentFade -= this.Interval.FadeAmount
		if (this.CurrentFade > -1) {
			this.Layer[this.CurrentLayer].style.opacity = this.CurrentFade/100
			this.Layer[this.CurrentLayer].style.filter = "Alpha(Opacity='" + this.CurrentFade + "')"
			
			this.Layer[this.NextLayer].style.opacity = (100-this.CurrentFade)/100
			this.Layer[this.NextLayer].style.filter = "Alpha(Opacity='" + (100-this.CurrentFade) + "')"
		}else{
			this.CurrentLayer = this.NextLayer
			this.CurrentImage = this.NextImage
			this.LoadNextLayer()
			window.clearInterval(this.Interval.Fade)
			this.StartSwapTimer()
		}
	}
}
