﻿/*------------------------------------------------------------------------------------------------------------/
 * JavaScript Framework Written for WOLFHOLE. Base On JQuery 1.3+
/*-----------------------------------------------------------------------------------------------------------*/

// jQuery Easing By George McGinley Smith
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

//加载时间统计-初始时间
var preTime=new Date();


//jQuery.noConflict();
var isIE6 = (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1);
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

jQuery(function($) {
	$("a[rel='external']").attr("target", "_blank");//链接处理
});
//if(isIE6){jQuery.fx.off = true;}
//if(!isIE6){jQuery.easing.def = "easeOutBack";}

//底栏
function toggleBottom(){
	jQuery("#popbox").css("filter", "alpha(Opacity=80)");
	
	logoScroll();
	
	jQuery("#closeBot").click(function(){
		if(jQuery("#popbox").css("top")=="0px"){
			ExtendBottom();
		}else{
			FoldBottom();
		}
	});
	
	var st;
	jQuery("#showbottom").hover(function(){
		if(st!=null)clearTimeout(st);
		st = setTimeout(function(){
			ExtendBottom();
			st = null;
		}, 300);
	},function(){
		if(st!=null)clearTimeout(st);
		st = setTimeout(function(){
			FoldBottom();
			st = null;
		}, 600);
	});
}

function ExtendBottom(){
	jQuery("#popbox").animate({
		top: "-78px",
		height: "110px"
	}, {queue: false, duration: 500, easing: "easeOutBack"});
	jQuery("#closeBot").removeClass("closeBot");
	jQuery("#closeBot").addClass("closeBotSelected");
	jQuery("#popbox h2").css("margin-top", "20px");
	jQuery("#vLink").css("margin-top", "19px");
	jQuery("#logoBottom").css("margin-top", "16px");
}
function FoldBottom(){
	jQuery("#popbox").animate({
		top: "0px",
		height: "35px"
	}, {queue: false, duration: 500, easing: "easeOutBack"});
	jQuery("#closeBot").removeClass("closeBotSelected");
	jQuery("#closeBot").addClass("closeBot");
	jQuery("#popbox h2").css("margin-top", "11px");
	jQuery("#vLink").css("margin-top", "35px");
	jQuery("#logoBottom").css("margin-top", "35px");
}
//底部LOGO滚动
function logoScroll(){
	var obj = jQuery("#logoBottom .container");
	jQuery("#logoToRight").click(function(){
		var curA = obj.find("a:first");
		curA.css("margin-left", "5px")
			.animate({marginLeft: "-" + curA.width() + "px"}, 500,	"easeOutBounce",
		function(){
			curA.appendTo(obj);
			curA.css("margin-left", "5px");
		});
	});
	jQuery("#logoToLeft").click(function(){
		var curA = obj.find("a:last");
		curA.prependTo(obj);
		curA.css("margin-left", "-" + curA.width() + "px")
			.animate({marginLeft: "5px"}, 500, "easeOutBounce");
	});
//	jQuery("#logoToLeft").hover(function(){
//		jQuery(this).css("background-position", "left -200px");
//	},function(){
//		jQuery(this).css("background-position", "left 0px");
//	});
//	jQuery("#logoToRight").hover(function(){
//		jQuery(this).css("background-position", "right -300px");
//	},function(){
//		jQuery(this).css("background-position", "right -100px");
//	});
}
//首页滚动
function scrollFocus(){
	var delaytime = 5000;
	var obj = jQuery("#scrollFocus ul");
	var stepScroll = function(){
		var curLi = obj.find("li:first");
		curLi.animate({
			marginTop: "-" + curLi.height()
		},
		300,
		"easeOutBack",
		function(){
			curLi.appendTo(obj);
			curLi.css("margin-top", "0px");
		});
	};
	setInterval(stepScroll, delaytime);
}

