/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  
var tb_pathToImage = "/images_v2/LightboxLoadingAnimation.gif";
var flashRequired = "<div style='padding:{0}px 0 0 0; text-align:center;'>You will need a Flash-enabled browser to watch this video.</div>";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	//tb_init('a.thickbox, area.thickbox, input.thickbox, div.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	
		var objItem = $(domChunk);


		var t = objItem.title || objItem.name || null;
		var a = objItem.href || objItem.alt;
		var g = objItem.rel || false;
		
		if(domChunk.indexOf('ThickBoxForQbOnly') > -1){
			a = objItem.attr('name');
			t = objItem.attr('title') || objItem.attr('alt');
		}
		
		if(domChunk.indexOf('howtoVideo') > -1){
			a = objItem.attr('name');
			var objRel = $(objItem.attr('relate'));
			//alert(objRel.html());
			
			t = "<div id=\"how-tos-related-video\"><h2>";
			t += objItem.attr('title') || objItem.attr('alt');
			t += "</h2>";
			t+=objRel.html()+"</div>";
		}
		
		if(t==null && $(document).find('#divTbTitle').html() != null){
			t = $(document).find('#divTbTitle').html();
		}
		
		if(a==null && $(document).find('#divTbHref').html() != null){
			a = $(document).find('#divTbHref').html();
		}
		
		//if using ipad , iphone or ipod, open video in youtube app
		if ((navigator.userAgent.match(/iPhone/i)
		|| navigator.userAgent.match(/iPod/i)
		|| navigator.userAgent.match(/iPad/i)) 
		&& a.indexOf('type=1') > -1){
			var queryString = a.replace('#','').replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery(queryString);
			var paramsVID;
			paramsVID = params['vid'];
			location.href = "http://www.youtube.com/watch?v=" + paramsVID;
		}else{
			tb_show(t,a,g);
			objItem.blur();
		}
		return false;
}

function onYouTubePlayerReady(id){
	//QB only
	if($('#myytplayer').length > 0){
		var ytswf;
		ytswf = document.getElementById('myytplayer');
		if(ytswf != null){
			if (ytswf.addEventListener) {
				ytswf.addEventListener('onStateChange', 'handlePlayerStateChange');
			}else {
				ytswf.attachEvent('onStateChange', 'handlePlayerStateChange');
			}
		}
	}
}

