var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
if (Browser.isFirefox) { 
    extendEventObject();
}
function extendEventObject() {
    Event.prototype.__defineGetter__("srcElement", function () {
        var node = this.target;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("fromElement", function () {
        var node;
        if (this.type == "mouseover")
        node = this.relatedTarget;
        else if (this.type == "mouseout")
        node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("toElement", function () {
        var node;
        if (this.type == "mouseout")
        node = this.relatedTarget;
        else if (this.type == "mouseover")
        node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });
}
function IsChild(cNode,pNode){
    while(cNode!=null){
        cNode=cNode.parentNode;
        if(cNode==pNode) return true;
    }
    return false;
}

var ajccache=new Object();
var waitInterval;
var tempref;
var MouseDelayTime=150;//鼠标感应延迟300毫秒


function attabs(){
	var obdelay=new Array();
	var ctdelay=new Array();
	for(var i=0;i<arguments.length;i++){
		var ulobj=document.getElementById(arguments[i]);
		
		var ulistlinktarget=ulobj.getAttribute("rel");//目标框架
		ulist=ulobj.childNodes;
		for(var j=0;j<ulist.length;j++)
		{
			var thelist=ulist[j];
            if(thelist.parentNode!=ulobj) continue;//第一层有效
			var ulistlinkurl=thelist.getAttribute("urn");
            if(thelist.tagName.toLowerCase()!="li") continue;
			thelist.setActive=function(bactive){
                if(bactive){
                    this.status="active";
					//alert(this.className);
					if (this.className=="" || this.className=="act")
					{
						this.className="act";
					}else{
						if(this.className.indexOf(" act")==-1)this.className=this.className+" act";
					}
                }else{
                    this.status="normal";
					if (this.className=="act")
					{
						this.className="";
					}else{
						this.className=this.className.replace(" act","");
					}
                }
            };//设置激活样式
			thelist.LoadTab=function(){
				if(this.parentNode.activetab!=null && this.parentNode.activetab!=this)
				{
					this.parentNode.activetab.setActive(false);
					this.parentNode.activetab=this;
					this.setActive(true);
				}
				loadAJAXTab(this);
            };//载入内嵌内容
			thelist.onmouseover=function(aEvent){
                var myEvent = window.event ? window.event : aEvent;
                var fm=myEvent.fromElement;
                if(IsChild(fm,this) || fm==this) return;//过滤子元素event
                if(this.status=="active") return;
                tempref=this;
                clearTimeout(waitInterval);
                waitInterval=window.setTimeout("tempref.LoadTab();",MouseDelayTime);
            };//鼠标经过事件
            thelist.onmouseout=function(aEvent){
                var myEvent = window.event ? window.event : aEvent;
                var em=myEvent.toElement;
                if(IsChild(em,this) || em==this) return; //过滤子元素event
                if(this.status=="active") return;
                clearTimeout(waitInterval);
            };//鼠标滑出事件
            if(ulistlinkurl.indexOf("#default")!=-1){
                thelist.setActive(true);
                ulobj.activetab=thelist;
                ajccache[ulistlinkurl]=document.getElementById(ulistlinktarget).innerHTML;
				var trel=thelist.getAttribute("rel");
				if (trel!=null) obdelay.push(trel);
            }else{
                thelist.setActive(false);
            }//默认首内容记录
			
		}
		if(ulobj.activetab==null) ulobj.activetab=ulist[0];//默认首内容显示
		if(ulistlinktarget.toString().indexOf("sjrecommend")!=-1)ctdelay.push(ulistlinktarget);//经销商显示
	}
	if (obdelay.length>0)
	{
		var trel=obdelay.join(",");
		trel=trel.toString().replace(/,/ig,"','");
		window.setTimeout("attabs('"+trel+"');",MouseDelayTime);
	}
	if (ctdelay.length>0)
	{
		var tct=ctdelay.join(",");
		tct=tct.toString().replace(/,/ig,"','");
		window.setTimeout("sjbox('"+tct+"');",MouseDelayTime);
	}
}

function getXmlhttp()
{
    var http_request;
    if(window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        window.alert("can't create XMLHttpRequest object.");
        return null;
    }
    return http_request;
}

function loadAJAXTab(tobj){
	var url=tobj.getAttribute("urn")
	if(url.indexOf("#default")==-1)
	{
		url="http://www.itsogo.net/"+url;
	}
	var contentid=tobj.parentNode.getAttribute("rel")
    var ocontent=document.getElementById(contentid);
    if(ajccache[url]==null) {
        var xhttp=getXmlhttp();
        xhttp.onreadystatechange=function(){
            if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
            {
                //ocontent.innerHTML=bytes2BSTR(xhttp.responseBody);
				ocontent.innerHTML=xhttp.responseText;
                ajccache[url]=ocontent.innerHTML;
				if (contentid.indexOf("sjrecommend")!=-1)window.setTimeout("sjbox('"+contentid+"');",MouseDelayTime*2);
            }
        }
        xhttp.open("GET",url+"?rand="+escape(Math.random()),true);
		//xhttp.setRequestHeader("cache-control","no-cache");  
		xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xhttp.send(null);
    }else{
        ocontent.innerHTML=ajccache[url];
		if (contentid.indexOf("sjrecommend")!=-1)window.setTimeout("sjbox('"+contentid+"');",MouseDelayTime*2);
    }
	if (tobj.getAttribute("rel")){
		trel=tobj.getAttribute("rel").toString().replace(/,/ig,"','");
		window.setTimeout("attabs('"+trel+"');",MouseDelayTime);
		//attabs(tobj.getAttribute("rel").toString().split(","));
	}
}
window.onerror=function(){return true;};
