﻿var topPixUrls=null,topPixDelay=null,topPixUrlsSwapper=null,pageTracker=null;
var MainTMenu=null,GoHomePixManager=null;
Asd.Init.push(function()
{
	MainTMenu=new MainTMenuBuilder();
	if(topPixUrls)
		new topPixUrlsSwapperBuilder();
	new GoHomePixManagerB();
});

function GoHomePixManagerB()
{
	var k;
	if(!(this.L=document.getElementById("lnkGoHome")))
		return;
	if(!(this.I=document.getElementById("imgGoHome")))
		return;
	if(!(this.C=document.getElementById("tdMain0")))
		return;
	if(!this.Reposition())
		return;
	GoHomePixManager=this;
	if(window.addEventListener)
		window.addEventListener("resize",function(){GoHomePixManager.Reposition();},false);
	else if(window.attachEvent)
		window.attachEvent("onresize", function(){GoHomePixManager.Reposition();});
	this.Cache=[new Image(),new Image()];
	for(k=0;k<this.Cache.length;k++)
		this.Cache[k].src="/img/home"+k+".png";
	this.I.PixManager=this;
	this.I.onmouseover=function(){this.src=this.PixManager.Cache[1].src;};
	this.I.onmouseout=function(){this.src=this.PixManager.Cache[0].src;};
	this.L.style.display="inline";
}
GoHomePixManagerB.prototype=
{
	Reposition:function()
	{
		try
		{
			var x=0,p=this.C;
			while(p)
			{
				if(p.offsetLeft)x+=p.offsetLeft;
				p=p.offsetParent;
			}
			this.L.style.left=(x+10)+"px";
			return true;
		}
		catch(e)
		{
			return false;
		}
	}
}

function topPixUrlsSwapperBuilder()
{
	topPixUrlsSwapper=this;
	this.Index=0;
	this.Lay=document.getElementById("tdMain11");
	this.UseFilter=false;
	try
	{
		if(document.all && this.Lay.filters && (typeof(this.Lay.filters.length)=="number") && this.Lay.filters.length)
			this.UseFilter=true;
	}
	catch(e)
	{}
	setInterval("topPixUrlsSwapper.Next()",topPixDelay?topPixDelay:4000);
}
topPixUrlsSwapperBuilder.prototype=
{
	FILTER_DELAY:0.8,
	FILTERS:
	[
		"Barn(orientation='horizontal' motion='in',%d%)",
		"Barn(orientation='horizontal' motion='out',%d%)",
		"Barn(orientation='vertical' motion='in',%d%)",
		"Barn(orientation='vertical' motion='out',%d%)",
		"Checkerboard(Direction='down',%d%)",
		"Checkerboard(Direction='left',%d%)",
		"Checkerboard(Direction='right',%d%)",
		"Checkerboard(Direction='up',%d%)",
		"Inset(%d%)",
		"Iris(irisStyle='circle', motion='in',%d%)",
		"Iris(irisStyle='cross', motion='out',%d%)",
		"Iris(irisStyle='diamond', motion='in',%d%)",
		"Iris(irisStyle='plus', motion='in',%d%)",
		"Iris(irisStyle='square', motion='out',%d%)",
		"Iris(irisStyle='star', motion='out',%d%)",
		//"Pixelate(%d%)",
		"RandomBars(motion='horizontal',%d%)",
		"RandomBars(motion='vertical',%d%)",
		"RandomDissolve(%d%)",
		//"Slide(bands=5, slidestyle='hide',%d%)",
		//"Slide(bands=5, slideStyle='push',%d%)",
		//"Slide(bands=5, slidestyle='swap',%d%)",
		"Spiral(%d%)",
		"Stretch(stretchStyle='push',%d%)"
	],
	Next:function()
	{
		var preIndex=this.Index;
		if(++this.Index>=topPixUrls.length)
			this.Index=0;
		if(this.UseFilter)
		{
			if(!this.Lay.style.backgroundImage)
				this.Lay.style.backgroundImage="url('"+topPixUrls[preIndex]+"')";
			this.Lay.style.filter="progid:DXImageTransform.Microsoft."+this.FILTERS[Math.round(Math.random()*(this.FILTERS.length-1))].replace("%d%","duration="+this.FILTER_DELAY);
			this.Lay.filters[0].apply();
		}
		this.Lay.style.backgroundImage="url('"+topPixUrls[this.Index]+"')";
		if(this.UseFilter)
			this.Lay.filters[0].play();
	}
}