function handlePlayerStateChange(state) {
	if(state == 0){
		//close window
		tb_remove();
	}
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if(typeof(caption) == 'undefined'){
			caption = "";
		}
	
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				//$("#TB_overlay").click(tb_remove);  //Close Window
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\#$|\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;//   this --> \#$| --> for flash 
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
			//Sample in the webpage:
			//<a href="images/large2.jpg" modal=true" title="Movie 2" class="thickbox"><img src="images/image2.jpg" /></a>
			
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 0;
			TB_HEIGHT = imageHeight + 60;
			var wondowContent = "<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='";
			wondowContent += imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption' width='" + imageWidth-30 + "px'>";
			wondowContent += caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML;
			wondowContent += "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>";
			wondowContent += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></div>";
			
			$("#TB_window").append(wondowContent); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else if(urlType == "#"){
			//get params
			var queryString = url.replace('#','').replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery(queryString);
			var paramsWidth;
			var paramsHeight;
			var paramsVID;
			var paramsLanguage;
			var paramsHD;
			var paramsAutoplay;
			var paramsSource;
			
			paramsWidth = params['width']; 
			paramsHeight = params['height'];
			paramsVID = params['vid'];
			paramsLanguage = params['language'];
			paramsHD = params['hd'];
			paramsAutoplay = params['autoplay'];
			paramsStart = params['start'];
			paramsSource = params['source'];
			paramsFile = params['file'];
			paramsImage = params['image'];
						
			if(paramsLanguage == null  || paramsLanguage == ''){
				paramsLanguage = 'en';
			}
			
			if(paramsHD == null  || paramsHD == ''){
				paramsHD = '0';
			}
			
			if(paramsAutoplay == null  || paramsAutoplay == ''){
				paramsAutoplay = '1';
			}
			
			if(paramsStart == null  || paramsStart == ''){
				paramsStart = '0';
			}
			
			if(paramsSource == null  || typeof(paramsSource) == 'undefined'){
				paramsSource = '';
			}
			
			if(paramsVID == null  || typeof(paramsVID) == 'undefined'){
				paramsVID = '';
			}
			
			if(paramsFile == null  || typeof(paramsFile) == 'undefined'){
				paramsFile = '';
			}
			
			if(paramsImage == null  || typeof(paramsImage) == 'undefined'){
				paramsImage = '';
			}
			
			while(paramsVID.indexOf(" ") >= 0) {
				paramsVID = paramsVID.replace(" ", "");
			}

			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = parseInt(paramsWidth);
			var imageHeight = parseInt(paramsHeight);
			
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			
			// End Resizing
			TB_WIDTH = imageWidth;
			TB_HEIGHT = imageHeight + 60;
			
			var appendHtml = '';
			appendHtml += "<div id='TB_CloseWindowV2'></div><div id='ytapiplayer'></div><div id='TB_Bottom'><div id='TB_caption' style='width:";
			appendHtml += (imageWidth - 42) + "px;'>"+caption+"</div></div>";
			
			$("#TB_window").append(appendHtml); 	
			
			
			//for no flash player
			var siteName = location.href.toLowerCase();
			flashRequired = flashRequired.replace("{0}", imageHeight/2);
			$('#ytapiplayer').width(imageWidth).height(imageHeight).html(flashRequired);
				
			if(paramsSource.toLowerCase() == 'youku'){
				//video in Youku, used by China
				var strUrl = 'http://player.youku.com/player.php/partnerid/XMTQ4OA==/sid/' + paramsVID + '/v.swf'; 
				var flashvars = {isAutoPlay: true, playMovie:"true", isShowRelatedVideo:false,allowFullScreen:"false",skinflag:"2",skincolor1:"ffffff",skincolor2:"555555",skinalpha:"40"};
				var params = { allowScriptAccess: "always", wmode: "transparent", menu: false };
				var atts = { id: "myytplayer" };
				swfobject.embedSWF(strUrl, "ytapiplayer", imageWidth, imageHeight, "8", null, flashvars, params, atts);
			}else if(paramsSource.toLowerCase() == 'htc'){
				//video host by HTC
				var strUrl = '/player/player-licensed.swf'; 
				var flashvars = {file:paramsFile,repeat:'single',image:paramsImage,skin:'/player/whotube.zip', autostart:true,screencolor:'000000'};
				var params = { allowScriptAccess: "always", wmode: "transparent",allowfullscreen:true};
				var atts = { id: "myytplayer" };
				swfobject.embedSWF(strUrl, "ytapiplayer", imageWidth, imageHeight, "8", null, flashvars, params, atts);
			}else{
				//youtube
				var strUrl = "http://www.youtube.com/v/" + paramsVID + "?enablejsapi=1&playerapiid=ytapiplayer";
				strUrl += "&showsearch=0&rel=0&fs=1&iv_load_policy=3&cc_load_policy=1";
				strUrl += "&autoplay=" + paramsAutoplay + "&hd=" + paramsHD + "&hl=" + paramsLanguage;
				strUrl += "&start=" + paramsStart;
			
				var params = { allowScriptAccess:"always", wmode:"transparent", menu:false, allowFullScreen:true, quality:"high"};
				var atts = { id: "myytplayer" };
				swfobject.embedSWF(strUrl, "ytapiplayer", imageWidth, imageHeight, "8", null, null, params, atts);
			}
		
			tb_position();
			$("#TB_load").remove();
			$("#TB_CloseWindowV2").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
		
		}else{//code to show html
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
		alert('error');
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	//stop video
	
	return false;
}


//YouTube Videos
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";	
	return false;
}

