var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) {
if(typeof fRef == 'function'){
var argu = Array.prototype.slice.call(arguments,2);
var f = (function(){ fRef.apply(null, argu); });
return _st(f, mDelay);
}
return _st(fRef,mDelay);
}
function jssClassShow(l,debug,page,menu){
	this.menu = menu
	this.showedList = null;
	this.showCount = 0;
	this.debug = true;
	this.onAction = false;
	//类别原始数据
	this.list = new Array();
	//类别列表
	this.cList = new Array();
	this.page = page;
	this.divShowTimer = null;
	if(l != null){
		this.list = l;
		this.initClasses();
	}
}
jssClassShow.prototype.mouseOut = function(){
	if(!this.onAction){
		this.divShowTimer = setTimeout(hiddenDiv,700,this);
	}
}
function hiddenDiv(o){
	if(!o.onAction){
		clearTimeout(o.divShowTimer)
		o.initShowList(null);
	}
}
//初始化菜单
jssClassShow.prototype.initShowList = function(o){
	var li = null;
	if(o != null){
		li = o.getParents();
		li[li.length] = o;
	}
	var showedList = this.showedList;
	for(var i = 0;i < this.cList.length;i++){
		if(this.cList[i].showed == true){
			if(showedList[this.cList[i].name] != null){
				var flag = false;
				if(li != null){
					for(var j = 0 ;j < li.length;j++){
						if(this.cList[i].name == li[j].name){
							if(li[j].li.className = "haveChild"){
								li[j].li.className += " CurrentLi";
							}
							flag = true;
							break;
						}
					}
				}
				if(!flag){
					if(o == null){
						this.cList[i].hidden();
					}
					else{
						if(this.cList[i].parentID != -1){
							this.cList[i].hidden();
						}
					}
					if(this.cList[i].li.className.indexOf("haveChild") != -1){
						this.cList[i].li.className = " haveChild";
					}
				}
			}
		}
		else{
			if(o == null && this.cList[i].li.className == "CurrentLiClass"){
				this.cList[i].li.className = "";
			}
		}
	}
}
//添加一个菜单到显示列表对象中
jssClassShow.prototype.addItemShowList = function(o){
	var showedList = this.showedList;
	if(showedList == null){
		showedList = new Array();
	}
	if(showedList[o.name] == null){
		showedList[o.name] = o;
	}
	this.showedList = showedList;
	this.initShowList(o);
}
//初始化原始数据为类别列表
jssClassShow.prototype.initClasses = function(){
	for(var i = 0;i < this.list.length;i++){
		this.cList[i] = new jssClass(this.list[i][0],this.list[i][1],this.list[i][2],this.list[i][3],this.list[i][4],this);
	}
}
jssClassShow.prototype.sendError = function(fun){
	if(this.debug){
		alert(fun);
	}
}
//总类别长度
jssClassShow.prototype.length = function(){
	return this.list.length;
}
//类别原始数据
jssClassShow.prototype.list = function(){
	return this.list;
}
//返回某个类别下的所有类别
jssClassShow.prototype.getClasses = function(parentID){
	var re = null;
	for(var i = 0;i < this.cList.length;i++){
		if(this.cList[i].id == parentID){
			re = this.cList[i].initClasses(this);
		}
	}
	return re;
}
//返回一个菜单项
jssClassShow.prototype.getJSSClass = function(id,index){
	var re = null;
	if(index == null){
		for(var i = 0;i < this.cList.length;i++){
			if(this.cList[i].id == id){
				re = this.cList[i];
			}
		}
	}
	else{
		re = this.cList[0];
	}
	return re;
}
//单个类别
function jssClass(id,name,parentID,rootID,childsLength,jssShow,delay){
	this.id = id;
	this.name = name;
	this.parentID = parentID;
	this.childsLength = childsLength;
	this.rootID = rootID;
	this.jssShow = jssShow;
	this.subClass = null;//当前类别下的所有类别
	this.li = document.createElement("LI");
	this.li.jssClass = this;
	this.layer = null;
	this.div = document.createElement("DIV");
	this.delay = delay == null ? 300 : delay;
	this.showed = false;
	this.parent = null;
	this.childLength = null;
	this.getDiv();
}
jssClass.prototype.getChildLength = function(){
	var re = 0;
	if(this.childLength == null){
		var list = this.jssShow.cList;
		for(var i = 0;i < list.length;i++){
			if(list[i].parentID == this.id){
				re ++;
			}
		}
		this.childLength = re;
	}
	else{
		re = this.childLength;
	}
	return re;
}
//初始化当前类别下的所有子类，并返回;
jssClass.prototype.initClasses = function(jssShow){
	if(jssShow == null)jssShow = this.jssShow;
	if(jssShow == null)return null;
	if(this.subClass == null){
		this.subClass = new Array();
		var index = 0;
		for(var i = 0;i < jssShow.cList.length;i++){
			if(jssShow.cList[i].parentID == this.id){
				this.subClass[index] = jssShow.cList[i];
				index ++;
			}
		}
	}
	return this.subClass;
}
//返回当前类别同一级的类别列表
jssClass.prototype.getCLC = function(){
	var re = null;
	if(this.jssShow != null){
		re = this.jssShow.getClasses(this.parentID);
	}
	return re;
}
//返回上一级类别
jssClass.prototype.getParent = function(){
	var re = null;
	if(this.parent == null){
		if(this.jssShow != null){
			re = this.jssShow.getJSSClass(this.parentID);
		}
		this.parent = re;
	}
	else{
		re = this.parent;
	}
	return re;
}
//返回当前类到根类的列表
jssClass.prototype.getParents = function(re){
	if(re == null)re = new Array();
	var temp = null;
	temp = this.getParent();
	if(temp != null){
		if(temp.parentID != -1)re.push(temp);
		temp.getParents(re);
	}
	return re;
}
//返回当前类到根类的列表的字符串
jssClass.prototype.getParentString = function(split){
	if(split == null)split = " ";
	var re = "";
	var o = this.getParents();
	for(var i = 0;i < o.length;i++){
		re = o[i].name + re;
		if(i < o.length - 1)re = split + re;
	}
	return re;
}
//返回一个DIV对象
jssClass.prototype.getDiv = function(left,top){
	if(left == null || left.toString() == "NaN")left = 200;
	if(top == null || top.toString() == "NaN")top = 200;
	this.div.style.position = "absolute";
	this.div.style.width = "10px";
	this.div.style.left = left - 3;
	this.div.style.top = top;
	this.div.style.border = "1px solid #000";
	this.div.className = "jsClassDiv";
	this.div.jssClass = this;
	this.showTime = null;
	this.div.innerHTML = "";
	return this.div;
}

