var newsTabSlider = Class.create({
  initialize: function(controls, divsClass,  itemsClass) {
	try{
		this.bAutoSlide = false;
		this.controlBtns= $(controls).childElements();
		this.itemsClass = itemsClass;
		this.divsClass  = divsClass;
		this.container	= $(divsClass);
		this.slides		= $$('.'+this.divsClass+' < div[class~='+this.itemsClass+']');
		this.timeout	= {};
		this.hideAll();
		this.showTab(0);
		this.observeBtn();
		//this.startAutoSlide();
	}
	catch(e){
		// console.log("adSlider started with error: "+e);	
		}
	},
		
	hideAll: function(){
		this.slides.invoke("hide");
	},
	
	fx: function (objNo)
	{
		el = this.slides[objNo];
		//el.siblings().find($$('.')).fade();
		el.appear();	
	},

	showTab: function(objNo)
	{
		//diff_x =  this.startPoint - (Position.cumulativeOffset( this.slides[objNo] )[0]) ;
		this.fx(objNo);
		this.fxBtn(objNo);
	},

	fxBtn: function (objNo)
	{
		el = $(this.controlBtns)[objNo];
		if(el.hasClassName('activeTitle') )return false;
		try{
			$($$('.activeTitle')[0].toString().split("#")[1]).fade();
			$$('.activeTitle')[0].removeClassName('activeTitle')
		}catch(e){}
		el.addClassName('activeTitle');	
	},
	
	autoSlide: function(startID)
	{
		o = this;
		if(! this.bAutoSlide ) return;
	
		if (isNaN(startID) ) startID = 0;
		nextID = (startID+1) % this.slides.length;		
		
		this.showTab(startID);
		o.timeout	=	setTimeout( "o.autoSlide("+nextID	+")", 3500);
		//console.log(" next awaiting ...");
	},
	
	observeBtn : function ()
	{
		var o = this;
		this.controlBtns.each( function(e, index){
			if( e.tagName == "A") {
				e.onclick = function(elEvent){
					// Event.stop(elEvent);
					o.showTab(index);	
					clearTimeout(o.timeout);
					//o.fxBtn(el.id);
					o.showTab(index);		
					nextID = index+1;
					// o.timeout	=	setTimeout( "o.autoSlide("+nextID	+")", 7000);
				}
			}
			});
	},
	
	startAutoSlide: function ()
	{
		this.bAutoSlide = (this.bAutoSlide) ? false: true;
		this.autoSlide();
	}
});	

Event.observe(window, 'load', function(){
	var tabNewsImg	= new newsTabSlider
					(
						'tabNewsImgControls',
						'contents',
						'section'
					);
	}
);

