$CT_AnimatedBanner.prototype.Count	 		= 0;
$CT_AnimatedBanner.prototype.TimerInstance 	= null;
$CT_AnimatedBanner.prototype.TimeOut 		= 2500;
$CT_AnimatedBanner.prototype.ImageArray		= null;
$CT_AnimatedBanner.prototype.Tag			= null;

var CT_ANIMATED_BANNER_IMAGE_TARGET = {Self:0, Blank:1};

function $CT_AnimatedBanner(tag, time_out){

    this.Count = 0;
	this.Instance = null;
	
	this.Tag = tag;

	if(time_out == null)
		this.TimeOut = 2500;
	else
		this.TimeOut = time_out;
}

$CT_AnimatedBanner.prototype.AddImage = function(url, image_url, target) {

    var length;

    if (this.ImageArray == null) {
        this.ImageArray = new Array();

        this.ImageArray[0] = new Array(2);
        this.ImageArray[0][0] = url;
        this.ImageArray[0][1] = image_url;
        this.ImageArray[0][2] = target;
    }
    else {
        if (this.ImageArray.length == 0) {

            this.ImageArray = new Array();

            this.ImageArray[0] = new Array(2);
            this.ImageArray[0][0] = url;
            this.ImageArray[0][1] = image_url;
            this.ImageArray[0][2] = target;
        }
        else {
            length = this.ImageArray.length;

            this.ImageArray[length] = new Array(2);
            this.ImageArray[length][0] = url;
            this.ImageArray[length][1] = image_url;
            this.ImageArray[length][2] = target;
        }
    }
}

$CT_AnimatedBanner.prototype.Execute = function() {
    var bannerImg = new Image();
    var thisObj = this;
    var array;

    this.Count++;
    if (this.Count == this.ImageArray.length)
        this.Count = 0;

    array = this.ImageArray[this.Count];
    bannerImg.src = array[1];
    eval("document." + this.Tag + ".src='" + bannerImg.src + "'");

    thisObj = this;
    this.TimerInstance = setTimeout(function() { thisObj.Execute(); }, this.TimeOut);
}

$CT_AnimatedBanner.prototype.Pause = function()
{
    clearTimeout(this.TimerInstance);
    eval("document." + this.Tag + ".style.cursor='pointer'");
}

$CT_AnimatedBanner.prototype.Restart = function() {

    eval("document." + this.Tag + ".style.cursor='default'");
    thisObj = this;
    this.TimerInstance = setTimeout(function() { thisObj.Execute(); }, 1000);
}

$CT_AnimatedBanner.prototype.OnClickEvent = function()
{
	var type = this.ImageArray[this.Count][2];
	
	if(type == CT_ANIMATED_BANNER_IMAGE_TARGET.Self)
		window.location = this.ImageArray[this.Count][0];
	else
		window.open(this.ImageArray[this.Count][0]);
}


