﻿/**
 * Cookie plugin
 * 
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) Dual licensed under the MIT and
 * GPL licenses: http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 * 
 * @example
 * $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 *       @example
 *       $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 *       @example
 *       $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 *       @example
 *       $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to
 *       use the same path and domain used when the cookie was set.
 * 
 * @param String
 *            name The name of the cookie.
 * @param String
 *            value The value of the cookie.
 * @param Object
 *            options An object literal containing key/value pairs to provide
 *            optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date
 *         from now on in days or a Date object. If a negative value is
 *         specified (e.g. a date in the past), the cookie will be deleted. If
 *         set to null or omitted, the cookie will be a session cookie and will
 *         not be retained when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default:
 *         path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie
 *         (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be
 *         set and the cookie transmission will require a secure protocol (like
 *         HTTPS).
 * @type undefined
 * 
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 * 
 * @example
 * $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 * 
 * @param String
 *            name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 * 
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires
				&& (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime()
						+ (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires
															// attribute,
															// max-age is not
															// supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path,
				domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie
							.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
jQuery.fn.slideLeft = function(speed, callback) {
	return this.animate({
				width : "hide"
			}, speed, callback);
}
jQuery.fn.slideRight = function(speed, callback) {
	return this.animate({
				width : "show"
			}, speed, callback);
}

// 写Cookie
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}
// 读Cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ')
			c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	return null;
}
// 清Cookie
function eraseCookie(name) {
	createCookie(name, "", -1);
}

function setHomepage(pageURL) {
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(pageURL);

	} else if (window.sidebar) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager
						.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				// 改方法在firefox3下不支持
				// alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项
				// signed.applets.codebase_principal_support 值该为true" );
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', pageURL);
	}
}

function myAddBookmark(title, url) {
	if ((typeof window.sidebar == "object")
			&& (typeof window.sidebar.addPanel == "function"))// Gecko
	{
		window.sidebar.addPanel(title, url, "");
	} else// IE
	{
		window.external.AddFavorite(url, title);
	}
}

function QueryString(fieldName) {
	var urlString = document.location.search;
	if (urlString != null) {
		var typeQu = fieldName + "=";
		var urlEnd = urlString.indexOf(typeQu);
		if (urlEnd != -1) {
			var paramsUrl = urlString.substring(urlEnd + typeQu.length);
			var isEnd = paramsUrl.indexOf('&');
			if (isEnd != -1) {
				return paramsUrl.substring(0, isEnd);
			} else {
				return paramsUrl;
			}
		} else {
			// search.jsp页面使用
			if (fieldName == "flag") {
				return "";
			}
			// sort.jsp页面使用
			else {
				return "01";
			}
		}
	} else {
		// search.jsp页面使用
		if (fieldName == "flag") {
			return "";
		}
		// sort.jsp页面使用
		else {
			return "01";
		}
	}
}

var iniPlayer = function() {

	var flashvars = {
		type : "video",
		autostart : "true",
		streamer : "lighttpd",
		abouttext : "Wanfang Video Player 1.4",
		aboutlink : "http://www.shwanfangdata.com"
	}		
	var flashvarsTeacther = {
		type : "video",
		autostart : "true",
		streamer : "lighttpd",
		abouttext : "Wanfang Video Player 1.4",
		aboutlink : "http://www.shwanfangdata.com",
		controlbar : 'none',
		displayclick : "none" //不可点击屏幕暂停
	}
	var mp3flashvers ={
		type : "audio",
		autostart : "true",
		streamer : "lighttpd",
		abouttext : "Wanfang Video Player 1.4",
		aboutlink : "http://www.shwanfangdata.com"
	}
	
	var params = {
		allowfullscreen : "true",
		allowscriptaccess : "always",
		wmode : "transparent"
	}
	var paramsTeacther = {
		allowfullscreen : "false",
		allowscriptaccess : "always",
		wmode : "transparent"
	}
	var attributesMp3Player = {
		id : "mp3Player",
		name : "mp3Player"
	}
	var attributesSingleClipPlayer = {
		id : "singleClipPlayer",
		name : "singleClipPlayer"
	}
	var attributesTeacherVideo = {
		id : "teacherVideoPlayer",
		name : "teacherVideoPlayer"
	}
	var attributesNotesVideo = {
		id : "notesVideoPlayer",
		name : "notesVideoPlayer"
	}
	
	//普通视频播放器
	swfobject.embedSWF("swf/player.swf", "player", "441", "367", "9.0.115",
			false, flashvars, params, attributesSingleClipPlayer);
	
	//教授头像播放器
	swfobject.embedSWF("swf/player.swf", "teacherVideo", "240", "160", "9.0.115",
			false, flashvarsTeacther, paramsTeacther, attributesTeacherVideo);
	
	swfobject.embedSWF("swf/player.swf", "notesVideo", "720", "576", "9.0.115",
			false, flashvars, params, attributesNotesVideo);
}

var singleClipPlayer = null;
var teacherVideoPlayer = null;
var notesVideoPlayer = null;

function playerReady(thePlayer) {
	if (thePlayer.id == 'singleClipPlayer' ) {
		singleClipPlayer = document.getElementById(thePlayer.id);
		
		//singleClipPlayer.addModelListener('ERROR','errorCallback');
	}
	if (thePlayer.id == 'teacherVideoPlayer') {
		teacherVideoPlayer = document.getElementById(thePlayer.id);
		//playClip(teacherVideoPlayer,clip);
	}
	
	if (thePlayer.id == 'notesVideoPlayer') {

		notesVideoPlayer = document.getElementById(thePlayer.id);
		notesVideoPlayer.addControllerListener('SEEK','seekCallback');
		notesVideoPlayer.addViewListener('PLAY','playCallback');
		notesVideoPlayer.addViewListener('STOP','stopCallback');
		playClip(notesVideoPlayer,clip);
	}
}

function errorCallback(message){
	alert(message);
}

function stopCallback(evt){
	teacherVideoPlayer.sendEvent('STOP');
}

function playCallback(evt){
	teacherVideoPlayer.sendEvent('PLAY');
}

function seekCallback(evt){
	teacherVideoPlayer.sendEvent('SEEK', ""+evt.position);
	//alert(evt.position);
}

function playClip(player,clip) {
//alert(clip.file);
	if(readCookie("player")!=null && readCookie("player")!=""){
	
	}else{
		if(window.confirm("在线播放需要专用插件,确定要下载安装吗？")){							
					player.sendEvent('STOP');
					
					//$.expose.close();
					$("#singleClipLayer").hide();
					$("#coursewareLayer").hide();
					window.location.href='wanfangvideoPlugins.zip';
					createCookie("player","installed","100");
						return;
		}else{
			createCookie("player","installed","100");
		}
	}
	//alert(player.sendEvent);
	//player.sendEvent('LOAD', clip);
	if (player&&player.sendEvent)
		
		player.sendEvent('LOAD', clip);
	else {
		setTimeout(function() {
					playClip(player,clip);
				}, 100);
	};
}

jQuery.fn.updateVideoLink = function() {

	var videoList = $(this);
	
		$("a[rel='#coursewareLayer']", videoList).each(function(i) {
															
				var hotlink = $(this);
				var currentLessonID = ""; //
				var source =""; 
				hotlink.overlay({
	
					mask: '#000',
					effect: 'apple',
					fixed: false,
					top: '0px',
					closeOnClick: false,
					
					onBeforeLoad: function () {
						
							var lessonListHtml = "";
							var techerIntroduce = ""; //讲师介绍
							var lessonIntroduce = "" ; //课程介绍
							
							//////////////////////许立竑 20100523修改：先登录才能观看--start--//////////////////
						
							// 先认证是否可以观看
						$.ajax({
							url : "JSONauthorityAction.action?fromAjax=ajax&runTime="
									+ Math.round(Math.random() * 10000),
							type : 'POST',
							dataType : 'json',
							async : false,
							success : function(data) {
								if (data.jsonAuthorityOK == "0") {
									// alert("认证失败");
									window.location.href = "authorityAction.action";
									return false;
								}
								if (data.jsonAuthorityOK == "10"
										|| data.jsonAuthorityOK == "11") {
									// alert("认证成功");
									// 计算费用
									// alert("计算费用"+link.attr("id"));
			
									$.ajax({
										url : "JSONcomputeVideoAction.action?fromAjax=ajax&sid="
													+ hotlink.attr("id") + "&runTime="
													+ Math.round(Math.random() * 10000),
										type : 'POST',
										dataType : 'json',
										async : false,
										success :	function(data) { //计费后开始播放视频，取得相关视频信息
										
												if(data.jsonMoneyEnough == "0")
												{
													alert("金额不足，无法观看视频！");
													return;
												}else
												{
													//alert("金额足，可以观看观看视频！");
												}
												//alert("金额验证完毕！");
												// 写入观看历史cookie start
												if (hotlink.attr("id") != null && hotlink.attr("id") != "") {
													if ($.cookie('wfvideohistory') == null) {
														$.cookie('wfvideohistory', hotlink
																		.attr("id"), {
																	expires : 7
																});
													} else {
														var sss = $
																.cookie('wfvideohistory');
														sss = sss + "_" + hotlink.attr("id");
			
														$.cookie('wfvideohistory', sss, {
																	expires : 7
																});
													}
												}					
											}
									});
								}
							}
						});
							
							//圣才视频 的处理
							var sflag = hotlink.attr("href");//圣才视频的标记
							var shencaiFlg = hotlink.attr("href_url"); //圣才视频的链接
							if("1" == sflag)
							{
								//window.location.href = "authorityAction.action";
								window.open(shencaiFlg);
								return false;
							}
							//////////////////////////////////////////////--end--////////////////////
							
							//同济视频的处理
							$.ajax({  //取课程列表
								   
								url : "JSONLesson.action?SID="
										+ hotlink.attr("id")
										+ "&runTime="
										+ Math.round(Math.random()
												* 10000),
								type : 'GET',
								dataType : 'json',
								async : false,
								success : function(data) {  //取回该课件下所有课程的列表，放入“课程列表”div中
								// 并开始播放第一节课
									lessonListHtml += "<ul >";
									for ( var i = 0; i < data.lessonList.length; i++) {
											var item = data.lessonList[i];
											
											lessonListHtml += '<li><a ';
											/*if (i==0) {
													lessonListHtml += 'class="currentLesson"';
													techerIntroduce = item.lecturerIntro;
													lessonIntroduce = item.lessonIntro;
													currentLessonID = item.sid_sub;
													source = item.source;
											}*/
											lessonListHtml += ' href="#" id="'+ item.sid_sub + '">' + item.lessonName+ '</a></li>';
											
										}
									lessonListHtml += '</ul>';
									
									$("#lessonList").html(lessonListHtml);
									/*$("#lessonIntroduce").html(lessonIntroduce);
									$("#techerIntroduce").html(techerIntroduce);*/
									
									$("a", $("#lessonList")).each(function(i) {//绑定课程标题点击事件
												
												var lessonLink = $(this);
												var success= "";
												var hasVideo = "1";
												
												lessonLink.click(function() {
													$("a", $("#lessonList")).removeClass("currentLesson"); //初始化当前课程样式
													$(this).addClass("currentLesson"); //给所选课程指导为当前课程样式
													currentLessonID = $(this).attr("id");
													$.ajax({  //取课程相关信息
														url : "JSONLesson.action?SID="
																+ hotlink.attr("id")
																+ "&sid_sub="
																+ currentLessonID
																
																+ "&runTime="
																+ Math.round(Math.random()
																		* 10000),
														type : 'GET',
														dataType : 'json',
														async : false,
														success : function(data) { 
															source = data.lessonList[0].source;
															$("#lessonIntroduce").html(data.lessonList[0].lessonIntro);
															$("#techerIntroduce").html(data.lessonList[0].lecturerIntro);
															$("#teacherPic").attr("src",data.lessonList[0].imageUrl);															hasVideo = data.lessonList[0].hasLittle;
														}
													})
													
													$.ajax({  //取课程相关附件
														url : "JSONLessonAtta.action?SID_sub="
																+ currentLessonID
																+ "&runTime="
																+ Math.round(Math.random()
																		* 10000),
														type : 'GET',
														dataType : 'json',
														async : false,
														success : function(data) { 
															$("a",$(".download")).each(function(){
																		$(this).addClass("no"); //默认附件样式为无附件样式
																		$(this).click(function(){return false;});
															})
															for ( var i = 0; i < data.lessonAttaList.length; i++) {
																var item = data.lessonAttaList[i];
																//alert(item.attachmentType);
																if(item.attachmentType == '1')//视频
																	$("a",$("div[class='d"+item.attachmentType+"']",$(".download"))).attr("href","download.action?sid="+currentLessonID+"_1").removeClass("no").unbind("click"); //如存在相应附件，则移除无附件样式
																else//视频以外
																	$("a",$("div[class='d"+item.attachmentType+"']",$(".download"))).attr("href",item.attachmentUrl).removeClass("no").unbind("click"); //如存在相应附件，则移除无附件样式
															}
														}
													})
													
													
													
													var notesClip = {
														type : "video",
														file : "http://127.0.0.1:8077/" + source + "/" + currentLessonID + "_1.wfv",
														title :  "http://127.0.0.1:8077/" + source + "/" + currentLessonID + "_0.wfv"
													}
													
													var teacherClip;
																							
													if (hasVideo=="1"||hasVideo==1) {
														$("#teacherSwitcher").show();
														$("#teacherSwitcher div").removeClass("videoOff");
														$("#maskWindow").removeClass("maskWindowPic");
														 teacherClip = {
															type : "video",
															file : "http://127.0.0.1:8077/" + source + "/" + currentLessonID + "_0.wfv",
															title : "Someone else's Cool Video"
														}
														playClip(teacherVideoPlayer,teacherClip);
														
													}else {
														$("#teacherSwitcher").hide();
														$("#maskWindow").addClass("maskWindowPic");
														if (teacherVideoPlayer) teacherVideoPlayer.sendEvent('STOP');
														//$("#teacherVideoWarp").hide();
														//$("#teacherPicWarp").show();
													}
													
													playClip(notesVideoPlayer,notesClip);
													return false;
											
											})
									})		

				
								}
							});
							
							
							
						},

					onLoad : function(content) {
						
							/*var notesClip = {
								type : "video",
								file : "http://127.0.0.1:8077/" + source + "/" + currentLessonID + "_1.wfv",
								title : "Someone else's Cool Video"
							}
							
							var teacherClip = {
								type : "video",
								file : "http://127.0.0.1:8077/" + source + "/" + currentLessonID + "_0.wfv",
								title : "Someone else's Cool Video"
							}
							
							playClip(teacherVideoPlayer,teacherClip);
							playClip(notesVideoPlayer,notesClip);*/
							
						$("a", $("#lessonList")).eq(0).click(); //触发第一节课
						$("a", $("#lessonTab")).eq(0).trigger('mouseover');//默认显示课程列表内容
						
					},
					
					onBeforeClose : function() {
						if (notesVideoPlayer) notesVideoPlayer.sendEvent('STOP');
						if (teacherVideoPlayer) teacherVideoPlayer.sendEvent('STOP');
					}
				});
		})
	$("a[rel='#singleClipLayer']", videoList).each(function(i) {
															
				var hotlink = $(this);
				
				hotlink.overlay({
					mask: '#000',
					effect: 'apple',											  
					fixed: false,
					// setup exposing when overlaying starts
					closeOnClick : false,
					onLoad : function(content) {			
						// alert("认证");
						// 先认证是否可以观看
			
						$.ajax({
							url : "JSONauthorityAction.action?fromAjax=ajax&runTime="
									+ Math.round(Math.random() * 10000),
							type : 'POST',
							dataType : 'json',
							async : false,
							success : function(data) {
								if (data.jsonAuthorityOK == "0") {
									// alert("认证失败");
									window.location.href = "authorityAction.action";
									return false;
								}
								if (data.jsonAuthorityOK == "10"
										|| data.jsonAuthorityOK == "11") {
									// alert("认证成功");
									// 计算费用
									// alert("计算费用"+link.attr("id"));
			
									$.ajax({
										url : "JSONcomputeVideoAction.action?fromAjax=ajax&sid="
													+ hotlink.attr("id") + "&runTime="
													+ Math.round(Math.random() * 10000),
										type : 'POST',
										dataType : 'json',
										async : false,
										success :	function(data) { //计费后开始播放视频，取得相关视频信息
										
												if(data.jsonMoneyEnough == "0")
												{
													alert("金额不足，无法观看视频！");
													return;
												}else
												{
													//alert("金额足，可以观看观看视频！");
												}
												//alert("金额验证完毕！");
												// 写入观看历史cookie start
												if (hotlink.attr("id") != null && hotlink.attr("id") != "") {
													if ($.cookie('wfvideohistory') == null) {
			
														$.cookie('wfvideohistory', hotlink
																		.attr("id"), {
																	expires : 7
																});
													} else {
														var sss = $
																.cookie('wfvideohistory');
														sss = sss + "_" + hotlink.attr("id");
			
														$.cookie('wfvideohistory', sss, {
																	expires : 7
																});
													}
												}
												// 写入观看历史cookie end
												// 下载客户端
												$("#downloadB").html('<a href="wanfangvideoPlugins.zip" target="_blank" ><img alt="下载客户端" src ="images/download.gif"/></a>');
												// 调用ajax填充数据 link.attr("id")
												// alert(link.attr("id"));
												// 根据ID取得相关数据放在 json中
												// 在此需要清空原有相关视频列表 start
												// 在此需要清空原有相关视频列表 end
												$("#ul_relativityVideo", $("#singleClipLayer")).empty();
												// $("#relativityVideo_info").html("数据");
												$.ajax({  //ajax方法取相关视频信息
													url : "JSONrelativityVideoSearch.action?sid="
															+ hotlink.attr("id")
															+ "&runTime="
															+ Math.round(Math.random()
																	* 10000),
													type : 'GET',
													dataType : 'json',
													async : false,
													success : function(data) {  //取回相关视频后的回调函数，把信息填入模板
														// alert("数量"+data.relativityVideoArray.length);
														// 单个视频信息的文字显示 start
														{
														$("#relativityVideo_info_title")
																.html(data.oneVideofilemanage.title);
														$("#relativityVideo_info_download")
																.html("<a href=\"download.action?sid="
																		+ hotlink.attr("id")
																		+ "\" target=\"_blank\" >下载视频</a>");
														$("#relativityVideo_info_outline")
																.html(data.oneVideofilemanage.outline);
														$("#relativityVideo_info_videoFileUpTime")
																.html("年代："
																		+ data.oneVideofilemanage.videoFileUpTime);
														$("#relativityVideo_info_dateTimeSize")
																.html("时长："
																		+ data.oneVideofilemanage.dateTimeSize);
														$("#relativityVideo_info_sourceName")
																.html("来源："
																		
																		+ data.oneVideofilemanage.sourceName1);
														$("#relativityVideo_info_className")
																.html("分类："
																		+ data.oneVideofilemanage.className);
														//alert(data.oneVideofilemanage.seriesCode);
														if(data.oneVideofilemanage.seriesCode=='XL01')
														{
															$("#relativityVideo_info_other").html("");
														}
														if(data.oneVideofilemanage.seriesCode=='XL02')
														{
															$("#relativityVideo_info_other")
															.html("主讲人:"+data.oneVideofilemanage.speaker);
														}
														if(data.oneVideofilemanage.seriesCode=='XL03')
														{
															$("#relativityVideo_info_other")
															.html("嘉宾:"+data.oneVideofilemanage.compere);
														}
														}
														// 单个视频信息的文字显示 end
														
														for (var i = 0; i < data.relativityVideoArray.length; i++) {
															var item = data.relativityVideoArray[i];
			
															// 克隆数据 循环生成相关视频 --start
															{
															var newLine = $("#relativityVideo_Row",$("#templates")).clone(true);																							 												// 为了让元素的事件处理也被传递，我们必须使用参数true。
			
															$(".fullinfo a#link", newLine).attr("href",
																			""+ item.sid_DegreeofAssociation+ ".wfv");
															//图片
															$(".fullinfo img.thumbnail", newLine)
															.attr("src","images/videoImages/"+ item.sid_DegreeofAssociation
																			+ ".jpg");
															
															$(".fullinfo a#link", newLine).attr("id",item.sid_DegreeofAssociation);
															$(".fullinfo .pic #IMGaddQlist",newLine).attr("onclick",
																			"favInsert('"
																					+ item.sid_DegreeofAssociation
																					+ "')");// 添加收藏小加号
															$("#innerShorttitle", newLine)
																	.text(item.className);
															$("#timesize", newLine)
																	.text(item.dateTimeSize);
															$("#shortt", newLine).text(item.shorttitle);
			
															newLine.attr("id","relativityVideo_Row_insert");// 改变绑定好数据的行的id
															newLine.appendTo($("#ul_relativityVideo",$("#singleClipLayer")));
															// 绑定播放事件
			
															// 克隆数据 循环生成相关视频 --end
															// $("#relativityVideo_Row").hide();//隐藏第一个模板层
															$('#relatedVaideoList',$("#singleClipLayer")).show();
																	
															$('#relatedVideoB', $("#singleClipLayer")).addClass("off");
															}
														}
														
														$("#ul_relativityVideo")
																.iniAddFaorite();// 添加收藏小加号
														// alert($("#singleClipLayer").html());
														$("#singleClipLayer").initSlideBehavior();
														$("#singleClipLayer").hightLightLi();
														if (data.relativityVideoArray.length == 0) {
															// alert("暂无相关视频！");
														}
														// alert(link.attr("href").indexOf(".wfv"));
														//alert("href=" +link.attr("href"));
														//alert("id=" +link.attr("id"));
														//自建视频处理
														{
														var customerVideoFlag ="";
														var customerVideoRootURL ="";
														var customerVideoFolder ="";
														var source ="";
														//提取视频信息，取得自建视频信息 start
														$.ajax({  //ajax方法取相关视频信息,检查是否是自建视频
															url : "JSONrelativityVideoSearch.action?sid="
																	+ hotlink.attr("id")
																	+ "&runTime="
																	+ Math.round(Math.random()
																			* 10000),
															type : 'GET',
															dataType : 'json',
															async : false,
															success : function(data) {  //取回相关视频后的回调函数，把信息填入模板
																// alert("数量"+data.relativityVideoArray.length);
																// 单个视频信息的文字显示 start					
																customerVideoFlag = data.oneVideofilemanage.customerVideoFlag +"";
																customerVideoRootURL = data.oneVideofilemanage.customerVideoRootURL;
																customerVideoFolder = data.oneVideofilemanage.customerVideoFolder;
																source = data.oneVideofilemanage.source;
																// 单个视频信息的文字显示 end
											
															}
														});
														
														//提取视频信息，取得自建视频信息 end
														//alert("同步");
														//alert(customerVideoFlag);
														var clip = null;
														if (customerVideoFlag == null ||customerVideoFlag == "" || customerVideoFlag == "W") {
															// wfv格式
															//alert("WFV");
															//alert("http://127.0.0.1:8077/" + link.attr("id") + ".wfv");
															clip = {
																type : "video",
																file : "http://127.0.0.1:8077/" + source + "/" + hotlink.attr("id") + ".wfv",
																title : "Someone else's Cool Video"
															};
															
														} // 自建视频
														 else {																
															clip = {
																type : "video",
																file : customerVideoRootURL + customerVideoFolder + hotlink.attr("id") + ".flv",
																title : "Someone else's Cool Video"
															};
														}
														
														}
														
														// player.sendEvent('LOAD',
														// "http://127.0.0.1:8077/"+link.attr("href"));
														//alert("开始播放");
														playClip(singleClipPlayer,clip);
														// player.play(link.attr("href"));
											
														
														//相关视及信息框频滑动动画处理
														{
														//打开信息框，设定按钮状态
														$('#information', $("#singleClipLayer")).show();
														$('#infoB', $("#singleClipLayer")).addClass("off");
											
														
														var t1 = null;
														var t2 = null;
														$('#relatedVaideoList:visible', $("#singleClipLayer")).mouseover(
																function() {
																	clearTimeout(t1); // 如果鼠标在相关视频列表上，则不再自动收起
																});
											
														$('#information', $("#singleClipLayer")).mouseover(function() {
																	clearTimeout(t2); // 如果鼠标在视频信息框上，则不再自动收起
																});
														t1 = setTimeout(function() {
																	$('#relatedVaideoList:visible', $("#singleClipLayer"))
																			.slideLeft('slow');
																	$('#relatedVideoB', $("#singleClipLayer")).removeClass("off");
																}, 30000); // 相关视频过2秒后自动收起
											
														t2 = setTimeout(function() {
																	$('#information', $("#singleClipLayer")).slideUp('slow');
																	$('#infoB', $("#singleClipLayer")).removeClass("off");
																}, 30000); // 视频信息过2秒后自动收起
														
														}
													}
												});													
											}
											
									});
			
								}
							}
						});
						
						
			
					},
					onBeforeClose : function() {
						
						//退出蒙板层前收起信息框和相关视频框的滑动动画处理
						if ($('#relatedVaideoList', $("#singleClipLayer")).is(':visible')) {
							$('#relatedVaideoList', $("#singleClipLayer")).slideLeft('slow',
									function() {
										if ($('#information', $("#singleClipLayer"))
												.is(':visible')) {
											$('#information', $("#singleClipLayer")).slideUp(
													'slow', function() {
														if (singleClipPlayer && singleClipPlayer.sendEvent )
															singleClipPlayer.sendEvent('STOP');

												});
										} else {
											if (singleClipPlayer && singleClipPlayer.sendEvent )
												singleClipPlayer.sendEvent('STOP');

										}
									});
						} else {
							if ($('#information', $("#singleClipLayer")).is(':visible')) {
								$('#information', $("#singleClipLayer")).slideUp('slow',
										function() {
											if (singleClipPlayer && singleClipPlayer.sendEvent )
												singleClipPlayer.sendEvent('STOP');

									});
							} else {
								if (singleClipPlayer && singleClipPlayer.sendEvent )
									singleClipPlayer.sendEvent('STOP');

							}
						}
						//return false;
					},
					// cloase exposing , unload our player
					onClose : function() {
						
						if ($('#relatedVaideoList', $("#singleClipLayer")).is(':visible')) {
							$('#relatedVaideoList', $("#singleClipLayer")).hide();
						}
						$('#relatedVideoB', $("#singleClipLayer")).removeClass("off");
						
						if ($('#information', $("#singleClipLayer")).is(':visible')) {
							$('#information', $("#singleClipLayer")).hide();
						}
						$('#infoB', $("#singleClipLayer")).removeClass("off");
						if (singleClipPlayer && singleClipPlayer.sendEvent )
							singleClipPlayer.sendEvent('STOP');
						// player.unload();
						//$.expose.close();
					}
				});
				});
	
	/*$("a[rel='#singleClipLayer']", videoList).overlay({
		mask: '#000',
		effect: 'apple',											  
		fixed: false,
		// setup exposing when overlaying starts
		closeOnClick : false,
		onLoad : function(content) {			
			// alert("认证");
			// 先认证是否可以观看

			$.ajax({
				url : "JSONauthorityAction.action?fromAjax=ajax&runTime="
						+ Math.round(Math.random() * 10000),
				type : 'POST',
				dataType : 'json',
				async : false,
				success : function(data) {
					if (data.jsonAuthorityOK == "0") {
						// alert("认证失败");
						window.location.href = "authorityAction.action";
						return false;
					}
					if (data.jsonAuthorityOK == "10"
							|| data.jsonAuthorityOK == "11") {
						// alert("认证成功");
						// 计算费用
						// alert("计算费用"+link.attr("id"));

						$.ajax({
							url : "JSONcomputeVideoAction.action?fromAjax=ajax&sid="
										+ hotlink.attr("id") + "&runTime="
										+ Math.round(Math.random() * 10000),
							type : 'POST',
							dataType : 'json',
							async : false,
							success :	function(data) { //计费后开始播放视频，取得相关视频信息
							
									if(data.jsonMoneyEnough == "0")
									{
										alert("金额不足，无法观看视频！");
										return;
									}else
									{
										//alert("金额足，可以观看观看视频！");
									}
									//alert("金额验证完毕！");
									// 写入观看历史cookie start
									if (hotlink.attr("id") != null && hotlink.attr("id") != "") {
										if ($.cookie('wfvideohistory') == null) {

											$.cookie('wfvideohistory', hotlink
															.attr("id"), {
														expires : 7
													});
										} else {
											var sss = $
													.cookie('wfvideohistory');
											sss = sss + "_" + hotlink.attr("id");

											$.cookie('wfvideohistory', sss, {
														expires : 7
													});
										}
									}
									// 写入观看历史cookie end
									// 下载客户端
									$("#downloadB").html('<a href="wanfangvideoPlugins.zip" target="_blank" ><img alt="下载客户端" src ="images/download.gif"/></a>');
									// 调用ajax填充数据 link.attr("id")
									// alert(link.attr("id"));
									// 根据ID取得相关数据放在 json中
									// 在此需要清空原有相关视频列表 start
									// 在此需要清空原有相关视频列表 end
									$("#ul_relativityVideo", $("#singleClipLayer")).empty();
									// $("#relativityVideo_info").html("数据");
									$.ajax({  //ajax方法取相关视频信息
										url : "JSONrelativityVideoSearch.action?sid="
												+ hotlink.attr("id")
												+ "&runTime="
												+ Math.round(Math.random()
														* 10000),
										type : 'GET',
										dataType : 'json',
										async : false,
										success : function(data) {  //取回相关视频后的回调函数，把信息填入模板
											// alert("数量"+data.relativityVideoArray.length);
											// 单个视频信息的文字显示 start
											{
											$("#relativityVideo_info_title")
													.html(data.oneVideofilemanage.title);
											$("#relativityVideo_info_download")
													.html("<a href=\"download.action?sid="
															+ hotlink.attr("id")
															+ "\" target=\"_blank\" >下载视频</a>");
											$("#relativityVideo_info_outline")
													.html(data.oneVideofilemanage.outline);
											$("#relativityVideo_info_videoFileUpTime")
													.html("年代："
															+ data.oneVideofilemanage.videoFileUpTime);
											$("#relativityVideo_info_dateTimeSize")
													.html("时长："
															+ data.oneVideofilemanage.dateTimeSize);
											$("#relativityVideo_info_sourceName")
													.html("来源："
															
															+ data.oneVideofilemanage.sourceName1);
											$("#relativityVideo_info_className")
													.html("分类："
															+ data.oneVideofilemanage.className);
											//alert(data.oneVideofilemanage.seriesCode);
											if(data.oneVideofilemanage.seriesCode=='XL01')
											{
												$("#relativityVideo_info_other").html("");
											}
											if(data.oneVideofilemanage.seriesCode=='XL02')
											{
												$("#relativityVideo_info_other")
												.html("主讲人:"+data.oneVideofilemanage.speaker);
											}
											if(data.oneVideofilemanage.seriesCode=='XL03')
											{
												$("#relativityVideo_info_other")
												.html("嘉宾:"+data.oneVideofilemanage.compere);
											}
											}
											// 单个视频信息的文字显示 end
											
											for (var i = 0; i < data.relativityVideoArray.length; i++) {
												var item = data.relativityVideoArray[i];

												// 克隆数据 循环生成相关视频 --start
												{
												var newLine = $("#relativityVideo_Row",$("#templates")).clone(true);																							 												// 为了让元素的事件处理也被传递，我们必须使用参数true。

												$(".fullinfo a#link", newLine).attr("href",
																""+ item.sid_DegreeofAssociation+ ".wfv");
												//图片
												$(".fullinfo img.thumbnail", newLine)
												.attr("src","images/videoImages/"+ item.sid_DegreeofAssociation
																+ ".jpg");
												
												$(".fullinfo a#link", newLine).attr("id",item.sid_DegreeofAssociation);
												$(".fullinfo .pic #IMGaddQlist",newLine).attr("onclick",
																"favInsert('"
																		+ item.sid_DegreeofAssociation
																		+ "')");// 添加收藏小加号
												$("#innerShorttitle", newLine)
														.text(item.className);
												$("#timesize", newLine)
														.text(item.dateTimeSize);
												$("#shortt", newLine).text(item.shorttitle);

												newLine.attr("id","relativityVideo_Row_insert");// 改变绑定好数据的行的id
												newLine.appendTo($("#ul_relativityVideo",$("#singleClipLayer")));
												// 绑定播放事件

												// 克隆数据 循环生成相关视频 --end
												// $("#relativityVideo_Row").hide();//隐藏第一个模板层
												$('#relatedVaideoList',$("#singleClipLayer")).show();
														
												$('#relatedVideoB', $("#singleClipLayer")).addClass("off");
												}
											}
											
											$("#ul_relativityVideo")
													.iniAddFaorite();// 添加收藏小加号
											// alert($("#singleClipLayer").html());
											$("#singleClipLayer").initSlideBehavior();
											$("#singleClipLayer").hightLightLi();
											if (data.relativityVideoArray.length == 0) {
												// alert("暂无相关视频！");
											}
											// alert(link.attr("href").indexOf(".wfv"));
											//alert("href=" +link.attr("href"));
											//alert("id=" +link.attr("id"));
											//自建视频处理
											{
											var customerVideoFlag ="";
											var customerVideoRootURL ="";
											var customerVideoFolder ="";
											var source ="";
											//提取视频信息，取得自建视频信息 start
											$.ajax({  //ajax方法取相关视频信息,检查是否是自建视频
												url : "JSONrelativityVideoSearch.action?sid="
														+ hotlink.attr("id")
														+ "&runTime="
														+ Math.round(Math.random()
																* 10000),
												type : 'GET',
												dataType : 'json',
												async : false,
												success : function(data) {  //取回相关视频后的回调函数，把信息填入模板
													// alert("数量"+data.relativityVideoArray.length);
													// 单个视频信息的文字显示 start					
													customerVideoFlag = data.oneVideofilemanage.customerVideoFlag +"";
													customerVideoRootURL = data.oneVideofilemanage.customerVideoRootURL;
													customerVideoFolder = data.oneVideofilemanage.customerVideoFolder;
													source = data.oneVideofilemanage.source;
													// 单个视频信息的文字显示 end
								
												}
											});
											
											//提取视频信息，取得自建视频信息 end
											//alert("同步");
											//alert(customerVideoFlag);
											var clip = null;
											if (customerVideoFlag == null ||customerVideoFlag == "" || customerVideoFlag == "W") {
												// wfv格式
												//alert("WFV");
												//alert("http://127.0.0.1:8077/" + link.attr("id") + ".wfv");
												clip = {
													type : "video",
													file : "http://127.0.0.1:8077/" + source + "/" + hotlink.attr("id") + ".wfv",
													title : "Someone else's Cool Video"
												};
												
											} // 自建视频
											 else {																
												clip = {
													type : "video",
													file : customerVideoRootURL + customerVideoFolder + hotlink.attr("id") + ".flv",
													title : "Someone else's Cool Video"
												};
											}
											
											}
											
											// player.sendEvent('LOAD',
											// "http://127.0.0.1:8077/"+link.attr("href"));
											//alert("开始播放");
											playClip(singleClipPlayer,clip);
											// player.play(link.attr("href"));
								
											
											//相关视及信息框频滑动动画处理
											{
											//打开信息框，设定按钮状态
											$('#information', $("#singleClipLayer")).show();
											$('#infoB', $("#singleClipLayer")).addClass("off");
								
											
											var t1 = null;
											var t2 = null;
											$('#relatedVaideoList:visible', $("#singleClipLayer")).mouseover(
													function() {
														clearTimeout(t1); // 如果鼠标在相关视频列表上，则不再自动收起
													});
								
											$('#information', $("#singleClipLayer")).mouseover(function() {
														clearTimeout(t2); // 如果鼠标在视频信息框上，则不再自动收起
													});
											t1 = setTimeout(function() {
														$('#relatedVaideoList:visible', $("#singleClipLayer"))
																.slideLeft('slow');
														$('#relatedVideoB', $("#singleClipLayer")).removeClass("off");
													}, 30000); // 相关视频过2秒后自动收起
								
											t2 = setTimeout(function() {
														$('#information', $("#singleClipLayer")).slideUp('slow');
														$('#infoB', $("#singleClipLayer")).removeClass("off");
													}, 30000); // 视频信息过2秒后自动收起
											
											}
										}
									});													
								}
								
						});

					}
				}
			});
			
			

		},
		onBeforeClose : function() {
			
			//退出蒙板层前收起信息框和相关视频框的滑动动画处理
			if ($('#relatedVaideoList', $("#singleClipLayer")).is(':visible')) {
				$('#relatedVaideoList', $("#singleClipLayer")).slideLeft('slow',
						function() {
							if ($('#information', $("#singleClipLayer"))
									.is(':visible')) {
								$('#information', $("#singleClipLayer")).slideUp(
										'slow', function() {
											//singleClipPlayer.sendEvent('STOP');
											// player.unload();
											//$.expose.close();
											// this.finalClose();
									});
							} else {
								//singleClipPlayer.sendEvent('STOP');
								// player.unload();
								//$.expose.close();
								// this.finalClose();
							}
						});
			} else {
				if ($('#information', $("#singleClipLayer")).is(':visible')) {
					$('#information', $("#singleClipLayer")).slideUp('slow',
							function() {
						//singleClipPlayer.sendEvent('STOP');
								// player.unload();
								//$.expose.close();
								// this.finalClose();
						});
				} else {
					//singleClipPlayer.sendEvent('STOP');
					// player.unload();
					//$.expose.close();
					// this.finalClose();
				}
			}
			//return false;
		},
		// cloase exposing , unload our player
		onClose : function() {
			
			if ($('#relatedVaideoList', $("#singleClipLayer")).is(':visible')) {
				$('#relatedVaideoList', $("#singleClipLayer")).hide();
			}
			$('#relatedVideoB', $("#singleClipLayer")).removeClass("off");
			
			if ($('#information', $("#singleClipLayer")).is(':visible')) {
				$('#information', $("#singleClipLayer")).hide();
			}
			$('#infoB', $("#singleClipLayer")).removeClass("off");
			//singleClipPlayer.sendEvent('STOP');
			// player.unload();
			//$.expose.close();
		}
	});*/

}

