(function(){var isModifyUploadVideo=false;window.onload=function(){$focus($G("videoUrl"));initVideo();};function initVideo(){createAlignButton(["videoFloat"]);addUrlChangeListener($G("videoUrl"));addOkListener();(function(){var img=editor.selection.getRange().getClosedNode(),url;if(img&&img.className){var hasFakedClass=(img.className=="edui-faked-video"),hasUploadClass=img.className.indexOf("edui-upload-video")!=-1;if(hasFakedClass||hasUploadClass){$G("videoUrl").value=url=img.getAttribute("video_fileurl");$G("videoWidth").value=img.width;$G("videoHeight").value=img.height;var align=domUtils.getComputedStyle(img,"float"),parentAlign=domUtils.getComputedStyle(img.parentNode,"text-align");updateAlignButton(parentAlign==="center"?"center":align);}
if(hasUploadClass){isModifyUploadVideo=true;}}
createPreviewVideo(url);})();}
function addOkListener(){dialog.onok=function(){$G("preview").innerHTML="";return insertSingle();};dialog.oncancel=function(){$G("preview").innerHTML="";};}
function updateAlignButton(align){var aligns=$G("videoFloat").children;for(var i=0,ci;ci=aligns[i++];){if(ci.getAttribute("name")==align){if(ci.className!="focus"){ci.className="focus";}}else{if(ci.className=="focus"){ci.className="";}}}}
function insertSingle(){var width=$G("videoWidth"),height=$G("videoHeight"),url=$G('videoUrl').value,align=findFocus("videoFloat","name");if(!url)
return false;if(!checkNum([width,height]))
return false;if(is_url_http(url)){editor.execCommand('insertvideo',{url:convert_url(url),width:width.value,height:height.value,align:align},isModifyUploadVideo?'upload':null);}else{editor.execCommand('insertHtml','<p style="text-align: center;"><embed type="application/x-shockwave-flash" video_fileurl="'+url+'" flashvars="video='+url+'" class="edui-faked-video" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.ecisp.cn/ckplayer/ckplayer.swf" width="'+width.value+'" height="'+height.value+'" wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="always" allowfullscreen="true"/></p>');}}
function findFocus(id,returnProperty){var tabs=$G(id).children,property;for(var i=0,ci;ci=tabs[i++];){if(ci.className=="focus"){property=ci.getAttribute(returnProperty);break;}}
return property;}
function convert_url(url){if(!url){return'';}
if(!is_url_http(url)){return url;}
url=utils.trim(url).replace(/v\.youku\.com\/v_show\/id_([\w\-=]+)\.html/i,'player.youku.com/player.php/sid/$1/v.swf').replace(/(www\.)?youtube\.com\/watch\?v=([\w\-]+)/i,"www.youtube.com/v/$2").replace(/youtu.be\/(\w+)$/i,"www.youtube.com/v/$1").replace(/v\.ku6\.com\/.+\/([\w\.]+)\.html.*$/i,"player.ku6.com/refer/$1/v.swf").replace(/www\.56\.com\/u\d+\/v_([\w\-]+)\.html/i,"player.56.com/v_$1.swf").replace(/www.56.com\/w\d+\/play_album\-aid\-\d+_vid\-([^.]+)\.html/i,"player.56.com/v_$1.swf").replace(/v\.pps\.tv\/play_([\w]+)\.html.*$/i,"player.pps.tv/player/sid/$1/v.swf").replace(/www\.letv\.com\/ptv\/vplay\/([\d]+)\.html.*$/i,"i7.imgs.letv.com/player/swfPlayer.swf?id=$1&autoplay=0").replace(/www\.tudou\.com\/programs\/view\/([\w\-]+)\/?/i,"www.tudou.com/v/$1").replace(/v\.qq\.com\/cover\/[\w]+\/[\w]+\/([\w]+)\.html/i,"static.video.qq.com/TPout.swf?vid=$1").replace(/v\.qq\.com\/.+[\?\&]vid=([^&]+).*$/i,"static.video.qq.com/TPout.swf?vid=$1").replace(/my\.tv\.sohu\.com\/[\w]+\/[\d]+\/([\d]+)\.shtml.*$/i,"share.vrs.sohu.com/my/v.swf&id=$1");return url;}
function is_url_http(url){var isURL=false;if(url.indexOf('youku\.com')>0||url.indexOf('youtube')>0||url.indexOf('ku6\.com')>0||url.indexOf('56\.com')>0||url.indexOf('pps\.tv')>0||url.indexOf('letv\.com')>0||url.indexOf('tudou\.com')>0||url.indexOf('qq\.com')>0||url.indexOf('sohu\.com')>0){isURL=true;}
return isURL;}
function checkNum(nodes){for(var i=0,ci;ci=nodes[i++];){var value=ci.value;if(!isNumber(value)&&value){ci.value="";ci.focus();return false;}}
return true;}
function isNumber(value){return/(0|^[1-9]\d*$)/.test(value);}
function createAlignButton(ids){for(var i=0,ci;ci=ids[i++];){var floatContainer=$G(ci),nameMaps={"none":lang['default'],"left":lang.floatLeft,"right":lang.floatRight,"center":lang.block};for(var j in nameMaps){var div=document.createElement("div");div.setAttribute("name",j);if(j=="none")
div.className="focus";div.style.cssText="background:url(images/"+j+"_focus.jpg);";div.setAttribute("title",nameMaps[j]);floatContainer.appendChild(div);}
switchSelect(ci);}}
function switchSelect(selectParentId){var selects=$G(selectParentId).children;for(var i=0,ci;ci=selects[i++];){domUtils.on(ci,"click",function(){for(var j=0,cj;cj=selects[j++];){cj.className="";cj.removeAttribute&&cj.removeAttribute("class");}
this.className="focus";});}}
function addUrlChangeListener(url){if(browser.ie){url.onpropertychange=function(){createPreviewVideo(this.value);}}else{url.addEventListener("input",function(){createPreviewVideo(this.value);},false);}}
function createPreviewVideo(url){if(!url){return false;}
var conUrl=convert_url(url);if(is_url_http(url)){$G("preview").innerHTML='<div class="previewMsg"><span>'+lang.urlError+'</span></div>'+'<embed class="previewVideo" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"'+' src="'+conUrl+'"'+' width="'+420+'"'+' height="'+280+'"'+' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >'+'</embed>';}else{$G("preview").innerHTML='<embed type="application/x-shockwave-flash" video_fileurl="'+conUrl+'" flashvars="video='+conUrl+'" class="edui-faked-video" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.ecisp.cn/ckplayer/ckplayer.swf" width="420" height="280" wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="always" allowfullscreen="true"/>';}}})();