//内页边栏
function toggleSidebar(action){
	//var delayTime = (isIE6) ? 300 : 500;
	var delayTime = 300;
	if (action != "toFold" && action != "toUnFold"){//如果action未指定则默认为展开边栏;优先级低于cookie
		var action = "toUnFold";
	}
	var ShowSidebar = getCookie("kspeShowSidebar");//大于0表示展开边栏
	if(ShowSidebar == "" || ShowSidebar == undefined){//如果浏览器没有存储这个cookie
		if(action == "toUnFold"){
			setCookie("kspeShowSidebar", 1);
			ShowSidebar = 1;
		}else{
			setCookie("kspeShowSidebar", 0);
			ShowSidebar = 0;
		}
		
	}
	if(ShowSidebar == 0){
		jQuery("#divlineBT").append("<a id='BT_ToFold' class='BT_Folded'></a><a id='BT_ToUnfold' class='BT_ToUnfold'></a>");
		if(jQuery("#mainSidebar").is(":visible")){
			jQuery("#mainSidebar").hide();
			jQuery("#mainboxCon").css({background: "none", width: "820px"});
			jQuery("#divlineArrow").css("background-position", "0px 7px");
		}
	}
	if(ShowSidebar == 1){
		jQuery("#divlineBT").append("<a id='BT_ToFold' class='BT_ToFold'></a><a id='BT_ToUnfold' class='BT_Unfolded'></a>");
		if(jQuery("#mainSidebar").css("display") == "none"){
			jQuery("#mainSidebar").show();
			jQuery("#mainboxCon").css({background: "url(../Skin/kspe/Images/divline_lp.gif) repeat-y 2px", width: "599px"});
			jQuery("#divlineArrow").css("background-position", "-100px 7px");
		}
	}

	jQuery("#BT_ToUnfold").click(function(){
		if(jQuery("#mainSidebar").is(":hidden")){//如果隐藏了则展开
			jQuery("#mainSidebar").animate({
				width: "226px",
				opacity: "100%"
			}, {queue: false, duration: delayTime});
			jQuery("#mainboxCon").animate({
				width: "599px"
			}, {queue: false, duration: delayTime});
			jQuery("#mainboxCon").css("background", "url(../Skin/kspe/Images/divline_lp.gif) repeat-y 2px");
			jQuery("#BT_ToFold").removeClass();
			jQuery("#BT_ToUnfold").removeClass();
			jQuery("#BT_ToFold").addClass("BT_ToFold");
			jQuery("#BT_ToUnfold").addClass("BT_Unfolded");
			jQuery("#divlineArrow").css("background-position", "-100px 7px");
			setCookie("kspeShowSidebar", 1);
		}
	});
	
	jQuery("#BT_ToFold").click(function(){
		if(jQuery("#mainSidebar").is(":visible")){//如果展开了则隐藏
			jQuery("#mainSidebar").animate({
				width: "hide",
				opacity: "hide"
			}, {queue: false, duration: delayTime});
			jQuery("#mainboxCon").animate({
				width: "820px"
			}, {queue: false, duration: delayTime});
			jQuery("#mainboxCon").css("background", "none");
			jQuery("#BT_ToFold").removeClass();
			jQuery("#BT_ToUnfold").removeClass();
			jQuery("#BT_ToFold").addClass("BT_Folded");
			jQuery("#BT_ToUnfold").addClass("BT_ToUnfold");
			jQuery("#divlineArrow").css("background-position", "0px 7px");
			setCookie("kspeShowSidebar", 0);
		}
	});
	
}

//简单列表/图文列表切换
//function toggleList(){
//	var ListStyle = "";
//	ListStyle = getCookie("kspeListStyle");
//	if(ListStyle == "" || ListStyle == undefined){
//		setCookie("kspeListStyle", "PicList");
//		ListStyle = "PicList";
//	}
//	if(ListStyle == "PicList"){
//		jQuery("#PicListBox").fadeIn(300);
//	}
//	if(ListStyle == "SimList"){
//		jQuery("#SimListBox").fadeIn(300);
//		jQuery("#listSwitch").removeClass("listSwitch");
//		jQuery("#listSwitch").addClass("listSwitch2");
//		jQuery("#listSwitch").text("切换到图文列表");
//	}
//	jQuery("#listSwitch").click(function(){
//		if(jQuery("#SimListBox").is(":hidden")){
//			jQuery("#PicListBox").hide();
//			jQuery("#SimListBox").fadeIn(300);
//			jQuery("#listSwitch").removeClass("listSwitch");
//			jQuery("#listSwitch").addClass("listSwitch2");
//			jQuery("#listSwitch").text("切换到图文列表");
//			setCookie("kspeListStyle", "SimList");
//		}else{
//			jQuery("#SimListBox").hide();
//			jQuery("#PicListBox").fadeIn(300);
//			jQuery("#listSwitch").removeClass("listSwitch2");
//			jQuery("#listSwitch").addClass("listSwitch");
//			jQuery("#listSwitch").text("切换到简单列表");
//			setCookie("kspeListStyle", "PicList");
//		}
//	});
//}