function hide(obj){
		obj.hide();
		obj.addClass("off");
}

function show(obj){
		obj.show();
		obj.removeClass("off");
}

// 浮现加号 +入我的视频播放列表
// sid：相应需要加入的视频ID
function favInsert(sid) {
	var videoCode = sid;

	// 先判断用户是否已经登录
	$.ajax({
				url : "JSONauthorityAction.action?sid="+videoCode+"&fromAjax=ajax&runTime="
						+ Math.round(Math.random() * 10000),
				type : 'GET',
				dataType : 'json',
				async : false,
				success : function(data) {
					if (data.jsonAuthorityOK == "0") {
						window.location.href = "authorityAction.action";
						return false;
					} else if (data.jsonAuthorityOK == "10") {
						
						window.location.href = "authorityActionEmail.action?sid="+videoCode;
						return false;
					} else {
						$.getJSON("JSONfavInsert.action?videoCode=" + videoCode
										+ "&runTime="
										+ Math.round(Math.random() * 10000),
								function(data) {
									
									if (data.status != true && data.notIn != true) {
										$.jGrowl("该视频已收藏过!", {
													position : 'center'
												});// 弹出加入不成功信息
									} 
									else if (data.status != true && data.notIn == true) {
										$.jGrowl("视频最多可以收藏18个，您已经收藏满！", {
													position : 'center'
												});// 弹出加入不成功信息
									} 
									else {
										$.jGrowl("视频收藏成功!", {
													position : 'center'
												});
									}
									return false;
								});
					}

				}
			});

}

