// JavaScript Document

	function Banner(id,count,duration,direction,captiontarget,captions)
	{
	    var Me = this;
		this.Player = 0;
		this.Id = id;
		this.Count = count;
		this.Images = new Array();
		this.Duration = duration;
		this.Direction = direction;
		this.CaptionHolder = document.getElementById(captiontarget);
		this.Captions = captions;
		this.Index = 0;
		
		this.Init = function()
		{
			for(var k=0;k<=this.Count;k++)
			{
				var element = document.getElementById(this.Id + k);
				if(element!=null)
				{
					element.style.display = "none";
					Me.Images.push(element);
				}
			}
		};
		
		this.View = function()
		{
			for(var k=0;k<Me.Images.length;k++)
			{
				Me.Images[k].setAttribute("style", "display:none");
			}
			
			var nextPointer = -1;
			if(Me.Direction==null || Me.Direction==undefined)
			{
				if(Me.Index+1>=Me.Images.length)
					nextPointer = 0;
				else
					nextPointer = Me.Index + 1;
			}
			else
			{
				if(this.Index==0)
					nextPointer = Me.Images.length;
				else
					nextPointer = Me.Index - 1;
			}
			Me.Images[nextPointer].setAttribute("style", "z-index:1;display:block");
			Me.Images[Me.Index].setAttribute("style", "z-index:2;display:block");
			
			if(Me.Captions!=null && Me.Captions != undefined )
			{
				if(Me.Captions.length>=Me.Index)
				{
					if(Me.CaptionHolder!=null && Me.CaptionHolder!=undefined)
					Me.CaptionHolder.innerHTML = Me.Captions[Me.Index];
				}
			}
		};
		
		this.Play = function()
		{
		    Me.View();
			Me.Player = setInterval(function()
			{
				if(Me.Direction==undefined || Me.Direction == null)
				{
					$("#" + Me.Images[Me.Index].id).fadeOut("slow", function(){Me.View();});
					if(Me.Index + 1==Me.Images.length)
					    Me.Index = 0;
					else
					    Me.Index += 1;
				}
				else
				{
					if(Me.Index- 1<0)
					    Me.Index = Me.Images.length;
					else
					    Me.Index -= 1;
					$("#" + Me.Images[Me.Index].id).fadeOut("slow", function(){Me.View();});
				}
			},this.Duration);
		};

		this.Pause = function()
		{
			clearInterval(Me.Player);
		};

		this.Previous = function()
		{
			Me.Pause();
		    if(Me.Direction==undefined || Me.Direction == null)
		    {
		        if(Me.Index - 1<0)
    		        Me.Index = Me.Images.length;
		        else
	    	        Me.Index -= 1;
		        Me.View();
		    }
            else
            {
		        if(Me.Index + 1>Me.Images.length)
    		        Me.Index = 0;
		        else
	    	        Me.Index += 1;
		        Me.View();
            }
			Me.Play();
		};

		this.Next = function()
		{
			Me.Pause();
		    if(Me.Direction==undefined || Me.Direction == null)
		    {
		        if(Me.Index + 1>Me.Images.length)
    		        Me.Index = 0;
		        else
	    	        Me.Index += 1;
		        Me.View();
		    }
            else
            {
		        if(Me.Index - 1<0)
    		        Me.Index = Me.Images.length;
		        else
	    	        Me.Index -= 1;
		        Me.View();
            }
			Me.Play();
		};

		this.Initialized = this.Init();
	}


