//by JuSNS v1.0系列
//官方站：www.juSNS.com，演示站:www.ju001.com，www.julala.cn
//QQ:655071(技术)，QQ:9170617（客服）
//MSN:simplt@163.com EMail:simplt@163.com
//program design by Simplt.Xie，arjun
//========================================

//兼容firefox
try
{
	HTMLElement.prototype.__defineGetter__("children",
	function () {
	var returnValue = new Object();
	var number = 0;
	for (var i=0; i<this.childNodes.length; i++) {
	if (this.childNodes[i].nodeType == 1) {
	returnValue[number] = this.childNodes[i];
	number++;
	}
	}
	returnValue.length = number;
	return returnValue;
	}
	);
}
catch(e){}

function getEvent(){     //同时兼容ie和ff的写法
         if(document.all)    return window.event;        
         func=getEvent.caller;            
         while(func!=null){    
             var arg0=func.arguments[0];
             if(arg0){
                 if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
                     || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    
                     return arg0;
                 }
             }
             func=func.caller;
         }
         return null;
 }
 
//载入菜单js
var MenuLoaded=false;
var menuclassvalue=[];
function getmenurunelement(obj)
{
    try
    {
	    if(obj.children.length>0)
	    {
		    for(var i=0;i<obj.children.length;i++)
		    {
			    var o=obj.children[i];
    			
			    if(o.className=="drop")
			    {
				    menuclassvalue[menuclassvalue.length]=o;
			    }
			    getmenurunelement(o);
		    }
	    }
	}catch(e){}
}


function LoadAllMenu()
{
    var elements=getMenuElement();
    var obj=null;
    for(var i=0;i<elements.length;i++)
    {
        obj=elements[i];
		if (window.attachEvent)
		{
		    
			obj.attachEvent("onclick",runfunction); 
		}
		if (window.addEventListener)
		{
		    
			obj.addEventListener("click",runfunction,false);
		} 
    }
    function runfunction()
    {
         var event=getEvent();
         var obj=event.srcElement||event.target;
         
         var parentObj=obj.parentNode;
		 var nextobj=obj.nextSibling.nextSibling;
		 parentObj.style.backgroundColor="#68a8e2";
		 nextobj.style.display="block";
		 nextobj.style.visibility="visible";
		 hidemenu2(obj);
    }
    MenuLoaded=true; 
}

//取得页面所有有事件的对象
function getMenuElement()
{
    menuclassvalue=[];
    getmenurunelement(document.getElementsByTagName("body")[0]);
    return menuclassvalue;
}

//隐藏菜单
function hidemenu()
{
	var elements=getMenuElement();
	var obj=null;
	var event=getEvent();
    var obj=event.srcElement||event.target;
    if(obj.className=="drop")
    {
        return;
    }
	for(var i=0;i<elements.length;i++)
    {
        obj=elements[i];
		var nextobj=obj.nextSibling.nextSibling;
		var parentObj=obj.parentNode;
		parentObj.style.backgroundColor="";
		nextobj.style.display="none";
		nextobj.style.visibility="hidden";
    }
}

//隐藏菜单
function hidemenu2(obj2)
{
	var elements=getMenuElement();
	var obj=null;
	var event=getEvent();
    var obj=event.srcElement||event.target;
	for(var i=0;i<elements.length;i++)
    {
        obj=elements[i];
        if(obj!=obj2)
        {
		    var nextobj=obj.nextSibling.nextSibling;
		    var parentObj=obj.parentNode;
		    parentObj.style.backgroundColor="";
		    nextobj.style.display="none";
		    nextobj.style.visibility="hidden";
		}
    }
}


if (window.attachEvent)
{
    window.attachEvent("onload",LoadAllMenu); 
    document.attachEvent("onclick",hidemenu);
}
if (window.addEventListener)
{
    window.addEventListener("load",LoadAllMenu,false);
    document.addEventListener("click",hidemenu,false); 
} 