// 绑定弹出层按钮效果
var initMylayerFunction = function() {
	$('#relatedVideoB').click(function() {
				var self = $(this);
				if ($('#relatedVaideoList').is(':visible')) {
					$('#relatedVaideoList').slideLeft('slow', function() {
								self.removeClass("off");
							});
				} else {
					$('#relatedVaideoList').slideRight('slow', function() {
								self.addClass("off");
							});
				}
			});
	$('#infoB').click(function() {
				var self = $(this);
				$('#information').slideToggle('slow', function() {
							if (self.hasClass("off"))
								self.removeClass("off");
							else
								self.addClass("off");
						});
			});

	$("#templates .video_list li a").click(function() {
		// play the clip specified in href- attribute with

		// alert("计算费用相关视频"+$(this).attr("id"));
		// alert("认证成功");
		// 计算费用
		var jsonMoneyEnough = "0";
//		$.getJSON("JSONcomputeVideoAction.action?fromAjax=ajax&sid="
//						+ $(this).attr("id") + "&runTime="
//						+ Math.round(Math.random() * 10000), function(data) {
//							
//							if(data.jsonMoneyEnough == "0")
//							{
//								jsonMoneyEnough = data.jsonMoneyEnough;
//								//alert("金额不足，无法观看视频！");
//								//return;
//							}else
//							{
//								jsonMoneyEnough = data.jsonMoneyEnough;
//								//alert("金额足，可以观看观看视频！");
//							}
//				});
		//改成同步，下面要用结果
		$.ajax({
			url : "JSONcomputeVideoAction.action?fromAjax=ajax&sid="
				+ $(this).attr("id") + "&runTime="
				+ Math.round(Math.random() * 10000),
			type : 'GET',
			dataType : 'json',
			async : false,
			success : function(data) {
				jsonMoneyEnough = data.jsonMoneyEnough;
			}
		});
		// alert(2);
		// 刷新文字
		
		var thisLink = $(this);
		$.ajax({
					url : "JSONrelativityVideoSearch.action?sid="
							+ $(this).attr("id") + "&runTime="
							+ Math.round(Math.random() * 10000),
					type : 'GET',
					dataType : 'json',
					async : false,
					success : function(data) {
						// alert("数量"+data.relativityVideoArray.length);
						// 单个视频信息的文字显示 start
						$("#relativityVideo_info_title")
								.html(data.oneVideofilemanage.title);
						$("#relativityVideo_info_download")
								.html("<a href=\"download.action?sid="
										+ thisLink.attr("id")
										+ "\" target=\"_blank\" >下载视频</a>");
						$("#relativityVideo_info_outline")
								.html(data.oneVideofilemanage.outline);
						$("#relativityVideo_info_videoFileUpTime").html("年代："
								+ data.oneVideofilemanage.videoFileUpTime);
						$("#relativityVideo_info_dateTimeSize").html("时长："
								+ data.oneVideofilemanage.dateTimeSize);
						$("#relativityVideo_info_sourceName").html("来源："
								
								+ data.oneVideofilemanage.sourceName1);
						$("#relativityVideo_info_className").html("分类："
								+ data.oneVideofilemanage.className);
						// 单个视频信息的文字显示 end
						if(data.oneVideofilemanage.seriesCode=='XL01')
											{
												$("#relativityVideo_info_other")
												.html("");
											}
											if(data.oneVideofilemanage.seriesCode=='XL02')
											{
												$("#relativityVideo_info_other")
												.html("主讲人:"+data.oneVideofilemanage.speaker);
											}
											if(data.oneVideofilemanage.seriesCode=='XL03')
											{
												$("#relativityVideo_info_other")
												.html("嘉宾:"+data.oneVideofilemanage.compere);
											}
					}
					
				});

		var customerVideoFlag ="";
		var customerVideoRootURL ="";
		var customerVideoFolder ="";
		var source ="";
		//提取视频信息，取得自建视频信息 start
		$.ajax({  //ajax方法取相关视频信息,检查是否是自建视频
			url : "JSONrelativityVideoSearch.action?sid="
					+ $(this).attr("id")
					+ "&runTime="
					+ Math.round(Math.random()
							* 10000),
			type : 'GET',
			dataType : 'json',
			async : false,
			success : function(data) {  //取回相关视频后的回调函数，把信息填入模板
				// alert("数量"+data.relativityVideoArray.length);
				// 单个视频信息的文字显示 start					
				customerVideoFlag = data.oneVideofilemanage.customerVideoFlag +"";
				customerVideoRootURL = data.oneVideofilemanage.customerVideoRootURL;
				customerVideoFolder = data.oneVideofilemanage.customerVideoFolder;
				source = data.oneVideofilemanage.source;
				
				// 单个视频信息的文字显示 end

			}
		});		
		//提取视频信息，取得自建视频信息 end
		//alert("同步");
		//alert(customerVideoFlag);
		var clip = null;
		if (customerVideoFlag == null ||customerVideoFlag == "" || customerVideoFlag == "W") {
			// wfv格式
			clip = {
				type : "video",
				file : "http://127.0.0.1:8077/" + source + "/" + $(this).attr("id")+ ".wfv",
				title : "Someone else's Cool Video"
			};
		} else {
			// 自建视频
			clip = {
					type : "video",
					file : customerVideoRootURL + customerVideoFolder + $(this).attr("id") + ".flv",
					title : "Someone else's Cool Video"
				};
		}
		// player.sendEvent('LOAD', "http://127.0.0.1:8077/"+link.attr("href"));
		//alert("jsonMoneyEnough = "+jsonMoneyEnough);
		if(jsonMoneyEnough == "1")
		{
			//alert("开始播放");
		if (singleClipPlayer && singleClipPlayer.sendEvent)
			singleClipPlayer.sendEvent('LOAD', clip);
		else {
			setTimeout(function() {
						singleClipPlayer.sendEvent('LOAD', clip);
					}, 200);
		}
		}else{alert("余额不足，无法播放！");};
		// player.play($(this).attr("href"));
		// by returning false normal link behaviour is skipped
		return false;
	});

}