//返回可以显示的层
jssClass.prototype.getLayer = function(left,top){
	var re = document.createElement("ul");
	if(this.layer == null){
		if(this.subClass == null)this.initClasses();
		var len = 0;
		for(var i = 0;i < this.subClass.length;i++){
			re.appendChild(this.subClass[i].getCurrentItem())
			var l = this.getLen(this.subClass[i].name);
			len = l > len ? l : len;
		}
	}
	var w = len * 6 + 35;
	var divMinWidth = 120;
	if(w < divMinWidth) w = divMinWidth;
	var e = this.getDiv(left,top);
	this.div.style.width = w;
	e.appendChild(re)
	return e;
}
//返回当前条目的HTML
jssClass.prototype.getCurrentItem = function(){
	var re = this.li;
	re.id = "jssClassLi" + this.id;
	if(this.childsLength != 0){
		re.className = "haveChild";
	}
	re.onmouseover = this.mouseOver;
	re.onmouseout = this.mouseOut;//page.replace("$classid$",this.id)
	re.innerHTML = "<a title='点击选择此类别' href='" + this.jssShow.page.replace("$classid$",this.id).replace("$class$",re.id) + "' onfocus='this.blur()'>" + this.name + "</a>";
	return re;
}
jssClass.prototype.getLen = function(str){
	var i ,len;	
	len = 0;
	for(i = 0;i < str.length;i++){
		if(str.charCodeAt(i) > 128){
			len += 2;
		}
		else{
			len +=1;
		}
	}
	return len;
}
jssClass.prototype.mouseOver = function(){
	this.showTime = setTimeout(show,this.jssClass.delay,this)
	if(this.jssClass != null){
		this.jssClass.jssShow.onAction = true;
	}
}
jssClass.prototype.mouseOut = function(){
	clearTimeout(this.showTime)
	if(this.jssClass != null){
		this.jssClass.jssShow.onAction = false;
		this.jssClass.jssShow.mouseOut();
	}
}
function show(o){
	if(!o.jssClass.showed){
		if(o.jssClass.getChildLength() != 0){
			var li = o.jssClass.li;
			var left = o.jssClass.getDivLeft();
			var top = o.jssClass.getDivTop();
			o.jssClass.insertLayer(left,top);
		}
		o.jssClass.jssShow.addItemShowList(o.jssClass);
		o.jssClass.mouseOut();
	}
}
var jssAllRight = 0;
var jssDirect = 1;
//返回当前类别下一级类别的DIV的Left
jssClass.prototype.getDivLeft = function(){
	var parent = this.getParent();
	var parentDivWidth = parseInt(parent.div.style.width) - 2;
	var parentLeft = parseInt(parent.div.style.left);
	var left = this.getLeft(this.li) + parentDivWidth - 2;
	var l = 0;
	if(left > document.body.clientWidth - 120){
		jssDirect = 0;
	}
	var sLeft = parseInt(this.div.style.left);
	if(jssDirect == 0){
		left = parentLeft - parentDivWidth;
	}
	if(left < 0){//如果下级菜单LEFT小于0,重新计算LEFT
		jssDirect = 1;
		left = parentLeft + parentDivWidth;
	}
	return left;
}
//返回当前类别下一级类别的DIV的Top
jssClass.prototype.getDivTop = function(){
	var top = this.getTop(this.li);
	top -= (this.getChildLength() / 2) * 5;
	if(top < 10)top = 10;
	return top;
}
///对象的绝对Left
jssClass.prototype.getLeft = function(e){
	var t = e.offsetTop;
	var l = e.offsetLeft;
	while(e = e.offsetParent){
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	return l
}

///对象的绝对Top
jssClass.prototype.getTop = function (e){
	var t = e.offsetTop;
	var l = e.offsetLeft;
	while(e = e.offsetParent){
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	return t
}
jssClass.prototype.hidden = function(){
	this.div.style.display = "none";
	this.jssShow.showCount --;
	this.showed = false;
}
jssClass.prototype.insertLayer = function(left,top,isShowParent){
	if(isShowParent){
		var list = this.getParents();
		var l = 0,t = 0;
		var root = list[list.length - (0 + 1)];
		if(root != null){
			root = root.getParent();
			if(root != null){
				root.insertLayer(left,top);
				root.jssShow.addItemShowList(root);
			}
		}
		
		if(list.length == 0){//如果是根
			if(this.id == -1){
				this.insertLayer(left,top);
			}
			else{
				var ds = this.getParent();
				if(ds != null){
					ds.insertLayer(left,top);
				}
				else{
					this.insertLayer(left,top);
				}
			}
			return;
		}
		for(var i = 0;i < list.length;i++){
			show(list[list.length - (i + 1)].li);
		}
		this.li.className = "CurrentLiClass";
		return;
	}
	this.showed = true;
	if(this.div.style.display == "none"){
		this.div.style.display = '';
	}
	else{
		var ur = this.getLayer(left,top);
		var menu = document.getElementById("menu");
		this.jssShow.divShowTimer = setTimeout(hiddenDiv,2000,this.jssShow);
		menu.appendChild(ur);}
}
var fjc = null;
if(window.onlyShowTowLayer){
	fjc = new jssClassShow(cList,null,window.goodsSortFileName,document.getElementById("menu"));
}



