String.prototype.startsWith=function(str){return(this.indexOf(str)===0)};jQuery.fn.ytplaylist=function(options){var options=jQuery.extend({holderId:"ytvideo",playerHeight:300,playerWidth:450,addThumbs:false,thumbSize:"small",showInline:false,autoPlay:true,showRelated:true,allowFullScreen:false},options);return this.each(function(){var $el=$(this);var first=true;var autoPlay="";var showRelated="&rel=0";var fullScreen="";if(options.autoPlay){autoPlay="&autoplay=1"}if(options.showRelated){showRelated="&rel=1"}if(options.allowFullScreen){fullScreen="&fs=1"}function playOld(id){var html="";html+='<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">';if(first==true){html+='<param name="movie" value="http://www.youtube.com/v/'+id+"&autoplay=0"+showRelated+fullScreen+'&hd=1&showinfo=0"> </param>'}else{html+='<param name="movie" value="http://www.youtube.com/v/'+id+"&autoplay=1"+showRelated+fullScreen+'&hd=1&showinfo=0"> </param>'}html+='<param name="wmode" value="transparent"> </param>';if(options.allowFullScreen){html+='<param name="allowfullscreen" value="true"> </param>'}if(first==true){html+='<embed src="http://www.youtube.com/v/'+id+"&autoplay=0"+showRelated+fullScreen+'&hd=1&showinfo=0"';first=false}else{html+='<embed src="http://www.youtube.com/v/'+id+"&autoplay=1"+showRelated+fullScreen+'&hd=1&showinfo=0"'}if(options.allowFullScreen){html+=' allowfullscreen="true" '}html+='type="application/x-shockwave-flash" wmode="transparent"  height="'+options.playerHeight+'" width="'+options.playerWidth+'"></embed>';html+="</object>";return html}function playNew(id){var html="";html+='<iframe width="'+options.playerWidth+'" height="'+options.playerHeight+'"';html+=' src="http://www.youtube.com/embed/'+id+'" frameborder="0"';hml+=" allowfullscreen></iframe>"}function youtubeid(url){var ytid=url.match("[\\?&]v=([^&#]*)");ytid=ytid[1];return ytid}$el.children("li").each(function(){$(this).find("a").each(function(){var thisHref=$(this).attr("href");if(thisHref.startsWith("http://www.youtube.com")){$(this).addClass("yt-vid");$(this).data("yt-id",youtubeid(thisHref))}else{if(thisHref.startsWith("http://youtu.be")){$(this).addClass("yt-vid");var id=thisHref.substr(thisHref.lastIndexOf("/")+1);$(this).data("yt-id",id)}else{$(this).addClass("img-link")}}})});$el.children("li").children("a.yt-vid").click(function(){if(options.showInline){$("li.currentvideo").removeClass("currentvideo");$(this).parent("li").addClass("currentvideo").html(playOld($(this).data("yt-id")))}else{$("#"+options.holderId+"").html(playOld($(this).data("yt-id")));$(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo");$(this).parent("li").addClass("currentvideo")}return false});$el.find("a.img-link").click(function(){var $img=$("<img/>");$img.attr({src:$(this).attr("href")}).css({display:"none",position:"absolute",left:"0px",top:"50%"});if(options.showInline){$("li.currentvideo").removeClass("currentvideo");$(this).parent("li").addClass("currentvideo").html($img)}else{$("#"+options.holderId+"").html($img);$(this).closest("ul").find("li.currentvideo").removeClass("currentvideo");$(this).parent("li").addClass("currentvideo")}setTimeout(function(){if($img.height()<$img.width()){$img.width(options.playerWidth).css("margin-top",parseInt($img.height()/-2,10)).css({height:"auto"})}else{$img.css({height:options.playerHeight,width:"auto",top:"0px",position:"relative"})}$img.fadeIn()},100);return false});if(options.addThumbs){$el.children().each(function(i){var $link=$(this).find("a:first");var replacedText=$(this).text();if($link.hasClass("yt-vid")){if(options.thumbSize=="small"){var thumbUrl="http://img.youtube.com/vi/"+$link.data("yt-id")+"/2.jpg"}else{var thumbUrl="http://img.youtube.com/vi/"+$link.data("yt-id")+"/0.jpg"}var thumbHtml="<img src='"+thumbUrl+"' alt='"+replacedText+"' />";$link.empty().html(thumbHtml+replacedText).attr("title",replacedText)}else{var $img=$("<img/>").attr("src",$link.attr("href"));$link.empty().html($img).attr("title",replacedText)}})}var firstVid=$el.children("li:first-child").addClass("currentvideo").children("a").click()})};
