var _show = null;
var _hide = null;
var isIE6 = /MSIE 6.0/ig.test(navigator.appVersion);

var cfg = {
		divID:"divTips",
		//延长多么时间弹出,以毫秒为单位
		delay:5000,
		//加载的html文件路径
		htmlPath:"/huachu.htm",
		//广告弹出的总高度
		height:159,
		//显示出来广告标题的高度
		titleHeight:28,
		//时间间隔,数据越大速度越慢,越小越快
		interval:2,
		//持续时间
		duration:15000
	};
//在元素中找子元素,p = parent,c = child
function GetChild(p,c){
	var pdom = document.getElementById(p);
	var nodes = pdom.childNodes;
	var cdom = false;
	for(var i=0;i < nodes.length;i++){
		if(nodes[i].tagName == c.toUpperCase()){
			cdom = nodes[i];
			break;
		}
	}
	return cdom;
}
function TipsPop(act){
	var MsgPop = GetChild(cfg.divID,"div");
	var MsgPop = null == MsgPop?document.getElementById(cfg.divID):MsgPop;
	var popH = parseInt(MsgPop.clientHeight);
	if(act == "up"){
		MsgPop.style.display = "block";
		_show = setInterval("TipsChangeHeight('up')",cfg.interval);
	}
	if(act == "down"){
		_hide = setInterval("TipsChangeHeight('down')",cfg.interval);
	}
}
function TipsChangeHeight(str){

	var MsgPop = GetChild(cfg.divID,"div");
	var MsgPop = (null == MsgPop)?document.getElementById(cfg.divID):MsgPop;
	var popH = parseInt(MsgPop.clientHeight);
	if(str == "up"){
		if(isIE6){
			MsgPop.style.height = cfg.height.toString() + "px";
			SetbtnSwitchEvent("down");
			return;
		}

		if(popH <= cfg.height){		
			MsgPop.style.height = (popH + 4).toString() + "px";
			SetbtnSwitchNullEvent();
		}else {
			SetbtnSwitchEvent("down");
		}
	}
	if(str == "down"){
		if(isIE6){
			MsgPop.style.height = cfg.titleHeight.toString() + "px";
			SetbtnSwitchEvent("up");
			return;
		}

		if(popH > cfg.titleHeight){
			MsgPop.style.height = (popH - 4).toString() + "px";
			SetbtnSwitchNullEvent();
		}else {
			SetbtnSwitchEvent("up");
		}
	}
}
function SetbtnSwitchNullEvent(){
	//防止多次点击
	var btnSwitch = document.getElementById("h6-switch");
	btnSwitch.onclick = function(){};
}
function SetbtnSwitchEvent(cmd){
	var btnSwitch = document.getElementById("h6-switch");
	btnSwitch.onclick = function(){
		TipsPop(cmd);
	};
	if(cmd == "up"){
		clearInterval(_hide);
	}else{
		clearInterval(_show);
	}	
}

if (document.all){ 
	window.attachEvent('onload',winLoad) 
} 
else{ 
	window.addEventListener('load',winLoad,false); 
} 

function winLoad(){

	//document.getElementById(cfg.divID).style.display = "block";
	//开关
	var btnSwitch = document.getElementById("h6-switch");
	btnSwitch.onclick = function(){
		TipsPop('down');
		return false;;
	};
	//return;
	//设置初始高度
	//var MsgPop = GetChild(cfg.divID,"div");
	//MsgPop.style.height = cfg.height + "px";
	//延迟时间弹出
	//setTimeout("TipsPop('up')",cfg.delay);
	//停留时间下降
	//setTimeout("TipsPop('down')",cfg.duration);	
}