/**
 * <code>
 * cache中的数据:
 * _ldtId_ :  	{	type : type, //文本显示类型 0=直接显示,1=加载显示
 * 			   		msg : ldtMessage//0时:显示的内容文本,1=查询的参数
 * 				};
 * 
 * 
 * </code>
 */

// playv(nodeId) 播放视频的方法
// opXml();处理xml
// opVideo
// loadTimes
// _c2(ri);更新点击次数
$.fn.kyStudio = function(opts) {

	opts = $.extend({
				waterMark : '',/* 水印 */
				pcode : '',
				width : 710,
				height : 380,
				showByLayer : false,/* 是否在层中显示 */
				theRenderElementId : '',/* 进行渲染的空气 */
				userId : 0,
				/** 用户的id,用来记录点击 */
				callback : function() {
				}
			}, opts || {});

	// var pages = new Array();
	// var synchronization = function(page) {
	// for (var i = 0; i < pages.length; i++) {
	// var tmp = pages[i];
	// tmp.synchronization(page);
	// }
	// }

	return this.each(function() {
		// 节点的字体大小样式
		var nodeTxtFontSizeStyle;
		var imagePath = '/keyajs/jquery/plugin/tree/images/1/';
		// 播放列表的图标
		var iconPathPlayList;
		// 播放列表的锁定图标
		var iconPathPlayListLock;

		// 视频图标_锁定
		// treepath = '/keyajs/jquery/plugin/tree/images/123.gif';
		// treepath = '/keyaimages/firepower/index/lock3.gif';// circle.gif
		var IconPathVideoNormal;

		// 视频图标_可以观看
		// treepath = '/keyajs/jquery/plugin/tree/images/1/film.png';
		var IconPathVideoLock;

		// 根节点图标
		var rootIcon;

		rootIcon = imagePath + 'monitor_go.png';

		iconPathPlayListLock = imagePath + 'page_lock.gif';

		iconPathPlayList = imagePath + 'control_play_blue.png';
		IconPathVideoNormal = imagePath + 'page_white_flash.png';
		IconPathVideoLock = imagePath + 'lock.png';

		iconPathPlayList = imagePath + 'action_go.gif';
		IconPathVideoLock = imagePath + 'page_lock.gif';
		IconPathVideoNormal = imagePath + 'application_flash.gif';

		IconPathVideoLock = '/keyaimages/firepower/index/lock3.gif';
		IconPathVideoNormal = imagePath + "film.png";
		//		
		//		
		//		

		/**
		 * 请求的url的地址
		 */
		var r_url = contextPath + "/app/studio/";
		/**
		 * 
		 * var _cc = {<br>
		 * pid : pid,//flash 的pid或者code<br>
		 * sp : sp,//flash 的提供商0=使用pid的code代码,1=通用,2=56<br>
		 * desc : desc,//视频的描述<br>
		 * t : n,// title<br>
		 * ri : ri,//runtimeRelationId<br>
		 * l : lock,// 描述是否锁定<br>
		 * vDate : ''// 查看时间<br>
		 * <br>
		 * <br> };
		 */

		/**
		 * 
		 * 需要外部进行设定的对象:
		 * <ul>
		 * <li>width=""</li>
		 * </ul>
		 * 
		 * @type
		 */

		/**
		 * 树对象
		 * 
		 * @type
		 */
		var _tree;
		/**
		 * 放置出现重复id,这个创建一个 元素id的前缀!
		 * 
		 * @type String
		 */
		var studioId;

		/**
		 * flash的宽度
		 * 
		 * @type Number
		 */
		var _flashWidth = 480;
		/**
		 * flash的高度
		 * 
		 * @type Number
		 */
		var _flashHeight = 360;

		// 隐藏 水印的 左右滚动
		var hiddenAttr_4_hidMarquee = '0';
		function gid(id) {
			return studioId + '_' + id;
		}
		/**
		 * 播放器的界面相关属性
		 * 
		 * @type
		 */
		var _plc = {};

		var __studio_cacheElementId = '__studio_cacheElementId';
		function _cacheGet(key) {
			if (isEmpty(key)) {
				return "";
			}
			var $c = getS(__studio_cacheElementId);
			return $c.data(key);
		}
		/**
		 * 把data数据放到缓存中!前提,需要在页面中,提供 一个div id是"_div_cache"
		 * 
		 * 代码为:<div id="__div_cache_" />
		 * 
		 * @param {String}
		 *            key
		 * @param {Object}
		 *            data ,字符或者json数组等
		 */
		function _cachePut(key, data) {
			var $c = getS(__studio_cacheElementId);
			$c.data(key, data);
		}
		/**
		 * 初始化演播厅的 页面dom
		 */
		function initDOM() {
			var div = [
					'<div id="' + gid('studio_layer') + '" class="'
							+ gid('studio2') + '">',
					'	<div id="' + gid('studio2_main') + '" class="'
							+ gid('studio2_main') + '">',

					'		<div class="' + gid('studio2_main1') + '" id="'
							+ gid('studio_playlist')
							+ '"><ul class="simpleTree" id="'
							+ gid('_playListTree') + '"></ul></div>',
					'		<div class="' + gid('studio2_main2') + '">',
					'			<div id="' + gid('studio_flash') + '" class="'
							+ gid('studio2_main2_movie') + '">',
					'				<div class="' + gid("flash") + '" id="'//
							+ gid('v_dv_player') + '">',

					'					<div class="studio_watermark" id="'
							+ gid('_div_watermark') + '">',
					'						<marquee id="' + gid('_div_watermark2')
							+ '" width="100%" scrollamount="1"/></div>',
					'				</div>',
					'			</div>', //
					'		</div>',//
					'		<div style="height: 0; overflow: hidden;"></div>',
					'		<div class="clear"></div>',
					'	</div>',
					'	<div id="' + gid('studio_desc') + '" class="'
							+ gid('studio2_tag') + '"></div>',// 
					'</div>'];
			var txt = div.join('');

			var target = opts.theRenderElementId;
			if (exist(target)) {// 如果存在,就在下面创建,
				$("#" + target).html(txt);
			} else {
				$(document.body).append(txt);
			}
		}

		/**
		 * 演播厅时候已经初始化了 true:初始化了,false没有
		 */
		function isInitThis() {

		}
		/** 水印的id */
		var _watermark_id = "";
		function _initStudio() {
			// 判断缓存标签是否存在,不存在就创建

			studioId = opts.studioId;// 'st_' + randomInt(10, 1000);
			if (isdebug()) {
				log('studioId==' + studioId);
			}
			// getS(opts.theRenderElementId).html("<div/>")
			var isInti = _cacheGet('_studio_is_init');

			if (!isInti) {// 演播厅时候已经初始化了

				// 水印id
				_watermark_id = gid('_watermark_id');
				_cachePut('_studio_is_init', true);
				// initCss();

				// 清空之前的dom

				// if( !exist('studio_layer')){

				// 初始化dom
				initDOM();
				// 初始化页面宽度
				initWidth();
			}
			// }

			/* 抽奖用户历史 */
			loadXml();

			// $("#_test_phprpc").bind("click", loadTimes);
			// $("#_test_phprpc").bind("click", function() {
			// loadTimes(opts.pcode);
			// });
			_initTimer();
		}

		/**
		 * 对加密的数据进行解密
		 * 
		 * @param {}
		 *            b64
		 * @return {解码后的字符}
		 */
		function _mc(b64) {

			var tmp = $.trim(b64);

			// return b64;
			var result = "";
			try {
				var k = [];
				k[0] = 'k';
				k[1] = 'y';
				k[2] = 'y';
				k[3] = 'x';
				var m_key = k.join('');

				// 进行base64解码
				var data = atob(tmp);

				var de = XXTEA.decrypt(data, m_key);

				result = de.toUTF16();
			} catch (e) {
				showErr(e);
			}
			return result;

		}
		/**
		 * 初始化node节点
		 * 
		 * @param {String}是否隐藏tooltip,1=隐藏
		 */
		function initTree(hiddenAttr_1_hidToolTip, hiddenAttr_5_hidRoot) {
			var param = {
				autoclose : false,
				drag : false,
				url : null,
				hiddenRoot : '1' == hiddenAttr_5_hidRoot,
				dataType : "html",

				afterClick : function(node) {
					// console.profile();
					// console.dir(node);
					// logTrace();
					// console.dirxml(document.getElementById('_playListTree'));
					// log( typeof node[0]);
					var obj = $('div:first', node);

					var nodeId = node.attr('id');
					// log(nodeId);
					playv(nodeId);
				},
				afterDblClick : function(node) {
					// log("afterDblClick:text-" + $('div:first',
					// node).text());
				},
				afterMove : function(destination, source, pos) {
					/**
					 * alert("destination-"+destination.attr('id')+"
					 * source-"+source.attr('id')+" pos-"+pos);
					 */
				},
				afterAjax : function() {
					/** alert('Loaded'); */
				},
				animate : true,
				getFolderClass : function(nodeId) {
					// TODO 判断这个node节点是否具有相应节点即可
					// if (nodeId == 'pl_2_2')
					// return "doc_lock";
					// return "lock-";

				},
				getNodeClass : function(nodeId) {
					// if (nodeId == 'pl_2_2')
					// return "doc";
					// return null;"folder-";
					// return "lock-";
				}
				/** ,docToFolderConvert:true */

			};
			try{
			_tree = $('#' + gid('_playListTree')).simpleTree(param);

			// 展开节点
			_tree.get(0).expandAll();

			// 判断是否隐藏 tooltip
			if (hiddenAttr_1_hidToolTip == '0') {
				// 初始化tooltip
				$("#" + gid("studio_playlist") + " div").bt({
					// contentSelector : "tree_tootip($(this))",
					contentSelector : tree_tootip,
					hoverIntentOpts : {
						/** 等待多久 */
						interval : 500,
						timeout : 1500
						/* 描述多久之后不再显示,之前是200,现在改为2描述,便于用户能够点击tootip */
					},

					positions : ['right', 'left'],
					fill : '#F4F4F4',
					strokeStyle : '#666666',
					spikeLength : 20,
					spikeGirth : 10,
					width : 300,
					overlap : 0,
					centerPointY : 1,
					cornerRadius : 0,
					cssStyles : {
						fontFamily : '"Lucida Grande",Helvetica,Arial,Verdana,sans-serif',
						fontSize : '12px',
						padding : '10px 14px',
						// height : '250px',
						overflow : 'auto'
					},
					shadow : true,
					shadowColor : 'rgba(0,0,0,.5)',
					shadowBlur : 8,
					shadowOffsetX : 4,
					shadowOffsetY : 4
				});
			}
			}catch(e){}
			// $('#studio_playlist li').each(function(index){
			// log(" lit "+index);
			// });
			// 'li>div'
			// x选取节点
		}
		/**
		 * toolTipText 生成 tooltip的文字
		 * 
		 * @param {json}
		 *            cache 中的缓存
		 * 
		 * @param {String}shoMessage
		 *            显示的文本,默认显示描述
		 */
		function toolTipText(_cc, shoMessage) {
			var desc = "";
			var lock = true;// 是否锁定

			var _title = '';
			var date = '';// 查看时间
			if (_cc) {
				desc = _cc.desc;
				lock = _cc.l;
				_title = _cc.t;
				date = _cc.vDate;// 查看时间,由 loadTimes()进行更新
			}

			if (shoMessage) {
				desc = shoMessage;
			}
			// "","","","","","","","","","","","","","","","","","","","","","",
			// []是数组的定义
			var k = [];
			if (lock) {// 锁定的样式
				// k = [_title,//
				// "本视频已经锁定!",//
				// "请先购买相应的商品!",//
				// "本段视频将于 " + date + " 启用.", //
				// "描述:", ("<p>" + desc + "</p><br/>"),//
				// "敬请期待!"//
				// ];

				var vd = '';// 观看时间的文本
				if (date) {
					vd = "将于 " + date + " 启用。";
				}
				// desc = desc + desc + desc + desc + desc + desc + desc + desc
				// + desc + desc;
				k = [
						'<div class="studio2_main2_text1"><div/>' + _title
								+ '</div>',
						'<div class="studio2_main2_text2">', "本视频已经锁定！" + vd,
						'</div>',// 
						'<div class="studio2_main2_text3">' + desc + '</div>'];

			} else {
				// k = [_title, "描述:", ("<p>" + desc + "</p><br/>")];

				k = [
						'<div class="studio2_main2_text1"><div/>' + _title
								+ '</div>',

						'<div class="studio2_main2_text3">' + desc + '</div>'];
			}
			var m_key = k.join('');
			return m_key;
		}
		/**
		 * 生成树节点可以显示的 提示文字
		 */
		function tree_tootip() {

			var liId = $(this).parent().attr("id");

			// TODO 需要根据这个liid来判断这个 视频是否可以点击
			// 从缓存中去描述
			var _cc = _cacheGet(liId);
			var t = toolTipText(_cc);
			// return '你猜猜我是谁';
			return t;
		}

		/**
		 * 加载历史获奖情况
		 */
		function loadXml() {
			getS(gid("_img_loading_history")).fadeOut(2000);
			var a = {
				pc : opts.pcode
			};

			var xmlUrl = r_url + "resource/";

			// var xmlUrl = r_url + "resource/xml/" + opts.pcode + "/1.xml";

			try {
				$.post(xmlUrl, a, opXml);
			} catch (err) {
				if (isdebug()) {
					showErr(err);
				}
			}
		}

		/**
		 * 加载时间
		 * 
		 * 
		 */
		function loadTimes() {
			// return;
			// alert('helo');

			// if (false) {
			// var a = {
			// op : "loadDate",
			// code : opts.pcode,
			// lt : 0,
			// ui : opts.userId
			// // 0=开始观看，1=结束观看，2=点击描述的链接，3=购买商品成功，4=订阅
			// };
			// var vPath = r_url + "m/";
			// doPost(vPath, a, function() {
			// if (isdebug()) {
			// log('');
			// }
			// });
			// } else {
			var vPath = r_url + "m/?op=loadDate2";
			var rpc = new PHPRPC_Client(vPath, ['loadStudioDate']);
			var backParam = false;// 是否引用参数传递
			rpc.loadStudioDate(opts.userId, opts.pcode, opViewTime, backParam);
			// }
		}

		/**
		 * 显示默认图片
		 */
		function dispDefPict() {
			var G = {
				defType : '0'
			};
			defPlay(G);
		}
		/**
		 * 默认的 数据播放
		 * 
		 * @param {json}
		 *            G {type,value}
		 * 
		 * 被 opXml()调用!
		 */
		function defPlay(G) {
			// SutdioDefaultViewEnum:
			// _0_DEFAULT(0, "系统默认图片", StateColor.i.getColorNONE()),
			// _1_INPUT_IMAGE(1, "指定图片", StateColor.i.getColor1()),
			// _2_FIRST_VIDEO(2, "第一段视频", StateColor.i.getColor2()),
			// _3_TEXT(3, "录入文本", StateColor.i.getColor3()),

			switch (G.defType) {
				case '0' :// 系统默认图片
				case '1' :// 指定图片
					var path = (G.defType == '0')
							? '/keyaimages/studio/234.jpg'
							: G.defValue;

					var t = '<img src="' + path + '" height="' + _flashHeight
							+ '" width="' + _flashWidth + '" />';
					// if (isdebug()) {
					// log('显示默认图片:' + t);
					// }

					var $1 = _gp();
					$1.html(t);
					break;
				case '2' :// 视频(plIndex_videoIndex)

					var nodeId = _mcpl(G.defValue);
					// playv(nodeId);
					// 选中节点 see initTree()的afterClick()方法,实现点击事件;
					try{
					_tree.get(0).clickByNodeId(nodeId);
					}catch(e1){}

					break;
				case '3' :// 文本
					dispFixText(G.defValue);
					break;

				default :

			}

		}

		/**
		 * 
		 * @param {}
		 *            ri= runtimeRelationId 关系id
		 * @return {}
		 */
		function _mcpl(ri) {
			return gid('pl_' + ri);
		}

		/**
		 * 处理 加载的xml
		 * 
		 * @param {}
		 *            xml
		 */
		function opXml(xml) {
			// 默认(default)的相关属性配置,type,和value
			var G = {};

			if (isdebug()) {
				log('处理 xml了 ' + xml);
			}
			// <#--hr位置0:单视频--隐藏播放列表和描述区域-->
			// <#--hr位置1:隐藏tooltip-->
			// <#--hr位置2:隐藏播放列表-->
			// <#--hr位置3:隐藏增销区域-->
			var hiddenAttr_0_singleVi_hidTreeDesc = '0';
			var hiddenAttr_1_hidToolTip = '0';
			var hiddenAttr_2_hidPl = '0';
			var hiddenAttr_3_hidDesc = '0';
			var hiddenAttr_5_hidRoot = '0';// 隐藏根节点

			var $xml = $(xml);
			var studioRuleType = {};
			var title = "";

			// alert("$xml=" + $xml.other);

			$xml.find('other').each(function() {
				// alert('我在other中');
				var o = $(this);

				title = _mc(o.find('t').text());
				var desc = _mc(o.find('d').text());

				// changeHtml('v_title', title);
				{
					var $def = o.find('def');
					G.defType = $def.attr('type');
					G.defValue = _mc($def.text());// $.trim($def.text());//
				}
				G.code = ky.util.trim(o.find('c').text());

				G.count = o.attr('vc');// videoCount 视频个数
				if (isdebug()) {
					log("title=" + title);
					log("desc=" + desc);
					log("def.text=" + G.defType);
					log("def.val=" + G.defValue);
					log("def.count=" + G.count);
				}

				// 规则 演播厅
				o.find('r').each(function() {
					var rule = $(this);

					var ruleType1 = rule.attr('t');
					var ruleCount = rule.attr('rc');
					var ruleTimeId = rule.attr('rti');
					// 隐藏属性
					// <#--hr位置0:单视频--隐藏播放列表和描述区域-->
					// <#--hr位置1:隐藏tooltip-->
					// <#--hr位置2:隐藏播放列表-->
					// <#--hr位置3:隐藏描述区域-->
					// <#--hr位置4:隐藏 水印的 左右滚动-->

					var hiddenAttr = rule.attr('hr');
					var length = hiddenAttr.length;

					for (var i = 0; i < length; i++) {
						var hiddenAttrVal = hiddenAttr.charAt(i);

						// alert(i + '' + '\t=' + hiddenAttrVal);
						switch (i) {
							case 0 :
								hiddenAttr_0_singleVi_hidTreeDesc = hiddenAttrVal;
								break;
							case 1 :
								hiddenAttr_1_hidToolTip = hiddenAttrVal;
								break;
							case 2 :
								hiddenAttr_2_hidPl = hiddenAttrVal;
								break;
							case 3 :
								hiddenAttr_3_hidDesc = hiddenAttrVal;
								break;
							case 4 :
								hiddenAttr_4_hidMarquee = hiddenAttrVal;
							case 5 :
								hiddenAttr_5_hidRoot = hiddenAttrVal;
							default :
								break;
						}
					}

					studioRuleType.hiddenAttr = hiddenAttr;

					studioRuleType.type = ruleType1;
					studioRuleType.time = ruleTimeId;
					studioRuleType.rc = ruleCount;

					// 如果有规则,那么全部数据就设置为锁定
					// 是否显示 true=显示,false=不显示
					studioRuleType.isView = (ruleCount == 0);
					
					if (isdebug()) {
						log('rule===other:type=' + json(studioRuleType));
					}
				});

				// alert('studioRuleType.hiddenAttr=' +
				// studioRuleType.hiddenAttr
				// + "===" + hiddenAttr_0_singleVi_hidTreeDesc + ''
				// + hiddenAttr_1_hidToolTip + '' + hiddenAttr_2_hidPl
				// + '' + hiddenAttr_3_hidDesc);
				// 锁定状态,显示的文本
				o.find('lt>id').each(function() {
					var ldt = $(this);

					var ldtId = ldt.attr('i');
					var type = ldt.attr('t');// 文本显示类型 0=直接显示,1=加载显示

					// 未解密过
					var ldtMessage = $.trim(ldt.text());
					var tmp = {
						type : type, // 文本显示类型 0=直接显示,1=加载显示
						msg : ldtMessage
						// 0时:显示的内容文本,1=查询的参数
					};
					_cachePut('_ldtId_' + ldtId, tmp);

						// if (isdebug()) {
						// log('ldtId=' + ldtId + "\tldtMessage="
						// + json(tmp));
						// }
					});

			});

			{// 部分隐藏

				// <#--hr位置2:隐藏播放列表-->
				if (hiddenAttr_2_hidPl == '1') {
					getS(gid('_playListTree')).hide();
					// log('_flashWidth=' + _flashWidth + '\t_flashHeight='
					// + _flashHeight + "\topts.width=" + opts.width
					// + "\topts.height=" + opts.height);
					// _flashHeight = opts.height;
					// _flashWidth = opts.width;
				}
				// <#--hr位置3:隐藏描述区域-->
				if (hiddenAttr_3_hidDesc == '1') {
					getS(gid('studio_desc')).hide();
				}
			}
			// 单视频--隐藏播放列表和描述区域
			if (G.count <= 1 && hiddenAttr_0_singleVi_hidTreeDesc == '1') {// 只有一个
				// 视频的时候,全部隐藏
				if (isdebug()) {
					log('------------------只有一个视频');
				}

				// flash 高宽 比
				// var fl_hw_cha = 360 / 480;

				_flashWidth = 480;// width;// flash的宽度
				_flashHeight = 360;// _flashWidth * fl_hw_cha;// flash的高度

				{
					var panel = $("#" + gid("studio_layer"));// 演播厅的层
					// 控制外层容器的大小和视频窗口的大小一致
					panel.css({
								width : _flashWidth,
								height : _flashHeight
							});

					if (opts.showByLayer) {
						if (opts.autoCreateLayer) {
							// 判断是否在一个 layer中显示视频
							$("." + gid("border1")).css({
										width : _flashWidth
									});

							var width = _flashWidth + 30;
							var height = _flashHeight + 70;

							// 总的 外层窗口
							var $self = $("#TB_window").hide();

							// 内容窗口
							$("#TB_ajaxContent").css({
										width : _flashWidth + 20,
										height : _flashHeight + 60
									});

							// 以下设置 居中显示
							// initializing variables
							// get the dimensions using dimensions plugin

							// get the paddings
							var paddingTop = parseInt($self.css("padding-top"));
							var paddingBottom = parseInt($self
									.css("padding-bottom"));
							// get the borders
							var borderTop = parseInt($self
									.css("border-top-width"));
							var borderBottom = parseInt($self
									.css("border-bottom-width"));
							// get the media of padding and borders
							var mediaBorder = (borderTop + borderBottom) / 2;
							var mediaPadding = (paddingTop + paddingBottom) / 2;
							// get the type of positioning
							var positionType = $self.parent().css("position");
							// get the half minus of width and height
							var halfWidth = (width / 2) * (-1);
							var halfHeight = ((height / 2) * (-1))
									- mediaPadding - mediaBorder;
							// initializing the css properties
							var cssProp = {
								position : 'absolute'
							};

							var vertical = false;
							var horizontal = true;
							if (vertical === true) {
								cssProp.height = height;
								cssProp.marginTop = halfHeight;

							}
							if (horizontal === true) {
								cssProp.width = width;
								cssProp.left = '50%';
								cssProp.marginLeft = halfWidth;
							}

							if (opts.top) {
								if ($.browser.msie) {
									cssProp.top = '50%';
								} else {

									var tempTop = parseInt(opts.top);
									if (tempTop > 0) {

										var oldTop = parseInt($self.css('top'));
										if (oldTop <= 0)
											oldTop = 100;

										var val = oldTop;
										if ($.browser.opera) {
											// 为了控制页面位置特地+200
											val = (tempTop > oldTop) ? (tempTop
													- oldTop + 200)
													+ "px" : oldTop;
										} else {
											val = (tempTop > oldTop)
													? (tempTop - oldTop) + "px"
													: oldTop;
										}
										// 这里重点解决控制了 演播厅的弹出窗口，在 opts.top 定义的位置附近

										cssProp.top = val;

										// log('opts.top=|' + tempTop + '|'
										// + "\toldTop=" + oldTop
										// + "\tval=" + val);
									} else {
										cssProp.top = '50%';
									}

								}
							} else {
								// cssProp.top = '50%';
								// 这种方式在滚动到下部后，而弹出的演播厅仍然在页面上部
							}

							// check the current position
							// if (positionType == 'static') {
							// $self.parent().css("position", "relative");
							// }
							// aplying the css

							$self.css(cssProp).show();
						}
					}

				}

				var playerIdPanel = gid('v_dv_player');
				var tmp = '<div class="flash" id="' + playerIdPanel
						+ '"></div>';
				panel.html(tmp);

				var $playlist = getS(playerIdPanel);

				$xml.find('playlist v').each(function() {
							var $v = $(this);

							studioRuleType.isView = true;

							var txt = opVideo($v, 'root', studioRuleType,
									$playlist);

							var ri = $v.attr('ri');// relationId
							var key = _mcpl(ri);

							if (isdebug()) {
								log('取出的 key是:' + key);
							}

							// 进行播放的操作
							playv(key);
						});

			} else {
				// 带有播放列表的多个视频
				var ulRoot = gid("_ul_tree_root");

				var treeRoot = gid("root");
				var $rootNode = $("#" + treeRoot);
				$rootNode.empty();

				// 树的数据封装
				var tree = "<li class='root' id='" + treeRoot + "'><div>"
						+ title + "</div><ul id='" + ulRoot + "'>";
				tree += "</ul></li>";

				var plt = $('#' + gid('_playListTree'));
				plt.empty();// 删除节点
				plt.html(tree);

				// 由于树层次还没有 和 dom关联上,所以重新操作对象
				$rootNode = $("#" + treeRoot);

				var $c = getS(ulRoot);
				$xml.find('playlist').each(function() {
					var $pl = $(this);

					var plid = $pl.attr('id');
					// 处理这个播放列表
					var tree1 = opPlayList($pl, studioRuleType, $c);

						// if (isdebug()) {
						// log('one play list=' + tree1);
						// }
						// $c.append(tree1);
					});

				$rootNode.css({
							'background' : 'url(' + rootIcon
									+ ') no-repeat 16px 0'
						});
				// 如果需要隐藏根节点,那么就不显示title,同时删除背景图片
				initTree(hiddenAttr_1_hidToolTip, hiddenAttr_5_hidRoot);

				// 播放默认视频
				defPlay(G);
			}

			if (isdebug()) {
				log("xml处理完成了:准备加载时间 G:" + json(G));
			}
			//loadTimes(G.code);

			if (opts.top && opts.top > 0) {

				var window = $("#TB_window");
				var oldTop = window.css('top');

				// 这里重点解决控制了 演播厅的弹出窗口，在 opts.top 定义的位置附近
				var val = oldTop
						+ ((opts.top > oldTop) ? (opts.top - oldTop) : 0);
				$("#TB_window").css({
							top : val + "px"
						});

			}
		}
		/**
		 * 处理xml的播放列表
		 * 
		 * @param
		 * @param {json}studioRuleType
		 *            <br>
		 * @param jquery对象
		 *            树节点的root节点对象
		 *            <li>.type = 规则类型;
		 *            <li>.time = 规则id;
		 *            <li>.isView =是否可以展现,true=可以显示;
		 * 
		 */
		function opPlayList(plXml, studioRuleType, $root) {
			
			// TODO 界面中,需要动态来创建播放列表的 页面
			var $pl = plXml;
			var plid = $pl.attr('ri');

			var title = _mc($pl.find('pln').text());

			if (isEmpty(title)) {
				title = '营销演播厅';
			}
			 
			if (isdebug()) {
				log('播放列表的标题是:' + title + "\t" + $.trim($pl.find('pln').text()));

			}
			var txt = "";

			// 播放列表的规则
			var playListRule = {};
			$pl.find('r').each(function() {
				var rule = $(this);

				var ruleTypeId = rule.attr('rti');

				var ruleType = rule.attr('t');
				if (isdebug()) {
					log('播放列表===ruleType  :' + ruleType + "\truleTypeId="
							+ ruleTypeId);
				}

				playListRule.ruleType = ruleType;
				playListRule.ruleTypeId = ruleTypeId;

			});

			var $playlist;// 播放列表对象
			$pl.find('v').each(function(index, domEle) {
				if (index == 0) {// 只有列表中有视频,才创建这个播放列表

					var tmpClass = '';
					// 描述是否锁定
					var lock = false;// !(studioRuleType.isView);
					
					switch (playListRule.ruleType) {

						case "1" :// _1_TIMERULE(1, "时间规则",
							lock = true;
							break;
						case "2" :// _2_FIX_TIME(2, "固定时间范围",
							lock = true;
							break;
						case "3" :// _3_LOCKED(3, "锁定",
							lock = true;
							break;
						case "0" :// _0_NONE(0, "无",
						default :
							break;
					}

					playListRule.isView = !lock;
					
					
					tmpClass = '';// (playListRule.isView) ? "" : "notToRead";

					var key = _mcpl(plid);
					
					txt = " <li id='" + key + "'><div  class='" + tmpClass
							+ "'>" + title + "</div><ul></ul></li>";

					$root.append(txt);

					// 初始化播放列表
					$playlist = getS(key);

					// 设置这个节点的样式

					if (playListRule.isView) {
						changeBackground($playlist, iconPathPlayList);
					} else {
						changeBackground($playlist, iconPathPlayListLock);
					}

					var _cc = {
						pid : '',// flash 的pid或者code
						nodeLevel : '1',// 节点级次
						// 0=root,1=playList,2=video(只在播放列表中记录,其他的不记录)
						desc : '',
						t : title,// title
						ri : plid,// runtimeRelationId
						l : lock,// 描述是否锁定
						vDate : ''// 查看时间
					};

					// 把相关内容保存到缓存中
					_cachePut(key, _cc);
					if (isdebug()) {
						log('----------------播放列表=' + title + "\tlock=" + lock
								+ " playListRule=" + json(playListRule));
					}

				}
				// 这个是一个视频文件的定义
				var $v = $(this);

				opVideo($v, plid, playListRule, $playlist);
					// txt =
					// $playlist.append(txt);
					// $root
			});

			// for (var i = 0; i < 10; i++) {
			// var d=new Date();
			// txt += "<li id='" + d.getTime() + "'>";
			// div = "<div class='notToRead'>" + d.getTime() + "</div>";
			// txt += div + "</li>";
			// }
			// if (!isEmpty(txt)) {
			// txt += "</ul></li>";
			// }
			if (isdebug()) {
				log("plid=" + plid);
			}
			return txt;
		}
		/**
		 * 一个视频的xml定义
		 * 
		 * @param {}
		 *            aVideoDef 一段视频的定义
		 * @param {}
		 *            plId 播放列表的id
		 * @param {json}studioRuleType
		 *            演播厅的播放规则,还需要传人播放列表的播放控制
		 * @param jquery
		 *            obj $playlist 播放列表对象
		 * @return {String} 一个 视频的href文本
		 */
		function opVideo(aVideoDef, plid, playListRule, $playlist) {
			var $v = aVideoDef;
			var n = _mc($v.find('n').text());
			var desc = _mc($v.find('d').text());

			var id = $v.attr('id');
			// var pid = $v.attr('i');

			//通用视频
			var pid = $.trim($v.find('cd1').text());
			//56视频
			var pid2 = $.trim($v.find('cd2').text());
			//其它视频
			var pid3 = $.trim($v.find('cd3').text());
			
			// 视频提供商 0=用pid(code)显示,1=通用视频,2=56

			var sp = $v.attr('sp');
			var ldtId = $v.attr('ltd');// 锁定状态的文本id,内容在 <other--desc>中定义

			// log('sp=='+sp);
			// 描述是否锁定
			var lock = !(playListRule.isView);

			var ruleType = $v.attr('rt');
			var ri = $v.attr('ri');// relationId
			switch (ruleType) {
				case '1' :// _1_TIMERULE :// 时间规则
				case '2' :// _2_FIX_TIME :// 固定时间范围
				case '3' :// _3_LOCKED :// 锁定

					// log('============================================='+ruleType);
					lock = true;
					break;
				case '0' :// _0_NONE :// 无
				default :
					// 不控制,取决于pl的规则了
					break;
			}
			// _0_NONE(0, "无", StateColor.i.getColorNONE()),
			// _1_TIMERULE(1, "时间规则", StateColor.i.getColor1()),
			// _2_FIX_TIME(2, "固定时间范围", StateColor.i.getColor2()),
			// _3_LOCKED(3, "锁定", StateColor.i.getColor3()),

			if (isdebug()) {
				log('视频:' + ri + "\t" + n + " ruleType='" + ruleType
						+ "'\tlock=" + lock + "\tplayListRule.isView="
						+ playListRule.isView);
			}

			desc = isEmpty(desc) ? n : desc;
			var key = _mcpl(ri);
			var _cc = {

				pid : pid,
				pid2 : pid2,
				pid3 : pid3,
				sp : sp,
				desc : desc,
				t : n,// title
				ri : ri,
				ruleType : ruleType,// 规则类型
				ldtId : ldtId,// 锁定文本
				l : lock,// 描述是否锁定
				vDate : ''// 查看时间

			};

			// 在 playv() 方法中 会调用 _cc进行播放

			// if (isdebug()) {
			// log('写入的 key是:' + key + " val=" + json(_cc));
			// }

			// 把相关内容保存到缓存中
			_cachePut(key, _cc);

			// 根据时候 显示来控制 样式
			var tmpClass = '';// (!lock) ? "" : "notToRead";

			// log('======================' + plid); class='notToRead_li abc
			// def'
			// li中无法添加其他样式了因为 控件内部会添加样式,前面的样式会被覆盖
			// "&nbsp;&nbsp;&nbsp;&nbsp;"+

			// nodeTxtFontSizeStyle在 initWidth中定义
			 
			var div = "<div style='" + nodeTxtFontSizeStyle + "' class='"
					+ tmpClass + "'>" + n + "</div>";

			var txt = "<li id='" + key + "' >" + div + "</li>";

			$playlist.append(txt);

			var treepath = '';
			 //2010-03-10默认标题全部不锁定
			lock= false;
			
			if (lock) {
				treepath = IconPathVideoLock;
			} else {
				treepath = IconPathVideoNormal;
			}

			// 设置这个节点的样式
			changeBackground(getS(key), treepath);
			return txt;
		}

		/**
		 * 记录点击次数
		 */
		function _c2(ri) {
			var a = {
				op : "view",
				ri : ri,
				lt : 0,
				ui : opts.userId
				// 0=开始观看，1=结束观看，2=点击描述的链接，3=购买商品成功，4=订阅
			};
			var vPath = r_url + "m/";
			doPost(vPath, a);
		}
		/**
		 * playVideo();播放视频
		 * 
		 * @param {String}plid
		 *            播放列表
		 * @param {String}pid
		 *            视频id
		 */
		function playv(key) {
			if (isdebug()) {
				log("playv= nodeId=" + key);
			}

			if (key == 'root') {
				// log('进入了root的配置');
				var G = {
					type : '0'// 显示 系统默认图片
				};
				defPlay(G);
				return;
			}

			var _cc = _cacheGet(key);
			if (_cc) {
				if (isdebug()) {
					log('playv=从缓存中取得的视频的配置文件是:' + json(_cc));
				}
				var lock = _cc.l;// 是否锁定
				
					//2010-03-10默认标题全部不锁定
					lock= false;
				if (lock === false) {// 未锁定

					if (isdebug()) {
						log('未锁定');
					}

					if (_cc.nodeLevel == '1') {
						if (isdebug()) {
							log('我是播放列表');
						}
						var desc = _cc.desc;
						dispDesc(desc);// 显示模式

						dispDefPict();// /显示默认图片
					} else {
						// 播放视频
						//2010-02-05修改 pid:通用视频 pid2:56视频 pid3其它视频
						
						var pid = _mc(_cc.pid);
						
						if(opts.sptype == 2){
							//56视频
							pid = _mc(_cc.pid2);
						}else if(opts.sptype == 3){
							//其它视频
							pid = _mc(_cc.pid3);
						}
						//alert(pid);
						
						var desc = _cc.desc;
						var ri = _cc.ri;
						var sp = _cc.sp;// 视频的提供商
						var autostart = 'true';

						if (isdebug()) {
							log("sp=" + sp + "\tpid=========" + pid);

							if (isEmpty(pid)) {
								alert('视频的pid不存在,请检查视频配置 ');
							}
							// pid = '';
						}
						// pid =
						// 'http://www.56.com/n_v139_/c43_/25_/6_/txwg2008_/zhajm_12365002648_/1099000_/0_/41746871.swf';
						//var txt = _c(pid, autostart, sp);
						var txt = _c(pid, autostart, opts.sptype);
						
						if (isdebug()) {
							log("sp=" + sp + "\tpid=========" + pid
									+ "\n视频的代码是:" + txt + "\n未解码的pid=\t"
									+ _cc.pid);
						}
						// txt = "";

						var tmpWm = '';// 水印
						switch (hiddenAttr_4_hidMarquee) {
							case '1' :
								tmpWm = '<marquee id="'
										+ gid('_div_watermark2')
										+ '" direction="left" width="100%"  scrollamount="1">'
										+ opts.waterMark + '</marquee>';
								break;
							case '0' :
							default :
								tmpWm = opts.waterMark;
								break;

						}

						txt += '<div  class="studio_watermark" id="'
								+ _watermark_id + '">' + tmpWm + '</div>';

						// 上下+左右滚动
						// txt += '<div class="studio_watermark"
						// id="_div_watermark"
						// hight="100%">';
						// txt += '<marquee direction="left"> <marquee
						// behavior="alternate"
						// direction="up" height="100%">'
						// + desc + '</marquee></marquee></div>';

						// 清空,避免某些id仍然存在
						var $1 = _gp();
						$1.empty();
						$1.html(txt);

						// $1.append($(marq));
						// 显示描述
						dispDesc(desc);

						// $("#" + gid('player')).append($(marqu));//这种方式
						// 除了ff下都不能显示
						_initWaterLocation();

						// 更新点击次数
						//_c2(ri);
					}

				} else {

					// if (isdebug()) {
					// log('锁定了');
					// }

					if (_cc.nodeLevel == '1') {
						// log('我是播放列表');

						var desc = _cc.desc;
						dispDesc(desc);// 显示模式

						dispDefPict();// /显示默认图片

					} else {
						// 加载lkdId
						var ldtKey = '_ldtId_' + _cc.ldtId
						// 解密
						var ldtObj = _cacheGet(ldtKey);
						if (ldtObj) {

							// if (isdebug()) {
							// log('显示锁定的文本___锁定');
							// }

							var ldtType = ldtObj.type;// 文本类型
							var ldtMsg = _mc(ldtObj.msg);// 对应内容
							// 加载锁定文本
							dispLockText(ldtKey, ldtType, ldtMsg, _cc);
						} else {

							// if (isdebug()) {
							// log('显示锁定的文本____视频描述');
							// }

							var t = toolTipText(_cc);
							dispFixText(t);
						}

						var desc = _cc.desc;
						dispDesc(desc);// 显示模式
						return false;
					}
				}
			} else {
				// alert("取得缓存出错!");
			}

			return false;
		}

		/**
		 * 显示锁定的文本
		 */
		function dispFixText(text) {
			var $1 = _gp();
			$1.empty();

			// <div class="studio2_main2_text">
			// <div class="studio2_main2_text1"></div>
			// <div class="studio2_main2_text2"></div>
			// <div class="studio2_main2_text3"></div>
			// </div>
			// log(text);//gid("fixText")
			var tmpT = ['<div class="' + 'studio2_main2_text' + '">',//
					text,// 
					'</div>'];

			$1.html(tmpT.join(''));

			// $(".studio2_main2_text").each(function() {// flash的容器
			// var $t = $(this);
			// // $t.width(_flashWidth-20);
			// // $t.height(_flashHeight - 20);
			// $t.css({
			// position : 'relative',
			// overflow : 'auto'
			// });
			// });
		}
		/**
		 * 显示描述
		 */
		function dispDesc(desc) {
			var desc = ky.util.sNull(desc);
			var $2 = getS(gid('studio_desc'));
			$2.empty();
			$2.html(desc);
		}
		/**
		 * 显示锁定的文本的内容
		 */
		function dispLockText(ldtKey, ldtType, ldtMsg, _cc) {
			switch (ldtType) {
				case 1 :
					var vPath = r_url + "m/?op=loadDate2";
					var rpc = new PHPRPC_Client(vPath, ['loadStudioDate']);
					var backParam = false;// 是否引用参数传递
					rpc.loadStudioDate(opts.userId, opts.pcode, function(
									result, args, output, warning) {
								if (result instanceof PHPRPC_Error) {
									var txt = "出错了:\n number="
											+ result.getNumber() + "\nmessage="
											+ result.getMessage()
											+ "\ttoString=" + result.toString();
									log(txt);
								} else if (result) {
									// var $1 = _gp();
									// $1.empty();
									// $1.html(result.txt);

									var t = toolTipText(_cc, result.txt);

									dispFixText(t);

									// 重新缓存,下次不需要通信了
									var tmp = {
										// 文本类型
										type : 0,

										// 对应内容
										msg : result.txt
									};
									cachePut(ldtKey, tmp);
								}
							}, backParam);

					break;

				case 0 :
				default :

					var t = toolTipText(_cc, ldtMsg);
					dispFixText(t);
					break;

			}

		}
		/**
		 * 播放视频的的player对象
		 * 
		 * @return {}
		 */
		function _gp() {
			return $("#" + gid("v_dv_player"));
		}
		function _cm(n, v) {
			return '<param name="' + n + '" value="' + v + '" />';
		}
		/**
		 * createFlashObj():创建一个播放flash 的object 语句
		 * 
		 * @param {}
		 *            pid
		 * @param {}
		 *            autostart
		 * 
		 * @param {int}
		 *            服务提供商 0=默认(flash内容), 1=通用视频,2=56,
		 */
		function _c(pid, autostart, sp) {

			var txt = '';
			sp=sp+'';
			switch (sp) {
				case '1' :// 通用视频
					txt = _c_gv(pid, autostart);
					// txt='通用视频';
					break;
				case '2' :// 56视频
					txt = _c_56(pid, autostart);
					// txt='56视频';
					break;
					
				case '3' :// 其它视频
					txt = pid;
					
					break;
				case '0' :
				default :
				
					//txt = pid;
				//txt = _c_gv(pid, autostart)
					break;
			}
			
			//alert(txt);
			return txt;
		}
		/**
		 * 创建通用视频的 播放器 createGvFlashObj():创建一个播放flash 的object 语句
		 * 
		 * @param {}
		 *            pid
		 * @param {}
		 *            autostart
		 */
		function _c_gv(pid, autostart) {

			var loop = 'false';// 是否循环
			var menu = 'false';// 是否启用菜单

			var fullscreen = 'false';// 是否支持全屏
			// var player = "http://p.generalv.com/player/player.swf";
			var player = "http://p.generalv.com/player/userplayer/huanqiu_player/player.swf";
			if (!autostart || ky.util.isEmpty(autostart)) {
				autostart = 'false';// 是否自动就开始
			}
			var t = '';
			t += '<object id="' + gid('player') + '" width="' + _flashWidth
					+ '" height="' + _flashHeight + '" ';
			t += 'data="' + player + '" ';
			t += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ';
			t += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >';
			t += _cm("allowScriptAccess", "always");
			t += _cm("allowfullscreen", fullscreen);
			t += _cm("wmode", "transparent");
			t += _cm("movie", player);
			t += _cm("quality", "high");
			t += _cm("autostart", autostart);
			t += _cm("loop", loop);
			t += _cm("menu", menu);
			t += _cm("FlashVars", pid);

			t += '<embed width="' + _flashWidth + '" height="' + _flashHeight
					+ '" ';
			t += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
			t += 'type="application/x-shockwave-flash" ';
			t += ' allowscriptaccess="always" ';
			t += ' autostart="' + autostart + '"';
			t += ' loop="' + loop + '"';
			t += ' bgcolor="#ffffff"';
			t += ' allowfullscreen="' + fullscreen + '"';
			t += ' wmode="transparent"';
			t += ' quality="high"';
			t += ' menu="' + menu + '"';
			t += ' flashvars="' + pid + '"';
			t += ' src="' + player + '" />';

			t += '</object>';

			return t;
		}
		/**
		 * 
		 */
		function _c_56(pid, autostart) {
			var fullscreen = 'false';// 是否支持全屏
			var array = ['<embed ',//
					' src="' + pid + '"',// 
					' type="application/x-shockwave-flash" ',//
					' width="' + _flashWidth + '" ',//
					' height="' + _flashHeight + '" ',//
					' wmode="transparent" ',//
					' allowfullscreen="' + fullscreen + '" ',//
					' allowscriptaccess="always"',
					' quality="high" ',//
					' bgcolor="#ffffff" ', '>',//
					'</embed>'// 

			];
			return array.join('');
		}
		/**
		 * 在每次播放的时候,初始化此对象
		 */
		function _initWaterLocation() {

			var play = _gp();

			// var height = play.height();
			// var width = play.width();

			// 获取匹配元素相对父元素的偏移
			// var position = play.position();

			// // 当前窗口的偏移
			var offset = play.offset();
			// position = offset;

			_plc = {
				height : _flashHeight,
				width : '200',
				top : 30,// offset.top,
				left : 5
				// offset.left
			};
			// $("#" + _watermark_id).fadeTo("fast", 0.25);
			// 调整透明度
			$("#" + _watermark_id).fadeTo("fast", 0.125);

			// "fast", 0.25,

			if (isdebug()) {
				log("plc=" + json(_plc));
			}
			// 滚动一下
			changeAnimate();

		}

		/**
		 * 初始化时间控件
		 */
		function _initTimer() {
			if (isEmpty(opts.waterMark)) {
				if (isdebug()) {
					log('无需要显示的水印');
				}
			} else {
				changeAnimate();// 先滚动一次
				var v = 60;// 默认滚动时间 一分钟一次
				// 由于 在firepower中不支持 marquee的动态显示,所以在ff下面对这个数值减小

				// FIXME 需要判断是否启用 滚动方式的水印,如果启用需要特别针对 firefox浏览器进行时间的控制,因为
				// 在ff下不滚动

				switch (hiddenAttr_4_hidMarquee) {
					case '1' :
						v = ($.browser.mozilla) ? 20 : v;
						break;
					case '0' :
					default :
						break;
				}

				setInterval(changeAnimate, 1000 * v);
			}
		}
		/**
		 * 初始化动画
		 */
		function changeAnimate() {
			// log("left: " + offset.left + ", top: " + offset.top + ", height:
			// " +
			// height
			// + ", width: " + width);

			var minWidth = 400;// 最小宽度

			var minTop = 20;// 距离上面的距离
			var minBottom = 50;// 距离下面的距离
			var w1 = minWidth;// _plc.width - 10;// randomInt(minWidth,
			// _plc.width);

			var t1 = randomInt(_plc.top + minTop, _plc.height - minBottom);// 作用是预留出的间隙

			var left = randomInt(0, minWidth - 200);
			if (!t1) {
				t1 = 200;
				w1 = 400;
				// if (isdebug()) {
				// log('无法得到t1,推出了 水印的操作,t1=' + t1 + "\t" + "_plc.top: "
				// + _plc.top + ", _plc.height: " + _plc.height);
				// }

			}
			if (isdebug()) {// 
				log("====================================================\n"

				+ ", width: " + w1 + ", top: " + t1 + "  ,left=" + left
						+ "\tloc___left: " + _plc.left + ", top: " + _plc.top
						+ ", height: " + _plc.height + ", width: " + _plc.width);

			}
			// obj.animate({
			// width : w1
			// }, 3000).animate({
			// top : t1
			// }, 3000);
			//	
			// var obj = $('div[alt="ts2"]');
			// var obj = $('div[sf="' + _watermark_id + '"]');

			// if (isdebug()) {
			// log("_watermark_id=" + _watermark_id + "\ttop : " + t1
			// + ",\twidth : " + w1 + "\twaterMark=" + opts.waterMark);
			// }
			$("#" + _watermark_id).each(function() {
						var t = $(this);
						t.css({
									align : 'left',
									top : t1,
									width : w1,
									left : left
								});
					});

		}

		/**
		 * 处理视频的显示时间
		 * 
		 * @param {}
		 *            result
		 * @param {}
		 *            args
		 * @param {}
		 *            output
		 * @param {}
		 *            warning
		 */
		function opViewTime(result, args, output, warning) {
			if (result instanceof PHPRPC_Error) {
				var txt = "出错了:\n number=" + result.getNumber() + "\nmessage="
						+ result.getMessage() + "\ttoString="
						+ result.toString();
				log(txt);
			} else {
				// log(result.length);
				if (result) {

					// log('now:'+result.now);
					// log(result.times);
					var now;// 这个有问题,不进行切换时间了.

					// if (isdebug()) {
					// now = new Date();
					// } else {
					now = new Date(result.now);// 正常运行,取服务器时间
					// }
					if (isdebug()) {
						log("now==" + ky.format.dateFormat(now));
					}
					var _t = result.times;
					for (var i = 0; i < _t.length; i++) {
						var t = _t[i];

						var tmpDate = new Date(t.date1);
						if (isdebug()) {
							var txt = "\tsrid=" + t.srId + " t.date1="
									+ ky.format.dateFormat(t.date1) + " t.now="
									+ ky.format.dateFormat(now)
									+ "\t(tmpDate <= now)=" + (tmpDate <= now);
							log(txt);
						}
						/** 节点编号 */
						var nodeId = _mcpl(t.srId);
						var _cc = _cacheGet(nodeId);

						if (_cc) {// 更新显示时间
							_cc.vDate = ky.format.toDateByFormat(tmpDate);

							if (tmpDate <= now) {
								// 更新界面图标

								_cc.l = false;/* 更新锁定lock的状态,便于tooltip使用 */

								/* 更新节点状态 */
								var node = $('#' + nodeId);
								// var obj = $('div:first', node);
								// obj.removeClass("notToRead");

								// 设置这个节点的样式

								if (_cc.nodeLevel == "1") {// 播放列表
									changeBackground(node, iconPathPlayList);
								} else {
									changeBackground(node, IconPathVideoNormal);
								}

								// log('div是' + json(_cc));
							} else {
								if (isdebug()) {
									log('时间不在' + _cc.vDate);
								}
							}

						} else {
							if (isdebug()) {
								log('没有得到缓存:' + nodeId);
							}
						}
					}
				}
			}
			// vDate
			// log(txt);
			// var feedback = document.getElementById('feedback');
			// feedback.innerHTML = txt;

		}

		/**
		 * 更改节点的样式
		 */
		function changeBackground($obj, path) {
			$obj.css({
						'background' : 'url(' + path + ') no-repeat 16px 0'
					});

		}
		/**
		 * 对界面的长宽进行初始化
		 */
		function initWidth() {

			var defWidth = 710;// 默认宽度
			var defHeight = 380;// 默认高度
			if (!opts.width) {
				opts.width = defWidth;
			}
			if(opts.width==540)
			{
				opts.width=530;
			}

			if (opts.width < defWidth) {// 如果宽度<默认宽度,那么就改变树文本字体大小
				if ($.browser.msie || $.browser.opera) {// 只针对ie实现,其他浏览器不好看
					nodeTxtFontSizeStyle = 'font-size:11px;';
				} else {
					nodeTxtFontSizeStyle = 'font-size:11.5px;';
				}

			}
			// 边框的宽度比
			var p_border_cha = 10 / defWidth;
			// 播放器的高宽度比
			var p_hw_cha = defHeight / defWidth;
			opts.height = opts.width * p_hw_cha;// 播放器的高度

			// 播放列表的宽度和播放器的宽度比
			var p_playlist_w_cha = 210 / defWidth;

			// 播放列表的高度和播放器的高度比
			var p_playlist_h_cha = defHeight / defHeight;

			// flash 的宽度和播放器的宽度比
			var fl_w_cha = 480 / defWidth;
			// flash 高宽 比
			var fl_hw_cha = 360 / 480;

			_flashWidth = opts.width * fl_w_cha;// flash的宽度
			_flashHeight = _flashWidth * fl_hw_cha;// flash的高度

			// 当前的边框的宽度
			var c_border = p_border_cha * opts.width;

			var c_playlist_h = p_playlist_h_cha * opts.height;// 播放列表高
			var c_playlist_w = p_playlist_w_cha * opts.width;// 播放列表宽

			// c_playlist_h=_flashHeight;
			// c_playlist_w=_flashWidth;
			if (isdebug()) {

				var t = '宽度:\n';
				t += '_flashWidth=' + _flashWidth + '\n';
				t += '_flashHeight=' + _flashHeight + '\n';
				t += 'c_border=' + c_border + '\n';

				t += 'c_playlist_h=' + c_playlist_h + '\n';
				t += 'c_playlist_w=' + c_playlist_w + '\n';

				log(t);
			}
			$("." + gid("studio1")).each(function() {// 演播厅的bannel图标行
						var $t = $(this);
						$t.width(opts.width);
					});

			$("." + gid("studio2")).each(function() {// 演播厅整体
						var $t = $(this);
						$t.width(opts.width);
					});

			$("." + gid("studio2_main")).each(function() {/* 播放列表和视频面板的父亲 */
						var $t = $(this);
						$t.width(opts.width);
						$t.height(opts.height);

					});

			$("." + gid("studio2_main1")).each(function() {/* 播放列表 */
						var $t = $(this);
						$t.width(c_playlist_w);
						$t.height(c_playlist_h);

						$t.css({
									// 'padding' : '4px',
									overflow : 'auto'// 增加播放列表的滚动条
								});
					});

			$("." + gid("studio2_tag")).each(function() {// 描述

						var pad = '6px 10px 3px 10px';
						var $t = $(this);
						$t.width((opts.width - 2 * c_border));// 2了边的宽度
						$t.css({
									height : '59px',
									'padding' : pad,
									position : 'relative',
									overflow : 'auto'
								});

					});

			$("." + gid("studio2_main2")).each(function() {// flash的容器
						var $t = $(this);
						$t.width(_flashWidth);
						$t.height(_flashHeight);
						$t.css('padding', parseInt(c_border) + 'px');
					});

			$("." + gid("studio2_main2_movie")).each(function() {// flash的容器
						var $t = $(this);
						$t.width(_flashWidth);
						$t.height(_flashHeight);

					});

			$("." + gid("flash")).each(function() {// flash的容器
						var $t = $(this);
						$t.width(_flashWidth);
						$t.height(_flashHeight);
						$t.css({
							position : 'relative'
								// , overflow : 'auto'
							});
					});
			// + gid("fixText")
			// $(".studio2_main2_text").each(function() {// flash的容器
			// var $t = $(this);
			// $t.width(_flashWidth);
			// $t.height(_flashHeight);
			// $t.css({
			// position : 'relative',
			// overflow : 'auto'
			// });
			// });

			// $(".studio2_main2_text3").each(function() {// flash的容器
			// var $t = $(this);
			// $t.width(_flashWidth);
			// $t.height(_flashHeight - 100);
			// $t.css({
			// position : 'relative',
			// overflow : 'auto'
			// });
			// });

		}

		if (ky.util.isEmpty(opts.pcode)) {
			alert('pcode 不允许为空无法得到 演播厅code');
		} else {
			{
				// 重新处理缓存
				var isInti = _cacheGet('_studio_is_init');

				__studio_cacheElementId = '_s_c_eid_' + ky.util.getNextId();

				// 初始化缓存,把之前的清空
				_initCache(__studio_cacheElementId);
				_cachePut('_studio_is_init', isInti);

			}
			// alert('开始初始化');
			_initStudio();

		}
		function haha() {
			alert('我在内部了');
		}

	});
}

