dojo.require("dojo.fx");
dojo.require("dojo.fx.easing");

ElementNews = function()
{
	 this.openNewsNode = 'news_item_0';
	 this._currentNewsNode = 'news_item_0';
	 this._item = 0;
};

ElementNews.prototype.displayNews = function( clicked_node )
{
	 this._currentNewsNode = clicked_node;
	 
	 window.oElementNews._moveNews();
};

ElementNews.prototype._moveNews = function()
{
	this._item++;
	if( this._item == Number(3) )
		this._item = 0;
	
	if ( this._currentNewsNode != this.openNewsNode ) 
    {
   	  var moveArgsOut = {
	            node: this.openNewsNode + '_body',
	            easing:dojo.fx.easing.quadOut,
	            duration: 500
	        };
	   	  dojo.fx.wipeOut(moveArgsOut).play();
    }
    
    var moveArgsIn = {
            node: this._currentNewsNode + '_body',
            easing:dojo.fx.easing.quadOut,
            duration: 800
        };
   	  dojo.fx.wipeIn(moveArgsIn).play();
	   	  
    //Change Tab style
    oElementNews._changeTabStyle();
    
    var animA = dojo.fadeOut({
        node:this.openNewsNode + '_body',
        duration: 500,
        onEnd: function(){
        }
	});
	var animB = dojo.fadeIn( { node:this._currentNewsNode + '_body', 
								duration: 1900 });
	dojo.fx.combine([animA, animB]).play();

    this.openNewsNode = this._currentNewsNode;
    
    this._currentNewsNode = 'news_item_' + this._item;
    //console.log( this._item );
};

ElementNews.prototype._changeTabStyle = function ()
{
	 if( dojo.hasClass( dojo.byId('link_' + this.openNewsNode), 'current' ) )
	 {
		dojo.removeClass( dojo.byId('link_' + this.openNewsNode), 'current' );
	 }
	 dojo.addClass( dojo.byId('link_' + this._currentNewsNode), 'current' );
};


dojo.addOnLoad( function(){
	 window.oElementNews = new ElementNews();
	
	setInterval("oElementNews._moveNews()", 3500);

});

