function init_menu() {
	$("#nav>li>a").each(function(){
		$(this).mouseover(function(){
			$(this).parent().find("ul").css("display","block");
			$(this).parent().find("ul").mouseout(function(){
				$(this).css("display","none");
				$(this).parent().find("a").eq(0).removeClass("s");
			}).mouseover(function(){
				$(this).css("display","block");
				$(this).parent().find("a").eq(0).addClass("s");
			});
			clearStyle();
			$(this).addClass("s");
		}).mouseout(function(){
			$(this).parent().find("ul").css("display","none");
			$(this).removeClass("s");
		});
	});
}

function init_curriculum () {
	$("#curriculum>dl>dt").each(function(){$(this).click(function(){
		if($(this).parent().hasClass("s")){
			$(this).parent().removeClass("s");
			$(this).attr("title","点击展开");
		}else {
			$("#curriculum>dl>dt").each(function(){$(this).parent().removeClass("s");});
			$(this).parent().addClass("s");
			$(this).attr("title","点击收回");
		}
	});});
	$("#curriculum>dl>dt>a").each(function(i){
		$(this).click(function(){
			$("#curriculum>dl>dt").unbind( "click" )
		});
	});
}

function init_work() {
	$("#works_show>.list>.t").each(function(i){
		this.local = i;
		$(this).click(function(){
			if($("#works_show>.list>ul").eq(this.local).css("display")=="block"){
				$(this).attr("id","");
				$("#works_show>.list>ul").eq(this.local).slideToggle("slow");
				$(this).attr("title","点击展开");
			} else {
				$("#works_show>.list>ul").each(function(i){
					if($(this).css("display")=="block"){
						$(this).slideToggle("slow");
						$("#works_show>.list>.t").eq(i).attr("id","");
					}
				});
				$(this).attr("id","works_show_ts");
				$("#works_show>.list>ul").eq(this.local).slideToggle("slow");
				$(this).attr("title","点击收回");
			}
		});
	;});
	$("#works_show li").each(function(){
		$(this).mouseover(function(){$(this).addClass("s");}).mouseout(function(){$(this).removeClass("s");});
	});
	$("#works_show>.list>.t>a").each(function(i){
		$(this).click(function(){
			$("#works_show>.list>.t").unbind( "click" )
		});
	});
}

function init_float() {
	oFloat = document.createElement("div");
	oFloat.style.width = 160 + "px";
	oFloat.style.height = 300 + "px";
	oFloat.style.position = "absolute";
	oFloat.style.top = 200 + "px";
	oFloat.style.right = 20 + "px";
	oFloat.style.background = "url('/templets/eduhtml/img/gg.png') no-repeat";
	oFloat.style.cursor = "pointer";
	oFloat.style.textAlign = "right";

	if(!window.XMLHttpRequest){
		oFloat.style.background = "none";
		oFloat.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='/templets/eduhtml/img/gg.png')";
	}

	oA = document.createElement("a");
	oA.style.marginTop = 2 + "px";
	oA.style.marginRight = 2 + "px";
	oA.innerHTML = "<img src='/templets/eduhtml/img/close.png' />";

	oFloat.appendChild(oA);
	document.body.appendChild(oFloat);
	window.onscroll = function(){change();}
	oFloat.onclick = function(){
		doyoo.util.openChat();return false;
	}
	oA.onclick = function(){
		evt = arguments[0]||window.event;
		if (evt.stopPropagation) {
			evt.stopPropagation();
		} else {
			evt.cancelBubble = true;
		}
		oFloat.style.display = "none";
	}
}

 function change(){
		if(parseInt(oFloat.style.top) == parseInt(document.documentElement.scrollTop) + 200)
			return;
		else{
			if(parseInt(oFloat.style.top) < parseInt(document.documentElement.scrollTop) + 200)
				oFloat.style.top = parseInt($(oFloat).css("top"))+1 + "px";
			else
				oFloat.style.top = parseInt($(oFloat).css("top"))-1 + "px";
			setTimeout(change,5);
		}
}

function clearStyle(){
	$("#nav>li>a").each(function(){
		$(this).removeClass("s");
	});
}

function openChat(t)
{
	var url = "http://chat.doyoo.net/WebModule/chat/p.do?c=11464";

	if(	t!= null &&  t.length != 0 )
		url +="&g=" + t;

	var sid = getCookie("DOYOO_VISITOR_ID");
	var cid = getCookie("DOYOO_USER_ID");
	var refer = getCookie("DOYOO_VISITOR_REFER");
	var loc = document.location.href;

	if(sid!=null)	url +="&v=" + sid;
	if(cid !=null)	url +="&u=" + cid;
	if(refer) url +="&refer="+shortURL(refer);
	if(loc) url +="&loc="+shortURL(loc);
	try{	url=url+"&r="+reseveKey ;}catch(e){}
	var param = "height=460,width=690,directories=no," + "location=no,menubar=no," + "resizeable=no,status=no,toolbar=no,top=100,left=200";

	var acceptWin = window.open(url,"chat_11464", param);
}

function getCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	else return null;
}

function shortURL(l)
{
    if(l==null)return '';
    l=encodeURIComponent(l);
    if(l.length > 500) l=l.substring(0,500);
    return l;
}

$(window).bind("load",init_menu);
$(window).bind("load",init_curriculum);
$(window).bind("load",init_work);
$(window).bind("load",init_float);