jQuery.fn.ytplaylist=function(options){var options=jQuery.extend({holderId:'ytvideo',playerHeight:'300',playerWidth:'450',addThumbs:false,thumbSize:'small',showInline:false,autoPlay:true,showRelated:false,allowFullScreen:false,color1:true,color2:true,thumbs_width:'80',thumbs_height:'60',divText:''},options);return this.each(function(){var selector=$(this);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";if(options.color1)color1="&color1="+options.color1;if(options.color2)color2="&color2="+options.color2;function play(id)
{var html='';html+='<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">';html+='<param name="movie" value="http://www.youtube.com/v/'+id+autoPlay+showRelated+fullScreen+color1+color2+'&version=3"> </param>';html+='<param name="wmode" value="transparent"> </param>';if(options.allowFullScreen){html+='<param name="allowfullscreen" value="true"> </param>';}
html+='<embed src="http://www.youtube.com/v/'+id+autoPlay+showRelated+fullScreen+color1+color2+'&version=3"';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 youtubeid(url){var ytid=url.match("[\\?&]v=([^&#]*)");ytid=ytid[1];return ytid;};var firstVid=selector.children("li:first-child").addClass("selected").children("a").attr("href");$("#"+options.holderId+"").html(play(youtubeid(firstVid)));$("#"+options.divText+"").html(selector.children("li:first-child").addClass("selected").children("a").attr("alt"));selector.children("li").children("a").click(function(){if(options.showInline){$("li.currentvideo").removeClass("selected");$(this).parent("li").addClass("selected").html(play(youtubeid($(this).attr("href"))));}
else{$("#"+options.holderId+"").html(play(youtubeid($(this).attr("href"))));$("#"+options.divText+"").html($(this).attr("alt"));$(this).parent().parent("ul").find("li.selected").removeClass("selected");$(this).parent("li").addClass("selected");}
return false;});if(options.addThumbs){selector.children().each(function(i){var replacedText=$(this).text();if(options.thumbSize=='small'){var thumbUrl="http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/2.jpg";}
else{var thumbUrl="http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/0.jpg";}
$(this).children("a").empty().html("<img src='"+thumbUrl+"' alt='"+replacedText+"' width='"+options.thumbs_width+"' height='"+options.thumbs_height+"' />");});}});};