function MainTMenuBuilder()
{
	var L,k,i;
	MainTMenu=this;
	this.Items=[];
	this.CurItem=null;
	this.CurZIndex=30000;
	L=document.getElementsByTagName("div");
	for(k=0;k<L.length;k++)
		if(L[k].className=="mainTMenuL")
			if(document.getElementById("mainTMenuI"+(i=L[k].id.substr("mainTMenuL".length)).toString()))
				new MainMenuItem(i);
	L=["trMain0","trMain2","trMain3"];
	for(k=0;k<L.length;k++)
		document.getElementById(L[k]).onmouseover=function(){MainTMenu.SetCurItem(null);};
}
MainTMenuBuilder.prototype=
{
	SetCurItem:function(item)
	{
		if(this.CurItem==item)
			return;
		if(this.CurItem)
			this.CurItem.Hide();
		if(this.CurItem=item)
			this.CurItem.Show();
	}
};

function MainMenuItem(index)
{
	MainTMenu.Items[this.Index=index]=this;
	this.Item=document.getElementById("mainTMenuI"+this.Index.toString());
	this.Lay=document.getElementById("mainTMenuL"+this.Index.toString());
	this._hTO=null;
	this.LayWidthFull=Math.max(150,this.Lay.offsetWidth);
	this.Lay.style.width=this.LayWidthFull+"px";
	this.LayWidth=0;
	this.Lay.style.clip="rect(auto 0 auto auto)";
	this.Lay.style.visibility="visible";
	this.LayVisDir=0;
	this.Item.MMI=this;
	this.Item.onmouseover=function(e){this.MMI.ItemOver(e||event);};
}
MainMenuItem.prototype=
{
	SHOWSPEED_ON:15,
	SHOWSPEED_OFF:20,
	SHOWSPEED_DELAY:20,
	ItemOver:function(e)
	{
		MainTMenu.SetCurItem(this);
	},
	Hide:function()
	{
		this.Item.style.backgroundColor="";
		this.Item.style.color="";
		this.SetVisDir(-1);
	},
	Show:function()
	{
		this.Item.style.backgroundColor="#0e9ea7";
		this.Item.style.color="#bcff70";
		this.Lay.style.zIndex=(MainTMenu.CurZIndex--);
		this.SetVisDir(1);
	},
	SetVisDir:function(delta)
	{
		var p;
		if(this._hTO)
		{
			clearTimeout(this._hTO);
			this._hTO=null;
		}
		if(this.LayWidth==0)
		{
			if(delta<0)return;
		}
		this.LayWidth=Math.max(0,Math.min(this.LayWidthFull,this.LayWidth+delta*((delta<0)?this.SHOWSPEED_OFF:this.SHOWSPEED_ON)));
		try
		{
			p=Math.max(0,Math.min(0.9,this.LayWidth/this.LayWidthFull));
			try
			{this.Lay.style.opacity=p;}
			catch(e)
			{}
			try
			{this.Lay.style.filter="alpha(opacity="+(p*100)+")";}
			catch(e)
			{}
		}
		catch(e)
		{}
		this.Lay.style.clip="rect(auto "+this.LayWidth+"px auto auto)";
		if((this.LayWidth==0)&&(delta<0))
			return;
		if((this.LayWidth==this.LayWidthFull)&&(delta>0))
			return;
		this._hTO=setTimeout("MainTMenu.Items["+this.Index+"].SetVisDir("+delta+")",this.SHOWSPEED_DELAY);
	}
};