<!--
// JavaScript Document
/**********************文档说明******************************
 *简单的网站导航
 *日期：2008-04-03
 *作者：杭州美中网络科技有限公司 汪奇志
 *在IE6和IE7，FireFox 2.0浏览器上测试通过
 ***********************************************************/
var simpleNav=function(_name) {
	//新实例的名称
	this.name=_name;
	//下拉菜单相对于主菜单左边的距离
	this.menuXoffset=0;
	//下拉菜单相对于主菜单底边的距离
	this.menuYoffset=0;
	
	this.navHeight=35;
	//下拉菜单关闭延迟时间，单位：毫秒
	this.menuDelay=800;
	//下拉菜单开始延迟时间，单位：毫秒
	this.menuDelayStart=200;
	//关闭菜单定时器
	this.menuHideTimer=null;
	//显示菜单定时器
	this.menuShowTimer=null;
	//当前菜单Data
	this.currentData=null;
	//当前菜单ID
	this.currentMenu=null;
	//当前是否在菜单上
	this.onMenu=false;
	//上一菜单
	this.prevMenu=false;
	//下拉菜单的ID
	this.menuIds="simpleMenu_";
	//Nav的ID
	this.navIds="nav_"
	//下拉菜单的样式
	this.menuClass="page_nav_menu";
	this.menuJgClass="page_nav_menu_jg"
	this.Written=false;
	//下拉菜单数据
	this.menuData=new Array();
	this.tempData=new Array();
	//关闭菜单时间
	this.start=null;
	//是否关闭
	this.isHide=false;
	//取对象
	this.$=function(_id) {
		return document.getElementById(_id);	
	}
	//页面跳转
	this.gt=function(_url) {
		document.location.href=_url;
	}
	//取_obj距页面左边距离
	this.getOffsetX=function(_obj) {
		var _x = 0;
		while (_obj.offsetParent!=null) {
			_x += _obj.offsetLeft;
			_obj = _obj.offsetParent;
		}
		return _x + _obj.offsetLeft;
	}
	//取_obj距页面顶部距离
	this.getOffsetY=function(_obj) {
		var _y = 0;
		while (_obj.offsetParent!=null) {
			_y += _obj.offsetTop;
			_obj = _obj.offsetParent;
		}
		return _y + _obj.offsetTop;
	}
	//menuObj _text:文本 _url：链接地址
	this.menuObj=function(_text,_url) {
		this.text = _text;
		this.url = _url;
		return this;	
	}
	//renderData _width:宽度 _menu：菜单ID
	this.renderData=function(_width,_menu) {
		this.tempData.width=_width;
		this.tempData.menu=_menu;
		this.menuData.push(this.tempData);
		this.tempData=new Array();
	}
	//向页面输出MENU
	this.writeMenu=function() {
		try {
			for(var i=0;i<this.menuData.length;i++) {
				var _dws='<div id="'+this.menuIds+this.menuData[i].menu+'" class="'+this.menuClass+'">';	
				_dws+='<dl style="width:'+(this.menuData[i].width-2)+'px" onmouseover="'+this.name+'.startShow('+i+');" onmouseout="'+this.name+'.startHide('+i+');">';
				for(var j=0;j<this.menuData[i].length;j++) {
					_dws+='<dd class="'+this.menuJgClass+'"><img src="../../images/spacer.gif" alt="" /></dd>'
					_dws+='<dd>';
					_dws+='<a href="'+this.menuData[i][j].url+'">';
					_dws+=this.menuData[i][j].text;
					_dws+='</a>';
					_dws+='</dd>';
				}
				_dws+='</dl>';
				_dws+="</div>";
				document.write(_dws);
				this.positioning(i);
			}
			this.Written=true;
		}catch(e) {this.Written=false;}
	}
	//定位下拉菜单
	this.positioning=function(_num) {
		var _tempMenu = this.menuIds + this.menuData[_num].menu;
		var _tempNav = this.navIds + this.menuData[_num].menu;
		var _xPos = this.getOffsetX(this.$(_tempNav))+this.menuXoffset;
		var _yPos = this.getOffsetY(this.$(_tempNav)) + this.navHeight + this.menuYoffset;
		this.$(_tempMenu).style.left = _xPos + "px";
		this.$(_tempMenu).style.top = _yPos + "px";
	}
	//开始显示下拉菜单
	this.startShow=function(_num) {
		if(!this.Written) return;
		//if(this.currentData==_num) {this.clearHideTimer();return;}
		//将当前Data等于_num
		this.currentData=_num;
		
		//如果上一菜单还在显示，将其visibility=hidden
		if(this.prevMenu) {
			this.$(this.prevMenu).style.visibility = "hidden";	
		}
		//清除关闭菜单定时器
		this.clearHideTimer();
		//如果onMenu=true，直接显示菜单，否则菜单在menuDelayStart毫秒后延迟显示
		if(!this.onMenu) {
			this.menuShowTimer = setTimeout(this.name+".showMenu()", this.menuDelayStart);
		} else {
			this.showMenu();	
		}
	}
	//显示下拉菜单
	this.showMenu=function() {
		//将onMenu设置成true
		this.onMenu=true;
		//当前显示菜单的ID
		var _currentMenu=this.menuIds+this.menuData[this.currentData].menu;
		//this.prevMenu=_currentMenu
		this.prevMenu=_currentMenu;
		//显示菜单
		if(this.$(_currentMenu).style.visibility!="visible") {
			this.$(_currentMenu).style.visibility = "visible";
		}
	}
	//开始关闭下拉菜单
	this.startHide=function() {
		if(!this.Written) return;
		//清除显示菜单定时器
		clearTimeout(this.menuShowTimer);
		this.start = new Date();
		this.isHide = true;
		//关闭菜单定时器
		this.menuHideTimer = setTimeout(this.name+".hideMenu()", this.menuDelay);
	}
	//关闭菜单
	this.hideMenu=function() {
		//isHide=false 返回
		if (!this.isHide) return;
		//要关闭菜单的已过时间
		var _elapsed = new Date() - this.start;
		//已过时间若小于关闭菜单延迟时间，重新定义定时器
		if (_elapsed < this.menuDelay) {
			this.menuHideTimer = setTimeout(this.name+".hideMenu()", this.menuDelay - _elapsed);
			return;
		}
		//关闭菜单
		this.hideAllMenus();
	}
	//关闭菜单
	this.hideAllMenus=function() {
		for (var i = 0; i<this.menuData.length; i++) {
			var _theMenu = this.menuIds + this.menuData[i].menu;
			this.$(_theMenu).style.visibility = "hidden";
		}
		//onMenu=false
		this.onMenu=false;
		this.prevMenu=false;
		this.isHide = false;
		this.currentData=false;
	}
	this.clearHideTimer=function() {
		if (this.menuHideTimer) clearTimeout(this.menuHideTimer);
		this.menuHideTimer = null;
		this.isHide = false;
	}
}
//-->
