//导航菜单
function showmenu (baseID, divID) {
    baseID = document.getElementById(baseID);
    divID  = document.getElementById(divID);
    if (showmenu.timer) clearTimeout(showmenu.timer);
	hideCur();
    divID.style.display = 'block';
	showmenu.cur = divID;

    if (! divID.isCreate) {
        divID.isCreate = true;
        divID.onmouseover = function () {
            if (showmenu.timer) clearTimeout(showmenu.timer);
			hideCur();
            divID.style.display = 'block';
        };

        function hide () {
            showmenu.timer = setTimeout(function () {divID.style.display = 'none';}, 1000);
        }

        divID.onmouseout = hide;
        baseID.onmouseout = hide;
    }
	function hideCur () {
		showmenu.cur && (showmenu.cur.style.display = 'none');
	}
}

//浮动提示框（显示title内容）
var tipname = "tips";
var tiptag = "a,label,div,img,span"; 
var tipx = 0;
var tipy = 15;
var tipobj = null;

function tipinit() {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = tipname;}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	tipobj = document.getElementById(tipname);
	if(tipobj) document.onmousemove = function(evt){tipmove(evt)};

	var a, sTitle, elements;
	
	var elementList = tiptag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle && typeof(a.onmouseover) != "function" && typeof(a.onmouseout) != "function")
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tipshow(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tiphide()};
				}
			}
		}
	}
}

function tipmove(evt) {
	if(tipobj.style.display == "block"){
		var x=0, y=0;
		if (document.all) {
			x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			x += window.event.clientX;
			y += window.event.clientY;
		} else {
			x = evt.pageX;
			y = evt.pageY;
		}
		tipobj.style.left = (x + tipx) + "px";
		tipobj.style.top = (y + tipy) + "px";
	}
}

function tipshow(text) {
	if (!tipobj) return;
	tipobj.innerHTML = text;
	tipobj.style.display = "block";
}

function tiphide() {
	if (!tipobj) return;
	tipobj.innerHTML = "";
	tipobj.style.display = "none";
}

if (document.all){
	window.attachEvent('onload',tipinit);
}else{
	window.addEventListener('load',tipinit,false);
} 

//tab效果
function selecttab(obj){
	var n = 0;
	var tabs = obj.parentNode.parentNode.getElementsByTagName("li"); 
	for(i=0; i<tabs.length; i++){
		tmp = tabs[i].getElementsByTagName("a")[0];
		if(tmp == obj){
			tmp.className="selected";
			n=i;
		}else{
			tmp.className="";
		}
 	}
	var contents = obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("div")[1].getElementsByTagName("div");
	for(i=0; i<contents.length; i++){
		contents[i].style.display = i==n ? "block" : "none";   
 	}
}

//tab menu
var $ = function(i){return document.getElementById(i);}
var ua = navigator.userAgent.toLowerCase();
var isIE = (ua.indexOf("msie") > -1),isIE7 = (ua.indexOf("msie 7") > -1),isOpera = (ua.indexOf("opera") > -1),isSafari = (ua.indexOf("webkit") != -1 || ua.indexOf("khtml") != -1),isGecko = (!isSafari && ua.indexOf("gecko") > -1);

var s=0;
var t;
var rt;

/*change link*/
function setTab(m,n){
var tli=document.getElementById("tab"+m).getElementsByTagName("li");
var mli=document.getElementById("tabmains"+m).getElementsByTagName("ul");
for(i=0;i<tli.length;i++){

   try { mli[i].style.display= i==n?"block":"none";} catch(err) { }

   tli[i].className= i==n?'on':'none';
   if( m==1){
   stop();
   s=n;//使轮转从当前点继续
   }
}
}
//启动轮转
function turn(){
	setTab(1,s);
	s=s+1;
	if(s>1){ s=0;}
	t =setTimeout("turn();",5000);
}
//清除轮转
function stop() 
{ 
    clearTimeout(t) ;
	clearInterval(rt) ;

}
//继续轮转
function rturn(){
	rt =setInterval("turn()",3000); 
	}


//
	function copy_clip(copy){
						if (window.clipboardData)
							{
								window.clipboardData.setData("Text", copy);
							}
						else if (window.netscape)
							{
							netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
							var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
							if (!clip) return;
							var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
							if (!trans) return;
							trans.addDataFlavor('text/unicode');
							var str = new Object();
							var len = new Object();
							var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
							var copytext=copy;
							str.data=copytext;
							trans.setTransferData("text/unicode",str,copytext.length*2);
							var clipid=Components.interfaces.nsIClipboard;
							if (!clip) return false;
							clip.setData(trans,null,clipid.kGlobalClipboard);
							}
				alert("海天中文网：已将本书链接复制到剪贴板,可以粘贴给你的朋友分享了！")
				return false;
						}