jQuery.fn.hightLightLi = function() {
	$("li", $(this)).hover(function() {
				$(this).addClass("highLight")
			}, function() {
				$(this).removeClass("highLight")
			});
}

// 初始化侧边列表滑动效果
jQuery.fn.initSlideBehavior = function() {

	var liHandle = $(".video_list li.normal", $(this));

	var t = null;

	liHandle.hover(function() {
				thisLi = $(this);
				t = setTimeout(function() {

							$(".fullinfo:visible", liHandle.not(thisLi))
									.animate({
												height : "hide"
											}, "slow");
							$(".fullinfo:hidden", thisLi).animate({
										height : "show"
									}, "slow",function(){
									$(this).css("visibility","hidden");
									
									$(this).css("visibility","visible");
									//alert($(this).css("visibility"));
									});		
						}, 200);

			}, function() {
				clearTimeout(t);
			});

	$(".fullinfo", $(".video_list li.normal", $(this)).not(":first")).hide(); // 打开第一条目
}

var inputTipText = function() {
	$("input[class*=grayTips]") // 所有样式名中含有grayTips的input
			.each(function() {
						var oldVal = $(this).val(); // 默认的提示性文本
						$(this).css({
									"color" : "#888"
								}) // 灰色
								.focus(function() {
											if ($(this).val() != oldVal) {
												$(this).css({
															"color" : "#000"
														})
											} else {
												$(this).val("").css({
															"color" : "#888"
														})
											}
										}).blur(function() {
											if ($(this).val() == "") {
												$(this).val(oldVal).css({
															"color" : "#888"
														})
											}
										}).keydown(function() {
											$(this).css({
														"color" : "#000"
													})
										})
					})
}

