(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 v=e(this).attr("href");var y;if(g(v)!=null){var r=e("<li></li>");b.append(r);e.getJSON("http://vimeo.com/api/oembed.json/?url="+v+"&callback=?",function(A){var D=A.thumbnail_url;var B=A.title;B=B.substring(0,13)+"...";var z=A.author_name;var C=A.video_id;r.replaceWith("<li><p class='hidden'>vimeo"+C+"</p><img src='"+D+"' alt='thumb'/><h2>"+B+"</h2><p>By <span class='med_spec'>"+z+"</span> On <span class='med_spec'>Vimeo</span></p>");c();k();f()})}else{if(v.indexOf("vimeo")>-1){var u=v.replace("http://vimeo.com/","");e.getJSON("http://vimeo.com/api/v2/"+u+"/videos.json/?callback=?",function(z){e.each(z,function(){var A=e("<li></li>");b.append(A);e.getJSON("http://vimeo.com/api/oembed.json/?url=http://www.vimeo.com/"+this.id+"&callback=?",function(C){var F=C.thumbnail_url;var D=C.title;D=D.substring(0,13)+"...";var B=C.author_name;var E=C.video_id;A.replaceWith("<li><p class='hidden'>vimeo"+E+"</p><img src='"+F+"' alt='thumb'/><h2>"+D+"</h2><p>By <span class='med_spec'>"+B+"</span> On <span class='med_spec'>Vimeo</span></p>");c();k();f()})})})}else{if(v.indexOf("user")>-1){var t=v.replace("http://www.youtube.com/user/","");var s;try{s=t.split("max-results=")[1].split("&")[0]}catch(x){}if(s&&parseFloat(s)>50){for(var w=1;w<s;w=w+50){e.getJSON("http://gdata.youtube.com/feeds/api/videos?v=2&author="+t.split("&")[0]+"&max-results=50&start-index="+w+"&alt=json&callback=?",function(z){e.each(z.feed.entry,function(){var C=this.id.$t;var B=C.indexOf("video:");C=C.substr(B+6,11);var A=e("<li></li>");b.append(A);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+C+"&alt=json&callback=?",function(E){var F=E.feed.entry[0].title.$t;F=F.substring(0,25)+"...";var H=E.feed.entry[0].media$group.media$thumbnail[0].url;var D=E.feed.entry[0].author[0].name.$t;var G=E.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");A.replaceWith("<li><p class='hidden'>youtube"+G+"</p><img src='"+H+"' alt='thumb'/><h2>"+F+"</h2><p>By <span class='med_spec'>"+D+"</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="+t+"&alt=json&callback=?",function(z){e.each(z.feed.entry,function(){var C=this.id.$t;var B=C.indexOf("video:");C=C.substr(B+6,11);var A=e("<li></li>");b.append(A);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+C+"&alt=json&callback=?",function(E){var F=E.feed.entry[0].title.$t;F=F.substring(0,25)+"...";var H=E.feed.entry[0].media$group.media$thumbnail[0].url;var D=E.feed.entry[0].author[0].name.$t;var G=E.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");A.replaceWith("<li><p class='hidden'>youtube"+G+"</p><img src='"+H+"' alt='thumb'/><h2>"+F+"</h2><p>By <span class='med_spec'>"+D+"</span> On <span class='med_spec'>Youtube</span></p>");c();k();f()})})})}}else{y=j(v);e.ajaxSetup({cache:false});var r=e("<li></li>");b.append(r);e.getJSON("http://gdata.youtube.com/feeds/api/videos?q="+y+"&alt=json&callback=?",function(A){var B=A.feed.entry[0].title.$t;B=B.substring(0,25)+"...";var D=A.feed.entry[0].media$group.media$thumbnail[0].url;var z=A.feed.entry[0].author[0].name.$t;var C=A.feed.entry[0].id.$t.replace("http://gdata.youtube.com/feeds/api/videos/","");r.replaceWith("<li><p class='hidden'>youtube"+C+"</p><img src='"+D+"' alt='thumb'/><h2>"+B+"</h2><p>By <span class='med_spec'>"+z+"</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")}});b.css("margin-top","0px");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);
