dojo.require("dojo.fx");

ElementBlog = function()
{
	 this.openNewsNode = 'blog_item_0';
	 this._currentNewsNode = 'blog_item_0';
	 this._item = 0;
};

ElementBlog.prototype.displayNews = function( clicked_node )
{
	 this._currentNewsNode = clicked_node;
	 
	 window.oElementBlog._moveNews();
};

ElementBlog.prototype._moveNews = function()
{
	this._item++;
	if( this._item == Number(window.num_blog_item) )
		this._item = 0;
	
	if ( this._currentNewsNode != this.openNewsNode ) 
    {
   	  var moveArgsOut = {
	            node: this.openNewsNode + '_body',
	            easing:dojo.fx.easing.quadInOut,
	            duration: 1500
	        };
	   	  dojo.fx.wipeOut(moveArgsOut).play();
    }
    
    var moveArgsIn = {
            node: this._currentNewsNode + '_body',
            easing:dojo.fx.easing.quadInOut,
            duration: 1500
        };
   	  dojo.fx.wipeIn(moveArgsIn).play();
	   	  
    //Change Tab style
    oElementBlog._changeTabStyle();
    
    var animA = dojo.fadeOut({
        node:this.openNewsNode + '_body',
        duration: 1000,
        onEnd: function(){
        }
	});
	var animB = dojo.fadeIn( { node:this._currentNewsNode + '_body', 
								duration: 2000 });
	dojo.fx.combine([animA, animB]).play();

    this.openNewsNode = this._currentNewsNode;
    
    this._currentNewsNode = 'blog_item_' + this._item;
    //console.log( this._item );
};

ElementBlog.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.oElementBlog = new ElementBlog();
	
	setInterval("oElementBlog._moveNews()", 4000);

});