function tb_position() {
	var siteName = location.href.toLowerCase();
	var strWrap = 'circular';
	if( jQuery.browser.msie && (siteName.indexOf('/mea-sa/') > -1 || siteName.indexOf('/eg/') > -1)){
		$("#TB_window").css({marginRight:  TB_WIDTH - parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	}else{
		$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	}
	
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

var win=null;
function PopupWindow(mypage,w,h){
	NewWindow(mypage,'mywin',w,h,'yes','center');
}

function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	
	if(pos=="center"){
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){
	LeftPosition=0;
	TopPosition=20;
	}
	
	settings='width='+w+',height='+h+',top='+TopPosition+',';
	settings +='left='+LeftPosition+',scrollbars='+scroll+',location=no,';
	settings +='directories=no,status=no,menubar=no,toolbar=no,resizable=yes';

	win=window.open(mypage,myname,settings);
}




//on page load call tb_init
	$(function(){
		if($('.playlist').length > 0){
			var thumbSize = 'large';		// 設定要取得的縮圖是大圖還是小圖
											// 大圖寬高為 480X360；小圖寬高為 120X90
			var imgWidth = '94';			// 限制圖片的寬
			var imgHeight = '68';			// 限制圖片的高
			var swfWidth = '640';			// 指定 YouTube 影片的寬
			var swfHeight = '385';			// 指定 YouTube 影片的高
			var autoPlay = '&autoplay=0';	// 是否載入 YouTube 影片後自動播放；若不要自動播放則設成 0
			var fullScreen = '&fs=1';		// 是否允許播放 YouTube 影片時能全螢幕播放
			var hd = '&hd=0'; // 是否高品質畫面
			var loop = '&loop=0'; //是否重撥
			var rel= '&rel=0';
			
			$('.playlist>li>a').each(function(){
				// 取得要連結轉換的網址及訊息內容
				var _this =  $(this);
				var _url = _this.attr('href');
				var _info = _this.text();
				var _type = (thumbSize == 'large') ? 0 : 2;
				
				// 取得 vid
				var vid = _url.match('[\\?&]v=([^&#]*)')[1];
				// 取得縮圖
				var thumbUrl = "http://img.youtube.com/vi/" + vid + "/" + _type + ".jpg";
				//用自己的圖片 rewrite
				thumbUrl = _this.attr('class');
				
				var NoFlashThumbUrl = 'http://img.youtube.com/vi/' + vid + '/0.jpg';
				
				// 把目前超連結的內容轉換成圖片並加入 click 事件
				var imgSrc = '<img src="'+thumbUrl+'" alt="'+_info+'" title="'+_info+'" width="'+imgWidth+'" height="'+imgHeight+'" />';
				_this.html(imgSrc).click(
					function(){
						return false;
					}
				).focus(
					function(){
						this.blur();
					}
				).children('img').click(
					function(){
						// 當點擊到圖片時就轉換成 YouTube 影片				
						// Version check based upon the values entered above in "Globals"
						var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

						// Check to see if the version meets the requirements for playback
						if (hasReqestedVersion) {
							// if we've detected an acceptable version
							// embed the Flash Content SWF when all tests are passed
							var so = new SWFObject('http://www.youtube.com/v/'+vid+autoPlay+fullScreen+hd+loop+rel, 'namePlayArea',swfWidth, swfHeight, '6.0.0', '#ffffff');
							so.addParam('quality', 'high');
							so.addParam('wmode', 'opaque');
							so.write('divPlayArea');			
						} else {  
							// flash is too old or we can't detect the plugin
							var alternateContent = '';
							alternateContent += '<img src="' + NoFlashThumbUrl +'" width="'+swfWidth+'" height="'+swfHeight+'" />';
							$('#divPlayArea').html(alternateContent); // insert non-flash content
						}
						return false;
					}
				);
			});
			
			// 先載入第一個影片
			$('.playlist>li>a').eq(0).children('img').click();
		}
	});
