//D. Akinshin 21.09.2006
//v 2.1	

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

/*******************************************************************/		
		var div_items=new Array();
		var div_items_job=new Array();
		
		function AddJob(div1,div2)
		{
			var o;
			if(div_items_job.length==0)
			{
				div_items_job[0]=new Object();
				div_items_job[0].div1=div1;
				div_items_job[0].div2=div2;
				div_items_job[0].ok=1;
				return 0;
			}
			else
			{
				//var f=0;
				for(var p in div_items_job)
				{
					if(div_items_job[p].ok==0)
					{
						div_items_job[p].div1=div1;
						div_items_job[p].div2=div2;
						div_items_job[p].ok=1;
						return p;
					}
				}
				var x=div_items_job.length;
				div_items_job[x]=new Object();
				div_items_job[x].div1=div1;
				div_items_job[x].div2=div2;
				div_items_job[x].ok=1;
				return x;
			}
		}
		function eFade(div1,div2)
		{
			this.div1=document.getElementById(div1);
			this.div2=document.getElementById(div2);
			//alert(div1+' '+div2);
		}
		eFade.prototype.swap1=function()
		{
			this.div1.style.display='none';
			document.getElementById(this.div1.id+'_root').style.display='none';
			this.div2.style.display='block';
			document.getElementById(this.div2.id+'_root').style.display='block';
			//this.cur_op=0;
			//this.IID=0;
			//alert('swap');
		}
		eFade.prototype.swap2=function(t_int)
		{
			var x=this.div1;
			var y=document.getElementById(x.id+'_root');
			
			if (navigator.appName=="Microsoft Internet Explorer") x.style.position='absolute';
			if (x.offsetWidth)
			{
				y.style.height=x.offsetHeight;
				y.style.width=x.offsetWidth;
			}
			else
			{
				y.style.height=x.scrollHeight;
				y.style.width=x.scrollWidth;
			}
			
			var jb=AddJob(this.div1.id,this.div2.id);
			var tmp='eFade.Fade1("'+jb+'")'
			o=div_items_job[jb];
			o.cur_op=1;
			o.t_int=t_int/2;
			o.delay=o.t_int*0.05;
			o.IID=setInterval(tmp,o.delay);

		}
		eFade.Fade1=function(p)
		{
			var o=div_items_job[p];
			o.cur_op-=0.05
			if (o.cur_op<=0)
			{
			document.getElementById(o.div1).style.display='none';
			document.getElementById(o.div1+'_root').style.display='none';
			
			setElementOpacity(document.getElementById(o.div2),0);
			o.cur_op=0;
			var x=document.getElementById(o.div2);
			var y=document.getElementById(o.div2+'_root');
			
			y.style.display='block';
			x.style.display='block';
			
			if (navigator.appName=="Microsoft Internet Explorer") x.style.position='absolute';
			if (x.offsetWidth)
			{
				y.style.height=x.offsetHeight;
				y.style.width=x.offsetWidth;
			}
			else
			{
				y.style.height=x.scrollHeight;
				y.style.width=x.scrollWidth;
			}
			
			clearInterval(o.IID);
			o.IID=setInterval('eFade.Fade2("'+p+'")',o.delay);
			}
			else setElementOpacity(document.getElementById(o.div1),o.cur_op);
		}
		eFade.Fade2=function(p)
		{
			var o=div_items_job[p];
			o.cur_op+=0.05
			if (o.cur_op>=1)
			{
			clearInterval(o.IID);
			o.ok=0;
			}
			else setElementOpacity(document.getElementById(o.div2),o.cur_op);
		}
		function SetItemObject(Ob,iID,tINT,delay)
		{
			if(Ob['cur']==null)
			{
			        if (tINT=='') tINT=3000;
			        if (tINT<=10) tINT=3000;
				Ob.cur=0;
				Ob.prev='';
				Ob.divs=new Array();
				Ob.divs[0]=iID;
				Ob.time_int=tINT;
				Ob.cur_int=0;
				Ob.delay=delay;
			}
			else
			{
				Ob.divs[Ob.divs.length]=iID;
			}
			
		}
		function AddItem(iID,iClass,tINT,delay)
		{
			var o=new Object();
			if(delay=='') delay=0;
			
			if(!div_items[iClass])
			{
				SetItemObject(o,iID,tINT,delay);
			}
			else
			{
				o=div_items[iClass];
				SetItemObject(o,iID,tINT,delay);
			}
			div_items[iClass]=o;
		}
		function rotateDIV()
		{
		  var o;
		  var idx;
		  var min_int='';
			var x;
		  for(p in div_items)
			{
				o=div_items[p];
				if (o.cur_int==0)
				{
					idx=div_items[p]['divs'][o.cur];
					if(o.prev!='')
					{
						x=new eFade(o.prev,idx)
						if(o.delay>0)
							x.swap2(o.delay);
						else
							x.swap1();
					}
					else
					{
						document.getElementById(idx).style.display="block";
						document.getElementById(idx+'_root').style.display="block";
					}
					(o.cur==(div_items[p]['divs'].length-1))?o.cur=0:o.cur++;
					div_items[p].prev=idx;
					o.cur_int=o.time_int;
					if(min_int=='') min_int=o.cur_int;
					else if(min_int>o.cur_int) min_int=o.cur_int;
				}
				else
				{
					if(min_int=='') min_int=o.cur_int;
					else if(min_int>o.cur_int) min_int=o.cur_int;
				}
				
			}
			if(min_int=='') min_int=3001;
			for(p in div_items)
			{
				div_items[p].cur_int-=min_int;
			}
			
		  setTimeout("rotateDIV()",min_int);
			
		}
		addLoadEvent(rotateDIV);