// 日期时间
var dateTime = {
	now		: new Date(),
	showObj	: null,
	timer	: null,
	tInt	: null,
	date : function() {
		var nY = dateTime.now.getFullYear(), nM = dateTime.now.getMonth()+1, nD = dateTime.now.getDate();
		return (nY +'年'+ nM +'月'+ nD +'日');
	},
	week : function() {
		var day = dateTime.now.getDay();
		var wStr = null;
		switch(day){
			case 0 : wStr = '日'; break;
			case 1 : wStr = '一'; break;
			case 2 : wStr = '二'; break;
			case 3 : wStr = '三'; break;
			case 4 : wStr = '四'; break;
			case 5 : wStr = '五'; break;
			case 6 : wStr = '六'; break;
		}
		wStr = '星期'+ wStr;
		return wStr;
	},
	time : function() {
		var now = new Date();
		var nH = now.getHours(), nM = now.getMinutes(), nS = now.getSeconds();
		nH = nH >= 10 ? nH : '0'+ nH;
		nM = nM >= 10 ? nM : '0'+ nM;
		nS = nS >= 10 ? nS : '0'+ nS;
		var tmpStr = null;
		var tInt = null;
		if(dateTime.timer == null){
			clearInterval(dateTime.tInt);
			tmpStr = '<span id="__timer">'+
					 nH +':'+ nM +':'+ nS +
					 '<\/span>';
			dateTime.timer = $('__timer');
			dateTime.tInt = setInterval('dateTime.time()', 1000);
			return tmpStr;
		}else{
			tmpStr = nH +':'+ nM +':'+ nS;
			dateTime.timer.innerHTML = tmpStr;
		}
	},
	show : function(d, w, t) {
		if(dateTime.showObj == null){ return;}
		var tnpStr = null;
		var tmpDate = new Array();
		tmpDate[0] = d ? dateTime.date() : null;
		tmpDate[1] = w ? dateTime.week() : null;
		tmpDate[2] = t ? dateTime.time() : null;
		tnpStr = tmpDate.join('&nbsp;');
		dateTime.showObj.innerHTML = tnpStr;
	}
};

//飘动
var _obj = null;
var lastScrollY = 0;
function Float(){ 
	var diffY = document.documentElement.scrollTop || document.body.scrollTop
	
	percent = .1 * (diffY-lastScrollY); 
	if(percent > 0) {
		percent = Math.ceil(percent);
	}else{
		percent = Math.floor(percent); 
	}
	_obj.style.top = (parseInt(_obj.style.top, 10) + percent)+"px";

	lastScrollY = lastScrollY + percent; 
}

// 菜单选择
function SelectMenu(i) {
	var mCase = document.getElementById("navMenu");
	var menus = mCase.getElementsByTagName("a");
	menus[i].className = 'sel';
}

// 搜索设置
function initSearch(e, id, url, txt, hint) {
	var iptSubmit = $(e);
	var iptKey = $(id);
	if(iptSubmit==null || iptKey==null) return;
	
	var defaultVal = txt==undefined ? '搜索关键字' : txt;
	if(iptKey.value=='') {
		iptKey.value = defaultVal;
		iptKey.style.color = '#666';
	}
	
	iptKey.onfocus = function() {
		if(this.value==defaultVal) {
			this.value='';
			this.style.color = '';
		}else{
			this.select();
		}
	}
	iptKey.onblur = function() {
		if(this.value=='') {
			this.value=defaultVal;
			this.style.color = '#666';
		}
	}
	
	iptSubmit.onclick = function() {
		if(iptKey.value=='' || iptKey.value==defaultVal) {
			alert(defaultVal +'不能为空！');
			iptKey.focus();
			iptKey.select();
			return false;
		}else{
			var keyword = escape(iptKey.value.replace(/-/g, '—'));
			iptSubmit.href = url +'-'+ keyword;
		}
		return true;
	}
}


//	子菜单
var doHide = null;
var prvSubMenu = null;
function showMenu(menu, e) {
	menu = $(menu);
	if(menu==null) return;
	clearTimeout(doHide);
	if(prvSubMenu!=null && prvSubMenu!=menu) hideMenu(prvSubMenu.id, true);
	
	if(e!=undefined) {
		var XY = getCoords(e);
		menu.style.left = XY.x +'px';
		menu.style.top = XY.y+e.offsetHeight +'px';
		menu.style.display = '';
		prvSubMenu = menu;
	}
	menu.onmouseover = function() {
		showMenu(this);
	}
	menu.onmouseout = function() {
		hideMenu(this);
	}
}

function hideMenu(menu, t) {
	menu = $(menu);
	if(menu==null) return;
	if(!t) {
		doHide = setTimeout('hideMenu("'+ menu.id +'", true)', 500);
		return;
	}
	menu.style.display = 'none';
	prvSubMenu = null;
}


