﻿// JScript 文件

//简易一级菜单效果
//作者：bonnyu
//要点：JS对象封装、JS对象内封包 CSS多重定义（与style中先后顺序有关，与class内顺序无关） CSS背景定位 等技术
//缺点：鼠标移动过快，客户端CPU占用率高
//初始化参数：bpy background-Position-Y, bpyStep 移动速度（px）, bpyfc 下边白色底的background-Position-Y, bpyfcStep 下边白色底的移动速度（px）, timeStep 移动速度间隔
//调用举例：见HTML代码
function MenuItemOver(obj)
{
	obj.style.backgroundPositionY = "-36px";
	obj.firstChild.style.backgroundPositionY = "33px";
	var bpy = -36;
	var bpyStep = 4;
	var bpyfc = 33;
	var bpyfcStep = 1;
	var timeStep = 10;
	var timeHand_1, timeHand_2;
	var __self = this;
	this.OverMenuText = function()
	{
		if(bpy >= 0)
		{
			window.clearTimeout(timeHand_1);
			obj.style.backgroundPositionY = "0px";
		}
		else
		{
			bpy += bpyStep;
			obj.style.backgroundPositionY = bpy + "px";
			timeHand_1 = window.setTimeout(__self.OverMenuText, timeStep);
		}
		if(bpy>-12)
		{
			__self.MoveMenuBG();
		}
	}
	this.MoveMenuBG = function()
	{
		objfc = obj.firstChild;
		if(bpyfc <= 27)
		{
			window.clearTimeout(timeHand_2);
			objfc.style.backgroundPositionY = "27px";
		}
		else
		{
			bpyfc -= bpyfcStep;
			objfc.style.backgroundPositionY = bpyfc + "px";
			timeHand_2 = window.setTimeout(__self.MoveMenuBG, timeStep);
		}
	}
}
function MenuItemOut(obj)
{
	obj.style.backgroundPositionY = "0px";
	obj.firstChild.style.backgroundPositionY = "27px";
	//var bpy = parseInt(obj.style.backgroundPositionY.replace("px",""));
	var bpy = 0;
	var bpyStep = 4;
	var bpyfc = 27;
	var bpyfcStep = 1;
	var timeStep = 10;
	var timeHand_1, timeHand_2;
	var __self = this;
	this.OutMenuText = function()
	{
		if(bpy <= -36)
		{
			window.clearTimeout(timeHand_1);
			obj.style.backgroundPositionY = "-36px";
		}
		else
		{
			bpy -= bpyStep;
			obj.style.backgroundPositionY = bpy + "px";
			timeHand_1 = window.setTimeout(__self.OutMenuText, timeStep);
		}
		if(bpy<=-12)
		{
			__self.MoveMenuBG();
		}
	}
	this.MoveMenuBG = function()
	{
		objfc = obj.firstChild;
		if(bpyfc >= 33)
		{
			window.clearTimeout(timeHand_2);
			objfc.style.backgroundPositionY = "33px";
		}
		else
		{
			bpyfc += bpyfcStep;
			objfc.style.backgroundPositionY = bpyfc + "px";
			timeHand_2 = window.setTimeout(__self.MoveMenuBG, timeStep);
		}
	}
}
function MenuOver(obj)
{
	var ov = new MenuItemOver(obj);
	ov.OverMenuText();
}
function MenuOut(obj)
{
	var ot = new MenuItemOut(obj);
	ot.OutMenuText();
}
function MenuUrl(url)
{
	window.location.href = url;
}