jQuery.fn.iniAddFaorite = function() {

	$("li", $(this)).each(function() {
		var liHandle = $(this);
		var isOut = false; // 防止由于网络延时导致加号显示时鼠标已经移出所用的标准位
		$("div.pic", liHandle).hover(function() {
			// 获取被选中的ID
			var videoCode = $("div.pic a", liHandle).attr("id");
			isOut = false; // 鼠标移入时，设定移出状态为false
			$.getJSON("JSONtrueOrfalse.action?videoCode=" + videoCode
							+ "&runTime=" + Math.round(Math.random() * 10000),
					function(data) {
						// 判断是否显示加号
						if (!isOut) {// 当没有添加过切鼠标没有移出时显示
							$("img.addQlist", liHandle).show();
							if (!data.status) {
								$("img.addQlist", liHandle)
										.addClass("addQlist_off");
							}
						}
					});

		}, function() {
			$("img.addQlist", liHandle).hide();
			$("img.addQlist", liHandle).removeClass("addQlist_off");
			isOut = true; // 鼠标移出时，设定移出状态为true
		});
	});
}

$(document).ready(function() {
			iniPlayer();
			initMylayerFunction();
			$("#hotVideo").initSlideBehavior();
			$(".video_list").hightLightLi();
			$("a",$("#lessonTab")).each(function () {
					$(this).click(function(){return false;});												 
					$(this).hover(function(){
						$("#lessonTab a").removeClass('active');
						$(this).addClass("active");
						$("#lessonList,#lessonIntroduce,#techerIntroduce").hide();
						$("#"+$(this).attr('rel')).show();
						return false;
					 })
			});

			$("#teacherSwitcher").click(function(){									
					$("#maskWindow").toggleClass("maskWindowPic");
					$("div",$(this)).toggleClass("videoOff");
			})
			// iniAddFaorite();
			inputTipText();
		})
		
//回车自动提交form
if(window.document.all != null)
{
	//IE
	window.document.attachEvent("onkeydown", function(){
		if(window.event.keyCode == 13){
			var submit = document.getElementById("searchbtn");
			submit.focus();
			//另一种激活的方法
			//submit.fireEvent("onclick");
			//注：fireEvent不能与focus共存，否则提交两次	
		}	
	});
}

function keysubmit(evt){
    evt = (evt) ? evt : ((window.event) ? window.event : "") //兼容IE和Firefox获得keyBoardEvent对象
    var key = evt.keyCode?evt.keyCode:evt.which; //兼容IE和Firefox获得keyBoardEvent对象的键值
    if(key == 13){ //同时按下了Ctrl和回车键
        var submit = document.getElementById("searchbtn");
		submit.focus();
    }
}



		