
var activeButton=null;
function browser_type()
{
	var ua,s,i;
	this.isIE=false;
	this.isNS=false;
	this.version=null;
	ua=navigator.userAgent;
	s="MSIE";
	
	if((i=ua.indexOf(s))>=0){
	this.isIE=true;
	this.version=parseFloat(ua.substr(i+s.length));
	return;
	}
	s="Netscape6/";
	if((i=ua.indexOf(s))>=0){
	this.isNS=true;
	this.version=parseFloat(ua.substr(i+s.length));
	return;
	}
	s="Gecko";
	if((i=ua.indexOf(s))>=0){
	this.isNS=true;
	this.version=6.1;return;
	}
}

var browser_type=new browser_type();


function drop_down(button,menuName,onImgSrc)
{
	
	if(activeButton!=button && menuName)
	{	
			if(!button.menu) button.menu=document.getElementById(menuName);
			//if(!button.offSrc) button.offSrc=button.src;
			//if(!button.onSrc) button.onSrc=onImgSrc;
			if(activeButton && activeButton!=button) hide_submenu(activeButton);
			show_submenu(button);
	}
	return false;
}


function MkBR(tDiv)
{	
	for(i = 0 ; i < tDiv.all.length ; i++)
	{
		//alert(tDiv.all[i].tagName + "=>" + i);
		if(tDiv.all[i].tagName == "BR")		return;		
	}
	//return;
	var aHarf = Math.floor((tDiv.all.length - 4) / 2) + 4;
	tDiv.all[aHarf].outerHTML = "<BR>" + tDiv.all[aHarf].outerHTML ;
}
function show_submenu(button)
{
	var w,dw,x,y;
	var tSpace = 10;
	//button.src = button.onSrc;	
	MkBR(button.menu);
	if(browser_type.isIE && !button.menu.firstChild.style.width)
	{
			w=button.menu.firstChild.offsetWidth;
			button.menu.firstChild.style.width=w+"px";	
			dw=button.menu.firstChild.offsetWidth-w;
			if(w >= button.menu.parentElement.offsetWidth) 
			{
				w-=dw + (tSpace*2);
			}
			else
			{
				w-=dw;
			}
			button.menu.firstChild.style.width=w+"px";
	}

	x=calculat_x(button)+(button.offsetWidth/2);
	y=calculat_y(button)+button.offsetHeight;
	
	if(browser_type.isIE)
	{
		//x+=2;
		//y+=2;
	}
	if(browser_type.isNS && browser_type.version < 6.1)		y--;
	
	//È­»ìÇ¥
	document.all.allowImg.style.visibility="visible";
	document.all.allowImg.style.left = x+"px";
	document.all.allowImg.style.top=(y - document.all.allowImg.offsetHeight) +"px";	
	//È­»ìÇ¥³¡	
	var menuY = y + 3;	
	var menuX = x - (button.menu.firstChild.offsetWidth /2);	
	var menuXRight = x + (button.menu.firstChild.offsetWidth /2);
	var pLeft = calculat_x(button.menu.parentElement);
	var pRight = pLeft + button.menu.parentElement.offsetWidth;
	var menuAlign="center";
	if(menuX <= pLeft + tSpace)
	{
		menuX -= menuX - pLeft - tSpace;
		menuAlign="left";
	}
	if(menuXRight >= pRight - tSpace)
	{
		menuX += pRight - menuXRight - tSpace;
		menuAlign="right";
	}
	
	button.menu.all[1].style.textAlign = menuAlign;
	button.menu.style.left=menuX+"px";
	button.menu.style.top=menuY+"px";
	button.menu.style.visibility="visible";
	
	activeButton=button;

}

function hide_submenu(button)
{
	//if(button.offSrc) button.src = button.offSrc;
	document.all.allowImg.style.visibility=="hidden";
	if(button.menu)	button.menu.style.visibility="hidden";
	activeButton=null;
}

function calculat_x(el)
{
	return el.offsetLeft+(el.offsetParent?calculat_x(el.offsetParent):0);
}

function calculat_y(el)
{
	return el.offsetTop+(el.offsetParent?calculat_y(el.offsetParent):0);
}





function PreloadImg()
{ 
  var img_list = PreloadImg.arguments;
  if (document.preloadlist == null)     document.preloadlist = new Array();
  var top = document.preloadlist.length;
  
  for (var i=0; i < img_list.length; i++) 
  {
    document.preloadlist[top+i]     = new Image;
    document.preloadlist[top+i].src = img_list[i+1];
  } 
}

var rBanner,maxH;	
function InitBannerMove()
{			
	rBanner = document.getElementById('rBanner');
	rBanner.style.top = document.body.scrollTop * 1;	
	maxH = rBanner.parentElement.offsetHeight - rBanner.firstChild.offsetHeight - 20;
	moveRightEdge();
}
	


function moveRightEdge() 
{
	var yMenuFrom, yMenuTo, yOffset, timeoutNextCheck;

	yMenuFrom   = parseInt (rBanner.style.top, 10);
	yMenuTo     = document.body.scrollTop;
	if(yMenuTo > maxH) yMenuTo = maxH;
	timeoutNextCheck = 500;

	if (yMenuFrom != yMenuTo) 
	{
		yOffset = Math.ceil(Math.abs(yMenuTo - yMenuFrom) / 20);
		if (yMenuTo < yMenuFrom)	yOffset = -yOffset;
		 
		rBanner.style.top = parseInt (rBanner.style.top, 10) + yOffset;
		timeoutNextCheck = 10;
	}
	setTimeout ("moveRightEdge()", timeoutNextCheck);
}

