(function($){$.fn.tenVideoCatcher=function(options){var elt=this;var setting={title:"YouTube and Dailymotion videos player",className:"TEN-player",width:640,height:390};$.extend(setting,options);var content=$(elt).html();var reg=/\[(youtube|dailymotion)(.*)\]([a-z0-9_ -]+)\[\/(youtube|dailymotion)\]/gi;var matches=content.match(reg);if(matches!=null){$.each(matches,function(index,code){code.match(reg);var videoType=RegExp.$1;var videoStyle=RegExp.$2;var videoId=RegExp.$3;videoId=videoId.replace(" ","");var videoURL=null;if(videoType=="youtube"){videoURL="http://www.youtube.com/embed/"+videoId;}
else if(videoType=="dailymotion"){videoURL="http://www.dailymotion.com/embed/video/"+videoId;}
var isset=new Array();isset['width']=false;isset['height']=false;if(videoStyle!=""&&videoStyle!=null){var regStyleW=/width=([0-9]+)(px)?/gi;matcheWidth=regStyleW.exec(videoStyle);var regStyleH=/height=([0-9]+)(px)?/gi;matcheHeight=regStyleH.exec(videoStyle);if(matcheWidth!=null){console.log("Width : "+matcheWidth[1]);setting.width=matcheWidth[1];isset['width']=true;}
if(matcheHeight!=null){console.log("Height : "+matcheHeight[1]);setting.height=matcheHeight[1];isset['height']=true;}
if(isset['width']&&!isset['height']){setting.height=Math.round((390/640)*setting.width);}else if(!isset['width']&&isset['height']){setting.width=Math.round((640/390)*setting.height);}}
var htmlToEmbed="<object type='text/html' data='"+videoURL+"'";htmlToEmbed+=" style='width:"+setting.width+"px;height:"+setting.height+"px;'></object>";content=content.replace(code,htmlToEmbed);$(elt).html(content);});}};})(jQuery);
