(function(e){var d={autoplay:1};var n;var b;var i;var l;var m,h;var a;e.fn.extend({mediaGallery:function(o){return this.each(function(){var q='<div id="mediagallery_video_wrap"><div id="mediagallery_video"><div id="media_gallery_inner_vid"></div></div><div id="mediagallery_video_descr"><h1></h1><p></p></div></div><div id="mediagallery_more"><div id="mediagallery_list"><ul id="med_list_cont"></ul></div><div id="mediagallery_scroll"></div><div id="mediagallery_scroll_hor"></div></div>';e.extend(d,o);var p="";e(this).append(q);b=e("#med_list_cont");i=e("#mediagallery_scroll");l=e("#mediagallery_scroll_hor");m=e("#mediagallery_video_descr").find("h1");h=e("#mediagallery_video_descr").find("p");a=e("#mediagallery_video");e(this).find("a").each(function(){var t=e(this).attr("href");var w;if(g(t)!=null){e.getJSON("http://vimeo.com/api/oembed.json/?url="+t+"&callback=?",function(y){var B=y.thumbnail_url;var z=y.title;z=z.substring(0,13)+"...";var x=y.author_name;var A=y.video_id;b.append("<li><p class='hidden'>vimeo"+A+"</p><img src='"+B+"' alt='thumb'/><h2>"+z+"</h2><p>By <span class='med_spec'>"+x+"</span> On <span class='med_spec'>Vimeo</span></p>");c();k();f()})}else{if(t.indexOf("user")>-1){var s=t.replace("http://www.youtube.com/user/","");var r;try{r=s.split("max-results=")[1].split("&")[0]}catch(v){}if(r&&parseFloat(r)>50){for(var u=1;u<r;u=u+50){e.getJSON("http://gdata.youtube.com/feeds/api/videos?v=2&author="+s.split("&")[0]+"&max-results=50&start-index="+u+"&alt=json&callback=?",function(x){e.each(x.feed.entry,function(){var z=this.id.$t;var y=z.indexOf("video:");z=z.substr(y+6,11);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+z+"&alt=json&callback=?",function(B){var C=B.feed.entry[0].title.$t;C=C.substring(0,25)+"...";var E=B.feed.entry[0].media$group.media$thumbnail[0].url;var A=B.feed.entry[0].author[0].name.$t;var D=B.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");b.append("<li><p class='hidden'>youtube"+D+"</p><img src='"+E+"' alt='thumb'/><h2>"+C+"</h2><p>By <span class='med_spec'>"+A+"</span> On <span class='med_spec'>Youtube</span></p>");c();k();f()})})})}}else{e.getJSON("http://gdata.youtube.com/feeds/api/videos?v=2&author="+s+"&alt=json&callback=?",function(x){e.each(x.feed.entry,function(){var z=this.id.$t;var y=z.indexOf("video:");z=z.substr(y+6,11);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+z+"&alt=json&callback=?",function(B){var C=B.feed.entry[0].title.$t;C=C.substring(0,25)+"...";var E=B.feed.entry[0].media$group.media$thumbnail[0].url;var A=B.feed.entry[0].author[0].name.$t;var D=B.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");b.append("<li><p class='hidden'>youtube"+D+"</p><img src='"+E+"' alt='thumb'/><h2>"+C+"</h2><p>By <span class='med_spec'>"+A+"</span> On <span class='med_spec'>Youtube</span></p>");c();k();f()})})})}}else{w=j(t);e.ajaxSetup({cache:false});e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+w+"&alt=json",function(y){var z=y.feed.entry[0].title.$t;z=z.substring(0,25)+"...";var B=y.feed.entry[0].media$group.media$thumbnail[0].url;var x=y.feed.entry[0].author[0].name.$t;var A=y.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");b.append("<li><p class='hidden'>youtube"+A+"</p><img src='"+B+"' alt='thumb'/><h2>"+z+"</h2><p>By <span class='med_spec'>"+x+"</span> On <span class='med_spec'>Youtube</span></p>");c();k();f()})}}e(this).remove()})})}});function k(){i.slider({orientation:"vertical",range:"max",min:0,value:b.height(),max:b.height(),slide:function(o,p){b.css("margin-top",(((b.height()-p.value)/2)*-1)+"px")},change:function(o,p){b.css("margin-top",(((b.height()-p.value)/2)*-1)+"px")}});l.slider({range:"max",min:0,value:0,max:b.width(),slide:function(o,p){b.css("margin-left",(((0+p.value))*-1)+"px")},change:function(o,p){b.css("margin-left",(((0+p.value))*-1)+"px")}});e("#med_list_cont , #mediagallery_more").mousewheel(function(o,r){var q=5;var p=i.slider("value");p+=(r*q);i.slider("value",p);o.preventDefault()});if(l.css("display")=="none"){}else{e("#mediagallery_list").css("width",(e("#med_list_cont li").size()*130)+"px")}}function f(){if(m.text()==""){m.text(" ");e("#med_list_cont li:first").find("img").click()}}function g(q){var p=/http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;var o=q.match(p);if(o!=null){return o[2]}else{return null}}function c(){var o=b.find("li");o.unbind("click");o.unbind("hover");o.hover(function(){e(this).addClass("med_active")},function(){e(this).removeClass("med_active")});o.click(function(){a.html("");a.append("<div id='media_gallery_inner_vid'></div>");var t=e(this);e(".med_current").removeClass("med_current");t.addClass("med_current");var v=e(this).find(".hidden").text();if(v.indexOf("youtube")>-1){v=v.replace("youtube","");var s={allowScriptAccess:"always",wmode:"opaque"};var u={id:"myytplayer"};swfobject.embedSWF("http://www.youtube.com/e/"+v+"?enablejsapi=1&playerapiid=ytplayer&autohide=1&autoplay="+d.autoplay,"media_gallery_inner_vid",a.width()+"",a.height()+"","8",null,null,s,u);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+v+"&alt=json&callback=?",function(w){m.text(w.feed.entry[0].title.$t);h.text(w.feed.entry[0].media$group.media$description.$t)})}else{if(v.indexOf("vimeo")>-1){v=v.replace("vimeo","");var p={clip_id:v,server:"vimeo.com",show_title:0,show_byline:0,show_portrait:0,fullscreen:1,js_api:1,autoplay:d.autoplay};var q={swliveconnect:true,fullscreen:1,allowscriptaccess:"always",allowfullscreen:true};var r={};r.id="vid";swfobject.embedSWF("http://www.vimeo.com/moogaloop.swf","media_gallery_inner_vid",a.width()+"",a.height()+"","9.0.28","",p,q,r);e.getJSON("http://vimeo.com/api/oembed.json/?url=http://www.vimeo.com/"+v+"&callback=?",function(w){m.text(w.title);h.text(w.description)})}}})}function j(q){var p=11;var o;var r=q.indexOf("?v=");if(!r){r=q.indexOf("&v=")}if(!r){return null}return q.substr(r+3,p)}})(jQuery);
