/**
* version: 0.01
*/ 


function Jsbanner() {
	var that = this;
	this.index = 0;
	this.idTimer = null;
	this.stack = new Array();

	this.start = function () {
        showImage( getImage() , gethrefLink() );
        setHover( that.index );
        that.setTimer();
	};
	    
	this.addImage = function( imageLink , hrefLink ) {
		addElement(imageLink , hrefLink);
	};
	
	this.hoverIn = function ( elementIndex ) {
		clearTimer();
		setIndex( elementIndex );
		showImage( getImage() ,gethrefLink() );
		setHover( elementIndex ); 
	};
	
	this.hoverInIn = function() {
	    that.hoverIn( that.index );
	}
	    
	this.hoverOut = function () {
	    that.setTimer();
	};
	
	this.setTimer = function() {
	    that.idTimer = setInterval( function() { rotates(); }  , 3000 );
	}
	

	
	function getImage() {
	    return that.stack[that.index]._src;
	};
	    
	function gethrefLink () {
		return that.stack[that.index]._href;
	};
	    
	function doIndex () {
	    if( that.index+1 >= that.stack.length )
		  setIndex(0);
	    else
		  setIndex( that.index+1 );
	};
	    
	function rotates () {
		doIndex();
		showImage( getImage() , gethrefLink() );
		setHover( that.index );
	}
	    
	function setHover ( elementIndex ) {
	    $("#id_js_banner_up > div").removeClass("hover");
	    $("#id_js_banner_up > div").eq(elementIndex).addClass("hover");
	};
	    
	function showImage ( imageLink , hrefLink ){
	    $("#id_js_banner > a > img").attr('src', imageLink );
	    $("#id_js_banner > a").attr('href', hrefLink );
	};
	

	function setIndex ( newIndex ) {
	    that.index = newIndex;
	};
	    
	function clearTimer() {
	    clearInterval( that.idTimer ); 
	}
	
	function element ( _src, _href ) {
	    this._src = _src;
	    this._href = _href;
	}
	
	function addElement( im, hr) {
	    that.stack.push( new element(im,hr) );
	}
 
};
