/* banner - KP tmp */
function RotateBanner(items, params)
{
	this.Inited = false;
	this.ItemList = ( items > 0 ) ? items : 1 ;

	this.AutoRotation = params.autorotate ? true : false;
	this.CurrentBunner = (params.current && this.ItemList >= params.current) ? params.current : 1;

	this.ActiveObj = params.aObj ? params.aObj : null;
	this.ListObj = params.lObj ? document.getElementById(params.lObj) : null;
	this.RotateTime = params.rTime ? params.rTime : 1000;
	
	this.ShowContent = params.ShowContentID;
	this.HideContent = params.HideContentID;
	
	if(this.ActiveObj && this.ListObj)
		this.Inited = true;

	this.ChangeBanner(this.CurrentBunner);
	
	this.images = ( params.images.length > 0 ) ? params.images : false;
	this.links = (params.links.length > 0) ? params.links : false;
	this.imageDir = params.imageDir;
	this.bigBannerImage = ( params.bigBannerImage ) ? document.getElementById(params.bigBannerImage).getElementsByTagName("img") : false;
	this.LinkContent = ( params.LinkContentID ) ? document.getElementById(params.LinkContentID): false;
}

RotateBanner.prototype.ChangeBanner = function(id, handle)
{	
	if(!id || id<=0 || id>this.ItemList || !this.Inited)
		return;
		
	if(handle===true)
		this.AutoRotation = false;

	ExCurrent = this.CurrentBunner;
	this.CurrentBunner = id;
	
		contentShow = document.getElementById(this.ActiveObj + "_" + this.CurrentBunner);
		contentHide = document.getElementById(this.ActiveObj + "_" + ExCurrent);
		btns = this.ListObj.getElementsByTagName('LI');

		if(contentShow && contentHide && btns[id-1])
		{
			btnsChildDeActive = btns[ExCurrent-1].getElementsByTagName("TD");
			btnsChildActive = btns[this.CurrentBunner-1].getElementsByTagName("TD");
			btnsChildDeActive[0].className = "";
			btnsChildActive[0].className = "active";
			
			if( this.images && this.bigBannerImage[0] && this.links ) 
			{
				this.bigBannerImage[0].src = this.imageDir + this.images[id-1];
				//this.bigBannerImage.parentNode.onclick = function(link){return function(){window.open(link)}}(this.links[id-1]);
				//this.LinkContent.setAttribute("href", this.links[id-1]);
			}
			
			//contentHide.removeAttribute("id");
			contentHide.className = this.HideContent;
			contentShow.className =  this.ShowContent;
			
			/* Часть кода, позволяющая включать пользовательские функции
			if(Citem.functions)
			{
				for(i = 0; i<Citem.functions.length; i++)
				{
					if(Citem.functions[i].func && Citem.functions[i].arg && typeof(Citem.functions[i].func) == 'function')
						Citem.functions[i].func.apply(null, Citem.functions[i].arg);
				}
			}
			*/
		}
}

RotateBanner.prototype.Rotation = function(start)
{
	if(!this.Inited || !this.AutoRotation)
		return;
	
	if(!start)
		this.ChangeBanner((this.CurrentBunner + 1) > this.ItemList ? 1 : (this.CurrentBunner + 1));
	
	_this = this;
	setTimeout(function(){_this.Rotation()}, this.RotateTime);
}

