/************************
Script by Mamed Mamedov.
Desc: GenieSpace.GenieTimer
      A usefull timer ticker
      An object-based version
Date: 28.05.2009 16:09:36
************************/
genieSpace.genieTimer = {

    objectList: [],
    timeList: [],
    sleepList:[],
    dd: [],
    h: [],
    ff: [],
    
    defineObject: function( searchString, timeLeft, sleep, act ){
        if( ! searchString )
        {
            return false;
        }
	var o = jQuery( searchString );
        if( o )
	{
	    this.objectList.push( o );
	    //alert( o.text( ) );
	    this.timeList.push( timeLeft );
	    this.sleepList.push( sleep * 1000 );
	    this.dd.push( new Date( timeLeft * 1000 ) )
	    this.ff.push( act );
	}
	
        return true;
    }, //defineObject
    
    startTimers: function( ){
	for( var a in this.objectList )
	{
	    with( this.dd[a] )
	    {		
		this.h[a] = setInterval( "genieSpace.genieTimer.ticker( " + a + ", " +  this.sleepList[a]  + " )", this.sleepList[a]);
	    }
	}
    }, //startTimers
    
    ticker: function( a, value ){
	
	var n = this.dd[a].valueOf( );
	if( n < value )
	{
	    clearInterval( this.h[a] );
	    if( this.ff[a] )
	    {
		setTimeout( "genieSpace.genieTimer.ff[" + a + "]( )", 2000 );
		this.objectList[a].html( '<img src="/img/icons/wait.gif" />' );
		return;
	    }	    
	}
	else
	{
	    this.dd[a] = new Date( n - ( value ) );
	}	
	var d = this.dd[a];	
	this.objectList[a].text(
	    [ d.getUTCHours( ), d.getUTCMinutes( ), d.getUTCSeconds( ) ].join( ':' )
	);
	
	
    }, //ticker


    init: function( ){

    } //init
}

jQuery( document ).ready( function( ){
    with( genieSpace.genieTimer )
    {
        init( );
    }
} );