//在新窗口运行指定代码
function CodeProcess()
{
	var oRunCode = jQuery("#ConField .RunableCode");
	var oCopyCode = jQuery("#ConField .CopyableCode");
	if(oRunCode.length > 0){
		oRunCode.each(function(i, ele){
			var oRunButton = "RunBtn_" + i;
			var rCode = jQuery(ele).find("textarea").val();
			jQuery(ele).append("<a id="+oRunButton+">运行代码</a>");
			jQuery("#"+oRunButton).click(function(){
				var oWin = window.open("", "", "");
				oWin.opener = null;
				oWin.document.write(rCode);
				oWin.document.close();
			});
			var oCopyButton = "CopyBtn_" + i;
			jQuery(ele).append("<a id="+oCopyButton+">复制代码</a>");
			jQuery("#"+oCopyButton).click(function(){
				if(window.clipboardData!=undefined){
					window.clipboardData.setData("Text", rCode);
				}else{
					ksPopup("您的浏览器禁止读写剪贴板", ele, "10px");
				}
			});
		});
	}
	if(oCopyCode.length > 0){
		oCopyCode.each(function(i, ele){
			var oCopyButton = "CopyBtn_" + i;
			jQuery(ele).append("<a id="+oCopyButton+">复制代码</a>");
			jQuery("#"+oCopyButton).click(function(){
				var rCode = jQuery(ele).find("textarea").val();
				if(window.clipboardData!=undefined){
					window.clipboardData.setData("Text", rCode);
				}else{
					ksPopup("您的浏览器禁止读写剪贴板", ele, "10px");
				}
			});
		});
	}
//	var oXSLTCode = jQuery("#ConField .oXSLTCode");
//	if(oXSLTCode.length > 0){
//		oXSLTCode.each(function(i, ele){
//			var oButton = "xBtn_" + i;
//			var oButton2 = "xBtn2_" + i;
//			jQuery(ele).append("<a id="+oButton+">生成xsl</a>");
//			jQuery(ele).append("<a id="+oButton2+">生成xml</a>");
//			jQuery("#"+oButton).click(function(){
//				var xslCode = jQuery(ele).find("textarea:last").val();
//				var oXSLWin = window.open("test.xsl", "", "");
//				oXSLWin.opener = null;
//				oXSLWin.document.write(xslCode);
//				oXSLWin.document.close();
//			});
//
//			jQuery("#"+oButton2).click(function(){
//				var xmlCode = jQuery(ele).find("textarea:first").val();
//				var oXMLWin = window.open("test.xml", "", "");
//				oXMLWin.opener = null;
//				oXMLWin.document.write(xmlCode);
//				oXMLWin.document.close();
//			});
//		});
//	}
}

/*栏目导航*/
function showSubChannel(){
	var oChannel = jQuery("#category dd>ul>li");
	var st;
	
	oChannel.each(function(i, ele){
		if(isIE){jQuery(ele).css("z-index", 100-i);}//重置ie下的z-index,修正覆盖问题
		var oSubChannel = jQuery(ele).find("ul");
		if(oSubChannel.length != 0){
			var oEntry = jQuery(ele).find("a:first");
			oSubChannel.css({left: oEntry.width(), filter: "alpha(Opacity=80)"});
			
			oEntry.mouseover(function(){
				oEntry.addClass("on");
				oSubChannel.show("10");
			});
			oSubChannel.mouseover(function(){
				oEntry.addClass("on");
				oSubChannel.show();
			});
			jQuery(ele).mouseout(function(){
				oEntry.removeClass("on");
				oSubChannel.hide();
			});
		}
	});
}


/**以下为公用函数**/
//定制的弹出显示
//Str, 要弹出显示的内容, 必选参数
//Width, 弹出容器的宽度, 必选参数
//Height, 弹出容器的高度, 必选参数
//Mask, 是否使周围内容变暗, 可选参数, 默认为false
//Container, 弹出的框体的相对定位容器, 可选参数, 默认为body
function ksAlert(Str, Width, Height, Mask, Container){
	var Mask = (Mask==undefined || Mask==null) ? false : Mask;
	var Container = (Container==undefined || Container==null) ? "body" : Container;
	var tMargin = "-" + Height/2 + "px 0 0 -" + Width/2 + "px";
	
	if(Mask) {
		jQuery("body").append("<div id='maskBox'></div>");
		jQuery("#maskBox").animate({opacity: "0"}, {queue: false, duration: 0})
		.animate({opacity: "0.3", width: "100%"}, {queue: true, duration: 0});
	}
	
	jQuery(Container).append("<div id='tipsBox'></div>");
	jQuery("#tipsBox").css({width: Width, height: Height, margin: tMargin});
	jQuery("#tipsBox").text(Str);
//	jQuery("#tipsBox").fadeIn("500");
	jQuery("#tipsBox").fadeIn({queue: false, duration: 500});
	jQuery("#tipsBox").click(function(){
		jQuery(this).fadeOut({queue: false, duration: 400});
		if(Mask){jQuery("#maskBox").fadeOut({queue: true, duration: 400});}
	});
}

//冒泡显示
//Str, 要弹出显示的内容, 必选参数
//Width, 弹出容器的宽度, 必选参数
//Container, 弹出的框体的相对定位容器, 可选参数, 默认为body
//offsetX, x偏移量, 可选参数
function ksPopup(Str, Container, offsetX){
	var Container = (Container==undefined || Container==null) ? "body" : Container;
	var offsetX = (offsetX==undefined || offsetX==null) ? "-50px" : offsetX;
	var oPopupBox = jQuery(Container).find(".popupBox");
	if (oPopupBox.length == 0){
		jQuery(Container).append("<span class='popupBox'></span>");
		jQuery(Container).css({position: "relative"});
		oPopupBox = jQuery(Container).find(".popupBox");
		oPopupBox.css({top: "20px", left: offsetX});
	}
	oPopupBox.text(Str);
	oPopupBox.fadeIn({queue: true, duration: 400});
	setTimeout(function(){oPopupBox.fadeOut({queue: true, duration: 800})}, 4000);
}



//Cookie操作
function getCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		{
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) break;
	}
	return;
}
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1)
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}
function setCookie(name, value, expires, path, domain, secure)
{
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}


