var TRotator=function(p){//pl.: {container:'rotator',interval:2} (konténer id-je, és szünet másodpercben)
	this.p=p;
	this.classNames={};
	this.classNames.button=(p.classNames&&p.classNames.button)?p.classNames.button:'';
	this.classNames.selectedButton=(p.classNames&&p.classNames.selectedButton)?p.classNames.selectedButton:'';

	if(typeof(p.container).toLowerCase()=='string'){
		this.container=document.getElementById(p.container);
	}
	with(this.container.style){
		position='relative';
		overflow='hidden';
	}

	this.interval=p.interval||5;
	this.intervalID=0;
	this.actual=0;

	this.elements=[];
	var ds=this.container.getElementsByTagName('div');
	for(var i=0;i<ds.length;i++){
		this.elements.push(ds[i]);
		with(ds[i].style){
			display='block';
			position='absolute';
			top='0px';
			left='0px';
			width='100%';
			height='100%';
		}
	}
	this.count=this.elements.length;

	this.buttonContainer=document.createElement('span');
	with(this.buttonContainer.style){
		width='100%';
		height='auto';
		top='auto';
		left='0px';
		position='absolute';
		bottom='0px';
		textAlign='center';
		try{
			backgroundColor='rgba(0,0,0,0.5)';
		}catch(e){
			filter='progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#80000000)';
		}
	}
	this.buttons=[];
	this.prevButton=null;
	this.nextButton=null;
	var _t=this;

	/*var el=document.createElement('input');
	el.type='button';
	el.value='<';
	el.className=this.classNames.button;
	el.onclick=function(){
		_t.restartRotating();
		_t.showPrev();
	}
	this.prevButton=el;
	this.buttonContainer.appendChild(el);*/

	for(var i=0;i<this.count;i++){
		var el=document.createElement('input');
		el.type='button';
		el.value=(i+1)+'';
		el.className=this.classNames.button;
		eval('el.onclick=function(){_t.restartRotating();_t.show('+i+');}');
		this.buttons.push(el);
		this.buttonContainer.appendChild(el);
	}
	this.container.appendChild(this.buttonContainer);

	/*var el=document.createElement('input');
	el.type='button';
	el.value='>';
	el.className=this.classNames.button;
	el.onclick=function(){
		_t.restartRotating();
		_t.showNext();
	}
	this.nextButton=el;
	this.buttonContainer.appendChild(el);*/

	this.hideAll=function(){
		for(var i=0;i<this.elements.length;i++)this.elements[i].style.display='none';
	}

	this.show=function(n){
		this.actual=n;
		for(var i=0;i<this.buttons.length;i++)this.buttons[i].className=((i==n)?this.classNames.selectedButton:this.classNames.button);
		this.hideAll();
		this.elements[n].style.display='block';
	}

	this.showNext=function(){
		this.actual++;
		if(this.actual+1>this.count)this.actual=0;
		this.show(this.actual);
	}

	this.showPrev=this.showPrevious=function(){
		this.actual--;
		if(this.actual<0)this.actual=this.count-1;
		this.show(this.actual);
	}

	this.startRotating=function(){
		if(this.intervalID==0){
			this.intervalID=setInterval(function(){_t.showNext()},this.interval*1000);
		}
	}

	this.stopRotating=function(){
		if(this.intervalID!=0){
			clearInterval(this.intervalID);
			this.intervalID=0;
		}
	}

	this.restartRotating=function(){
		this.stopRotating();
		this.startRotating();
	}

	this.hideAll();
	this.show(0);
	this.startRotating();
}

