var SNSLeftNav = function(){}
SNSLeftNav.lifes = null;
SNSLeftNav.groups = null;
SNSLeftNav.divId = "sns_left_list_div";
SNSLeftNav.lifeJSLoadPath = null;
SNSLeftNav.lifeJSLoadCharset = "gbk";
SNSLeftNav.groupJSLoadPath = null;
SNSLeftNav.groupJSLoadCharset = "utf-8";

SNSLeftNav.sleep = function(tm){
	var begin = new Date();
	while(new Date()-begin<tm){
		continue;
	}
}

SNSLeftNav.myLifes = function(){
	if(SNSLeftNav.lifes == null || typeof(SNSLeftNav.lifes) == "undefined"){
		SNSLeftNav.lifes = new Array();
	}
	var content = '<table border="0" cellspacing="0" cellpadding="0">\
		      <tr>\
		      <td>\
		      <div class="navCont">';
	var contentByType = ["","","","",""];
	var nameByType = ["大学班级","中学班级","小学班级","幼儿园班级","其他"];
	for(var i=0;i<SNSLeftNav.lifes.length;i++){
		var idx = -1;
		var type = parseInt(SNSLeftNav.lifes[i].type);
		switch(type){
			case 5:	
			case 6:	
				idx = 0;
				break;
			case 2:	
			case 3:	
			case 4:	
				idx = 1;
				break;
			case 1:	
				idx = 2;
				break;
			case 8:	
				idx = 3;
				break;
			case 7:	
				idx = 4;
				break;
		}
		if(idx < 0) continue;
		var classname = SNSLeftNav.lifes[i].cname;
		var iny = SNSLeftNav.lifes[i].iny;
		if(iny == 1 || iny == 3){
			classname = SNSLeftNav.cutStrHZ(classname,9)+"(待批准)";
		}else{
			classname = SNSLeftNav.cutStrHZ(classname,12);
		}
		if(contentByType[idx].length < 1) contentByType[idx] = "<ul>";
		contentByType[idx] += '<li><a href="http://class.chinaren.com/class/'+SNSLeftNav.lifes[i].cuuid+'" title="'+SNSLeftNav.lifes[i].cname+'">·'+classname+'</a></li>';
	}
	for(var i=0;i<nameByType.length;i++){
		content += "<h2>"+nameByType[i]+"</h2>";
		if(contentByType[i].length < 1){
			content += '<ul><li><span>·暂无班级</span></li></ul>';
		}else{
			content += contentByType[i]+'</ul>';
		}
	}
	content += '<div class="linefenge1"></div>\
		   <p><img src="http://s1.cr.itc.cn/sns/default/images/class_btn_8.gif" /><a href="http://class.chinaren.com/school/search_school.jsp?t=class">查找班级</a></p>\
		   <p><img src="http://s1.cr.itc.cn/sns/default/images/class_btn_8.gif" /><a href="http://class.chinaren.com/school/search_school.jsp">查找学校</a></p>\
		   <div class="blank10"></div>\
		   </div>\
		   </td>\
		   <td width="3" rowspan="2" class="rb"></td>\
		   </tr>\
		   <tr>\
		   <td height="4" class="rb"></td>\
		   </tr>\
		   </table>';
	return content;
}

SNSLeftNav.myGroups = function(){
	if(typeof(SNSLeftNav.groups) == "undefined" || !SNSLeftNav.groups || SNSLeftNav.groups == null){
		SNSLeftNav.groups = new Array();
	}
	if(!SNSLeftNav.groups || typeof SNSLeftNav.groups == "undefined") return;
	var content = '<table border="0" cellspacing="0" cellpadding="0">\
		      <tr>\
		      <td>\
		      <div class="navCont">\
		      <ul>';
	var i = 0;
	SNSLeftNav.groups.sort(function(a,b){return a.name.localeCompare(b.name)});
	for(;i<SNSLeftNav.groups.length;i++){
		content += '<li><a href="http://groups.chinaren.com/'+SNSLeftNav.groups[i].gid+'" title="'+SNSLeftNav.groups[i].name+'">·'+SNSLeftNav.cutStrHZ(SNSLeftNav.groups[i].name,12)+'</a></li>';
	}
	if(i < 1) content += '<li><div class=blank10></div><span>·暂无群组</span></li>';
	content += '</ul>\
		   <div class="linefenge1"></div>\
		   <p><img src="http://s1.cr.itc.cn/sns/default/images/class_btn_8.gif" /><a href="http://groups.chinaren.com/create">创建群组</a></p>\
		   <div class="blank10"></div>\
		   </div>\
		   </td>\
		   <td width="3" rowspan="2" class="rb"></td>\
		   </tr>\
		   <tr>\
		   <td height="4" class="rb"></td>\
		   </tr>\
		   </table>';

	return content;
}

