// JavaScript Document

var imageScroll = {
	 ID			: ""
	,$ : function (strID) {
		return document.getElementById(strID);
	}
	,imageIDs	: {
		 Main1 : "image_1"
		,Main2 : "image_2"
		,Fade1 : "image_fade_1"
		,Fade2 : "image_fade_2"
	}
	,ImageFolder : ""
	,Images		: {
		Count	: -1
	}
	,ChangeTime	: 2.5
	,Current	: {
		 Timer		: ""
		,Image		: -1
		,Depth		: {
			 1 : 0
			,2 : 0
		}
		
	}
	,Add		: function (strImage) {
		if (strImage != "") {
			this.Images.Count += 1
			this.Images[this.Images.Count] = {
				Filename	: strImage
			}
			
		}
	}
	,Start		: function () {
		this.$("image_0_1_img").src = this.ImageFolder + this.Images[0].Filename
		this.$("image_0_2_img").src = this.ImageFolder + this.Images[1].Filename
		if (this.Images.Count > 1) {
		this.Current.Image = 1
		this.Current.Timer = window.setInterval(function () {imageScroll.SwapImage();},this.ChangeTime * 1000)
		}
	}
	,SwapImage 	: function () {
		this.Current.Image += 1
		var intCol = 1
		if (this.Current.Image > this.Images.Count) {
			this.Current.Image = 0	
		}
		if ((this.Current.Image % 2) != 0) {
			intCol = 2
		}

		this.doFade(this.$("image_" + this.Current.Depth[intCol] + "_" + intCol),1,0,10,50)
		this.Current.Depth[intCol] = (this.Current.Depth[intCol] == 0) ? 1 : 0
		var strID = (this.Current.Depth[intCol] == 0) ? "Main" : "Fade"
		this.$("image_" + this.Current.Depth[intCol] + "_" + intCol + "_img").src = this.ImageFolder + this.Images[this.Current.Image].Filename
		this.doFade(this.$("image_" + this.Current.Depth[intCol] + "_" + intCol),0,1,10,50)
	}
	,doFade		: function ($,startOpacity,endOpacity,steps,interval,onComplete) {
		if ($.hexEffectFade) {
			window.clearInterval($.hexEffectFade);
			$.hexEffectFade = null
		}
		var actStep = 0;
		$.hexEffectFade = window.setInterval(
			function () {
				$.currentAlpha = imageScroll.getStepValue(startOpacity,endOpacity,steps,actStep)
				$.style.opacity = $.currentAlpha
				$.style.filter = "Alpha(Opacity='" + ($.currentAlpha*100) + "')"
				actStep ++;
				if (actStep > steps) {
					window.clearInterval($.hexEffectFade);
					$.hexEffectFade = null
					if (onComplete) {
						onComplete()
					}
				}
			}
			,interval)
	}
	,getStepValue	: function (minValue,maxValue,totalSteps,actualSteps) {
		return (minValue + ((maxValue - minValue) / totalSteps) * actualSteps)
	}
}

