// browser check
var TopMenuBrowserType = (navigator.appVersion.match(/MSIE/) && (!navigator.appVersion.match(/MSIE\s8\.0/) || OLD_VERSION_PAGE)) ? 'IE' : 'NS' ;
// JavaScript Document
function gnway_top_menu_by_tongfu(ex, cts, cname, mmargin){
	this.tfex=ex;
	this.tfucontent=cts;
	this.tfClsName=cname;
	this.tfMaxMargin=mmargin;
	this.len;
	this.lastId;
	this.lastObj;
	this.lastMenuObj;
	this.tt;
	this.tl;
	this.tm;
	this.init=function(){
		this.len = cts.length;
		this.lastObj = null;
	}
	this.getPos=function(obj){
	    if(TopMenuBrowserType != 'IE'){
            this.tt += parseInt(obj.offsetTop);
            this.tl += parseInt(obj.offsetLeft);
            this.tm += ('o:'+obj.tagName+'|ot:'+obj.scrollTop+'|ol:'+obj.offsetLeft+'|t:'+this.tt+'|l:'+this.tl+'\n');
	    }
	    else{
	        if(obj.tagName != 'UL'){
                this.tt += parseInt(obj.offsetTop);
                this.tl += parseInt(obj.offsetLeft);
            }
            this.tm += ('o:'+obj.tagName+'|ot:'+obj.scrollTop+'|ol:'+obj.offsetLeft+'|t:'+this.tt+'|l:'+this.tl+'\n');
            newObj = (TopMenuBrowserType == 'IE') ? obj.parentElement : obj.parentNode ;
	        if(newObj.tagName != 'BODY'){
                this.getPos(newObj);
	        }
            else{
                this.tt += parseInt(newObj.offsetTop);
                this.tl += parseInt(newObj.offsetLeft);
                this.tm += ('o:'+newObj.tagName+'|ot:'+newObj.offsetTop+'|ol:'+newObj.offsetLeft+'|t:'+this.tt+'|l:'+this.tl+'\n');
            }
        }
	}
	this.show=function(obj, id){
	    this.tt = 0;
	    this.tl = 0;
	    this.tm = '';
	    this.getPos(obj);
	    // add current object client height if IE
	    this.tt += (TopMenuBrowserType == 'IE') ? parseInt(obj.offsetHeight) : parseInt(obj.offsetHeight) ;
	    if(id != this.lastId){
		    if(this.lastObj != null){
			    if(this.lastMenuObj != null){
				    this.lastObj.removeChild(this.lastMenuObj);	
			    }
			    this.lastObj.className = '';
		    }
		    if(id >= 0 && id < this.len){
		        this.lastId = id;
		        // create frame
			    nObj = this.lastMenuObj = document.createElement("DIV");
			    nObj.className = this.tfClsName;
			    nObj.style.position = 'absolute';
			    nObj.style.top = this.tt+'px';
			    nObj.style.left = this.tl+'px';
			    // insert frame
                obj.appendChild(nObj);
                // making menus
			    nObjUl = document.createElement("TABLE");
			    nObjUl1 = document.createElement("THEAD");
			    nObjUl2 = document.createElement("TBODY");
			    nObjUl.appendChild(nObjUl1);
			    nObjUl.appendChild(nObjUl2);
			    nObj.appendChild(nObjUl);
			    il = this.tfucontent[id].length;
			    for(ii=0;ii<il;ii++){
			        if(this.tfucontent[id][ii] != null
			            && this.tfucontent[id][ii].length == 2){
				        nObjLi = document.createElement("TR");
				        nObjUl2.appendChild(nObjLi);
				        nObjLi2 = document.createElement("TD");
				        nObjLi.appendChild(nObjLi2);
				        //nObjLi2.innerHTML = this.tm.replace(/\n/g,'<br>');break;
				        nObjLi2.innerHTML = "<A href='"+this.tfucontent[id][ii][0]+"'>"+this.tfucontent[id][ii][1]+"</A>";
				    }
			    }
			    obj.className = 'cur';
			    // set memory
			    this.lastObj = obj;
		    }
		}
	}
	this.hide=function(){
	    if(this.lastObj != null){
		    if(this.lastMenuObj != null){
			    this.lastObj.removeChild(this.lastMenuObj);	
		    }
		    this.lastObj.className = '';
	    }
	    this.lastObj = null;
	    this.lastMenuObj = null;
	    this.lastId = null;
	}
	this.init();
}