SNSLeftNav.tm = null;
SNSLeftNav.loadLifeNum = 0;
SNSLeftNav.loadGroupNum = 0;
SNSLeftNav.showListDiv = function(type,parentId){
	if(document.documentElement.doScroll){
		try{	
			document.documentElement.doScroll("left");
		}catch(e){
			return;	
		}
	}
	var parentObj = document.getElementById(parentId);
	if(parentObj == null) return;
	if(SNSLeftNav.tm != null){
		clearTimeout(SNSLeftNav.tm);
	}
	if(type == 'life'){
		if(SNSLeftNav.lifes == null || !SNSLeftNav.lifes instanceof Array){
			if(typeof(life) != "undefined" && typeof(life.life) != "undefined"){
				SNSLeftNav.lifes = life.life;
			}else if(SNSLeftNav.lifeJSLoadPath != null){
				if(SNSLeftNav.loadLifeNum < 1){
					SNSLeftNav.loadJS(SNSLeftNav.lifeJSLoadPath,SNSLeftNav.lifeJSLoadCharset);
				}
				SNSLeftNav.loadLifeNum++;
				/*if(++SNSLeftNav.loadLifeNum>=5){
					SNSLeftNav.lifes = new Array();
				}*/
				SNSLeftNav.tm = setTimeout("SNSLeftNav.showListDiv('"+type+"','"+parentId+"')",100);
				return;
			}
		}
		content = SNSLeftNav.myLifes();
	}else if(type == 'group'){
		if(SNSLeftNav.groups == null || !SNSLeftNav.groups instanceof Array){
			if(typeof(mygroup) != "undefined" && typeof(mygroup.groups) != "undefined"){
				SNSLeftNav.groups = mygroup.groups;
			}else if(SNSLeftNav.groupJSLoadPath != null){
				if(SNSLeftNav.loadGroupNum < 1){
					SNSLeftNav.loadJS(SNSLeftNav.groupJSLoadPath,SNSLeftNav.groupJSLoadCharset);
				}
				SNSLeftNav.loadGroupNum++;
				/*if(++SNSLeftNav.loadGroupNum>=5){
					SNSLeftNav.groups = new Array();
				}*/
				SNSLeftNav.tm = setTimeout("SNSLeftNav.showListDiv('"+type+"','"+parentId+"')",100);
				return;
			}
		}
		content = SNSLeftNav.myGroups();
	}
	if(!content || typeof content == "undefined") return;
	SNSLeftNav.showDiv(content,parentObj);
}
SNSLeftNav.showDiv = function(content,parentObj){
	var div = document.getElementById(SNSLeftNav.divId);
	if(div == null){
		div = document.createElement("div");
		div.id = SNSLeftNav.divId;
		div.className = "navMovie";
		div.style.position = "absolute";
		div.style.zIndex = 9999;
		document.body.appendChild(div);
	}
	div.innerHTML = '<iframe style="position:absolute; z-index:-1;" frameborder="0" src="about:blank" width=100% height=100%></iframe>'+content;
	//div.innerHTML = content;
	div.onmouseover = function(){
		window.clearTimeout(SNSLeftNav.tm);	
	}
	div.onmouseout = function(){
		SNSLeftNav.hiddenListDiv();
	}
	div.style.display = '';
	var offsets = Position.cumulativeOffset(parentObj);
	div.style.left = (offsets[0]+132)+"px";
	div.style.top = offsets[1]+"px";
	//SNSLeftNav.showSelect('none');
	//SNSLeftNav.showSwf('none');
}

SNSLeftNav.hiddenListDiv = function(){
	SNSLeftNav.tm = window.setTimeout("try{document.getElementById('"+SNSLeftNav.divId+"').style.display='none';}catch(e){}",200);
}


SNSLeftNav.scriptId = "SnsLeftNav";
SNSLeftNav.isLoadedJS = new Array(); 
SNSLeftNav.loadJS = function(_jsFile,_charset){
	if(SNSLeftNav.isLoadedJS[_jsFile] != null && typeof(SNSLeftNav.isLoadedJS[_jsFile]) != "undefined" && SNSLeftNav.isLoadedJS[_jsFile] == true) return;
	var oJS = document.getElementById(SNSLeftNav.scriptId);
        if (oJS!=null && oJS.tagName.toLowerCase()=="script") {
                document.getElementsByTagName("head").item(0).removeChild(oJS);
        }
        oJS = document.createElement('script');
        oJS.setAttribute("language","JavaScript");
        oJS.setAttribute("id",SNSLeftNav.scriptId);
        oJS.setAttribute("charset",_charset);
        oJS.setAttribute("src", _jsFile);
        document.getElementsByTagName("head").item(0).appendChild(oJS);
	SNSLeftNav.isLoadedJS[_jsFile] = true;
}

SNSLeftNav.showSelect = function(_sDisplay){
	var aType = document.getElementsByTagName("select");
	for (var i = 0; i < aType.length; i++){
		aType[i].style.display = _sDisplay;
	}
}

SNSLeftNav.showSwf = function(_sDisplay){
	var aType = document.getElementsByTagName("embed");
	for (var i = 0; i < aType.length; i++){
		aType[i].style.display = _sDisplay;
	}
}

SNSLeftNav.cutStrHZ = function(str, length) { 
	var count = 0; 
	var res = ""; 
	for (var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i)>127) { 
			count = count + 2; 
		} else { 
			count = count + 1;
		} 
		if (count > length*2) break;
		res = res + str.charAt(i);
	}
	return res; 
} 

SNSLeftNav.login = function() {
        var theHost = top.window.location.host;
        var theUrl = top.window.location.href;
        top.window.location = "http://profile.chinaren.com/zhs/loginTip.jsp?group=alumni&url=" + UrlConv(theUrl);
}

