var radarok = new Array();

function radar(instance,delay)
{
	this._instance = instance;

    this._delay = delay ? delay : 300;
    
	this._sls_timer = null;
	this._sls_counter = 0;
	
    this._load_counter = 0;
    
	this._imgs = new Array();
	this._imgurls = new Array();
	this._imgtexts = new Array();
	
	/**
	 * Slideshow timer
	 */
	this._sls = function(dir)
	{
		this.showImage(this._imgs[this._sls_counter],this._imgtexts[this._sls_counter]);

		delay = this._delay;
		if (dir == 1) // Rewind
		{
			this._sls_counter--;
			if (this._sls_counter == -1) { this._sls_counter = this._imgs.length-1; }
		}
		else // Forward
		{
			this._sls_counter++;
			if (this._sls_counter == this._imgs.length) { this._sls_counter = 0; delay = 2000; }
		}
		this._sls_timer = window.setTimeout("radarok["+this._instance+"]._sls("+dir+")",delay);
	}

	/**
	 * Loads an image
	 */
	this.imageLoader2 = function(i)
	{
		var inst = this;
		this._imgs[i] = $("<img />").load(function(event) {
            inst._load_counter++;
            prec = Math.round(inst._load_counter/inst._imgs.length*100);
            $("#loaderbar_"+inst._instance).width(prec+"%");
            if (inst._imgs.length == inst._load_counter)
            {
                $("#loader_"+inst._instance).animate({"opacity":0},500,function() { $(this).hide(); });
                inst.startSlideshow();
            }
        }).attr("src",this._imgurls[i])[0];
	}

	/**
	 * Starts the slideshow 
	 */
	this.startSlideshow = function()
	{
		if (this._imgs.length == this._imgurls.length)
		{ 
			this._imgurls = new Array();
			this._sls(0);
		}
	}

	this.start = function() {
		this.stop(); this._sls(0);
	}
	this.rew = function() {
		this.stop(); this._sls(1);
	}
	this.stop = function() {
		window.clearTimeout(this._sls_timer);
	}

	/**
	 * Displays the parameter image in the image container
	 * Parameters:	img - ImageObject
	 */
	this.showImage = function(img,text)
	{
		$("#imgc_"+this._instance).children().remove().end().append(img);
		$("#textc_"+this._instance).html(text);
	}

	/**
	 * Adds an Image URL to the _imgurls array
	 */
	this.addImageURL = function(url) {
		this._imgurls.push(url);
	}

	/**
	 * Adds an text to the _imgtexts array
	 */
	this.addImageText = function(text) {
		this._imgtexts.push(text);
	}

	/**
	 * Starts the loading sequence
	 */
	this.init = function()
	{
		var inst = this;
		$("#btn_"+this._instance).toggle(function(event) {
			inst.stop();
			$(this).val("Start");
		},function(event) {
			inst.start();
			$(this).val("Stop");
		});

		for (i in this._imgurls) this.imageLoader2(i);
	}
}

function ikon_link_on(id)
{
	$('#'+id+'_link').css("textDecoration",'underline');
	$('#'+id+'_mask_over').show();
	$('#'+id+'_mask_out').hide();
}

function ikon_link_off(id)
{
	$('#'+id+'_link').css("textDecoration",'none');
	$('#'+id+'_mask_over').hide();
	$('#'+id+'_mask_out').show();
}