(function($){var youtubinCount=0;var youtubinMode=0;$.youtubin=function(options,box){var options=options||{};if((typeof options.iphoneBoot=='undefined'||options.iphoneBoot)&&((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))))return false;if(!youtubinMode){if(typeof(swfobject)=='undefined')youtubinMode='noScript';else youtubinMode='2'}if(typeof(box)=='undefined'||!box){options.scope=options.scope||$('body');$('a[href^=http://www.youtube.com/watch?v=]',options.scope).youtubin(options);return false}options.swfWidth=options.swfWidth||"425";options.swfHeight=options.swfHeight||"344";options.flashVersion=options.flashVersion||"8";options.expressInstall=options.expressInstall||"";options.flashvars=options.flashvars||{};options.params=options.params||{menu:"false",loop:"false",wmode:"opaque"};options.replaceTime=options.replaceTime||'auto';options.keepLink=options.keepLink||(options.replaceTime=='click');options.wrapper=options.wrapper||'<div class="youtubin-video"></div>';options.autoplay=typeof options.autoplay!='undefined'?options.autoplay:(options.replaceTime=='click');options.srcOptions=options.srcOptions||'?hl=en&fs=1'+(options.autoplay?'&autoplay=1':'');options.method=options.method||'href';options.target=options.target||false;var $box=$(box);if(options.replaceTime=='auto')replaceIt();else if(options.replaceTime=='click')$box.click(function(ev){ev.preventDefault();replaceIt()});function replaceIt(){function checkId($tgt){var boxId=$tgt.attr('id');if(!boxId.length){boxId=getNewId();$tgt.attr('id',boxId)}return boxId}function getNewId(){var boxId='youtubin-'+youtubinCount;youtubinCount++;return boxId}var src=$box.attr(options.method);if(src.substr(0,31)=='http://www.youtube.com/watch?v=')src='http://www.youtube.com/v/'+src.substr(31)+options.srcOptions;if(options.target){var $tgt=options.target;var boxId=checkId($tgt)}else if(options.keepLink){var boxId=getNewId();$box.after($('<div id="'+boxId+'"></div>'));var $tgt=$('#'+boxId);$tgt.css('clear','both')}else{var $tgt=$box;var boxId=checkId($tgt)}switch(youtubinMode){case'2':swfobject.embedSWF(src,boxId,options.swfWidth,options.swfHeight,options.flashVersion,options.expressInstall,options.flashvars,options.params);break;default:$tgt.html('<object width="'+options.swfWidth+'" height="'+options.swfHeight+'"><param name="movie" value="'+src+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+src+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+options.swfWidth+'" height="'+options.swfHeight+'"></embed></object>');break}}};$.fn.youtubin=function(options){this.each(function(){new $.youtubin(options,this)});return this}})(jQuery);
