/**
 * billboardManager
 *
 * @package    mivilagunk
 * @subpackage Manager
 * @author     Szijártó Tamás ( szicsu ) <szicsu@jquery.hu>
 * @version    SVN: $Id: $
 */
billboardManager = new function(){
	var self = this;
	
	this.data = {};
	this.containerObj;
	this.timer;
	this.timerTime;
	
	this.init = function( containerObj ){
		
		this.containerObj = containerObj;
		
		this.containerObj
			.find('.jsBillboardPagerLink').bind('click', function(){
				
				data = self.getItem( $(this).attr('rel') );
				
				$('.jsBillboardImg', self.containerObj).attr('src', data.img );
				$('.jsBillboardLink', self.containerObj)
					.attr('href', data.link )
					.text( data.title );
				$('.jsBillboardLead', self.containerObj).html( data.lead );	
				
				$('.jsBillboardPagerLink.active').removeClass('active');
				$(this).addClass('active').trigger('blur');
				
				self.resetTimer();
				
				return false;
			});
	}
	
	this.initTimer = function( time ){
		
		self.timerTime = time;
		
		self.timer = setInterval( function(){
		
			if( ( aItem = $('.jsBillboardPagerLink.active', self.containreObj ).parent().nextAll('li').find('.jsBillboardPagerLink')[0] ) ){
				aObj = $(aItem);
			}
			else{
				aObj = $('.jsBillboardPagerLink', self.containreObj ).eq(0);
			}
			
			aObj.trigger('click');
			
		}, self.timerTime);
		
	}
	
	this.resetTimer = function(){
		
		if( self.timer ){
			window.clearInterval( self.timer );
			self.initTimer( self.timerTime );
		}
	}
	
	/**
	 *
	 */
	this.addData = function( data ){
		this.data = data;
		this.preloadingImages();
	}
	
	/**
	 *
	 */
	this.preloadingImages = function(){
	
		for( var i in this.data ){
			Site.Helper.cacheImage( this.data[i].img );
		}
	}
	
	this.getItem = function( id ){
		
		return this.data[ id ] || false;
	}
}	