/**
 * Unobtrusive scripting adapter for jQuery
 *
 * Requires jQuery 1.6.0 or later.
 * https://github.com/rails/jquery-ujs

 * Uploading file using rails.js
 * =============================
 *
 * By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
 * in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
 *
 * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
 *
 * Ex:
 *     $('form').live('ajax:aborted:file', function(event, elements){
 *       // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
 *       // Returning false in this handler tells rails.js to disallow standard form submission
 *       return false;
 *     });
 *
 * The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
 *
 * Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
 * techniques like the iframe method to upload the file instead.
 *
 * Required fields in rails.js
 * ===========================
 *
 * If any blank required inputs (required="required") are detected in the remote form, the whole form submission
 * is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
 *
 * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
 *
 * !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
 *    get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
 *
 * Ex:
 *     $('form').live('ajax:aborted:required', function(event, elements){
 *       // Returning false in this handler tells rails.js to submit the form anyway.
 *       // The blank required inputs are passed to this function in `elements`.
 *       return ! confirm("Would you like to submit the form with missing info?");
 *     });
 */
function populatePlaylists(){$("#youtube-playlists").html('<table id="youtube-playlists-table"><tbody></tbody></table>'),$.playlists={};var a="http://gdata.youtube.com/feeds/api/users/"+$.youtubeUser+"/playlists?v=2&alt=jsonc";$.getJSON(a,function(a){var b=a.data.items;for(var c=b.length-1;c>=0;--c)populatePlaylistVideos(b[c]),$("#youtube-playlists-table tbody").append('<tr class="playlist" id="playlist-'+b[c].id+'"><td class="playlist-image"></td><td>'+playlistData(b[c])+"</td></tr>")})}function recursivePlaylistVideos(a,b){var c="http://gdata.youtube.com/feeds/api/playlists/"+a.id+"?v=2&alt=jsonc";b!=0&&(c+="&start-index="+b*25),$.getJSON(c,function(c){for(var d=0;d<c.data.items.length;d++){var e=c.data.items[d].video;temp=new Object,temp.description=e.description,temp.permalink=e.player["default"],temp.title=e.title,temp.thumbnail=e.thumbnail.sqDefault,temp.id=e.id,temp.date=e.uploaded,$.playlists[a.id].push(temp)}c.data.items.length==25?recursivePlaylistVideos(a,b+1):$.playlists[a.id].length>0?$("tr#playlist-"+a.id+" .playlist-image").html('<img src="'+$.playlists[a.id][0].thumbnail+'" />'):$("tr#playlist-"+a.id).hide()})}function populatePlaylistVideos(a){$.playlists[a.id]=[],recursivePlaylistVideos(a,0)}function playlistData(a){return'<div class="playlist-title">'+a.title+"</div>"}function switchLightboxVideo(a){var b=a.attr("id").split("--"),c=b[1],d=b[2];populateLightboxVideo($.playlists[d][c])}function populateLightboxVideo(a){var b="http://www.youtube.com/v/"+a.id,c='<div id="embed-video"><object type="application/x-shockwave-flash" data="'+b+'"><param name="movie" value="'+b+'" /></object></div>',d='<div id="video-data"><div id="video-title">'+a.title+'</div><div id="video-description">'+a.description+"</div></div>";$("#view-playlist-video").html(c+d)}function generateVideoListing(a,b,c){var d="video--"+b+"--"+c;return'<tr class="carousel-video" id="'+d+'"><td class="video-carousel-image"><img src="'+a.thumbnail+'" /></td><td><div class="playlist-title">'+a.title+"</div></td></tr>"}function showCurrentCarouselSelection(){if($("#video-carousel tbody tr").length<4){$("#video-carousel tfoot").hide(),$("#video-carousel thead").hide();for(var a=$.svi;a<$.evi;++a)$("#video-carousel tbody tr:eq("+a+")").show()}else for(var a=$.svi;a!=$.evi;a=wrap(a,1))$("#video-carousel tbody tr:eq("+a+")").show()}function wrap(a,b){return a+=b,a<0?a=$("#video-carousel tbody tr").length+a:a=a%$("#video-carousel tbody tr").length,a}function moveCarousel(a){for(var b=$.svi;b!=$.evi;b=wrap(b,1))$("#video-carousel tbody tr:eq("+b+")").hide();$.svi=wrap($.svi,a),$.evi=wrap($.evi,a),showCurrentCarouselSelection()}function populateLightboxVideoCarousel(a,b){$.svi=0,$.evi=a.length>4?4:a.length;var c='<table id="video-carousel"><thead><td id="carousel-up" colspan="2"><img src="/uparrow.gif" /></td></thead><tbody>';for(var d=0;d<a.length;++d)c+=generateVideoListing(a[d],d,b);c+='</tbody><tfoot><td colspan="2" id="carousel-down"><img src="/downarrow.gif" /></td></tfoot></table>',$("#view-playlist-carousel").html(c),showCurrentCarouselSelection()}function prepareLightbox(a){var b=$.playlists[a];$("#lightbox-content").html('<table id="view-playlist-table"><tr><td id="view-playlist-video"></td><td id="view-playlist-carousel"></td></tr></table>'),populateLightboxVideo(b[0]),populateLightboxVideoCarousel(b,a)}function openPlaylist(a){var b=a.attr("id").substring(9);prepareLightbox(b),showLightbox()}function outsideLightboxContent(a,b){var c=$("#lightbox-content").position(),d=c.left,e=c.top,f=d+$("#lightbox-content").outerWidth(),g=e+$("#lightbox-content").outerHeight();return a<d||b<e||b>g||a>f}function getBrowser(){return ret="",$.each($.browser,function(a,b){ret+=a+" ("+b+") "}),ret}function initMap(){$.locations=$.parseJSON($.locations),$.gmap=new google.maps.Map(document.getElementById("map"),{zoom:8,center:new google.maps.LatLng($.locations[0].latitude,$.locations[0].longitude),mapTypeId:google.maps.MapTypeId.ROADMAP});for(var a=0;a<$.locations.length;++a){var b=new google.maps.Marker({position:new google.maps.LatLng($.locations[a].latitude,$.locations[a].longitude),map:$.gmap}),c=new google.maps.InfoWindow;google.maps.event.addListener(b,"click",function(a,b){return function(){c.setContent('<div class="marker-html">'+$.locations[b].place+"</div>"),c.open($.gmap,a)}}(b,a))}}function calculate_tweet_quantity(){var a=$("#container").height();return a-=$("#non-twitter").outerHeight(),a-=50,Math.ceil(Math.min(3,a/200))}function process_tweet(a){var b=a.text;if(a.in_reply_to_screen_name){var c=a.in_reply_to_screen_name;b=b.replace("@"+c,"<a target='_blank' href='http://twitter.com/"+c+"'>@"+c+"</a>")}return b=b.replace(/http:\/\/t\.co\/[a-zA-Z0-9]+/g,"<a target='_blank' href='$&'>$&</a>"),b}function tweet(a){return $('<div class="tweet">'+process_tweet(a)+"</div>")}function twitter_callback(a){for(var b=0;b<a.length;++b)$("#twitter-feed").append(tweet(a[b])),$("#twitter-feed").append("<div class='tweet-hr'></div>");$("#twitter-feed").append("<div class='tweet'>Follow us on <a href='http://twitter.com/mmrambotics' target='_blank'>Twitter</a>!</div>")}function incrementAd(){$.currentAd++,$.currentAd=$.currentAd%$.numberOfAds}function adSelector(){return".rotating-ad:nth-child("+($.currentAd+1)+")"}function showNextAd(){$(adSelector()).removeClass("visible"),incrementAd(),$(adSelector()).addClass("visible")}function showLightbox(){setTimeout('$("#lightbox-content").show()',500),$("#lightbox").fadeIn(1e3),window.location="#lightbox"}function hideLightbox(){setTimeout('$("#lightbox-content").hide()',200),$("#lightbox").fadeOut()}(function(a,b){var c;a.rails=c={linkClickSelector:"a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]",inputChangeSelector:"select[data-remote], input[data-remote], textarea[data-remote]",formSubmitSelector:"form",formInputClickSelector:"form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])",disableSelector:"input[data-disable-with], button[data-disable-with], textarea[data-disable-with]",enableSelector:"input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled",requiredInputSelector:"input[name][required]:not([disabled]),textarea[name][required]:not([disabled])",fileInputSelector:"input:file",linkDisableSelector:"a[data-disable-with]",CSRFProtection:function(b){var c=a('meta[name="csrf-token"]').attr("content");c&&b.setRequestHeader("X-CSRF-Token",c)},fire:function(b,c,d){var e=a.Event(c);return b.trigger(e,d),e.result!==!1},confirm:function(a){return confirm(a)},ajax:function(b){return a.ajax(b)},handleRemote:function(d){var e,f,g,h=d.data("cross-domain")||null,i=d.data("type")||a.ajaxSettings&&a.ajaxSettings.dataType,j;if(c.fire(d,"ajax:before")){if(d.is("form")){e=d.attr("method"),f=d.attr("action"),g=d.serializeArray();var k=d.data("ujs:submit-button");k&&(g.push(k),d.data("ujs:submit-button",null))}else d.is(c.inputChangeSelector)?(e=d.data("method"),f=d.data("url"),g=d.serialize(),d.data("params")&&(g=g+"&"+d.data("params"))):(e=d.data("method"),f=d.attr("href"),g=d.data("params")||null);j={type:e||"GET",data:g,dataType:i,crossDomain:h,beforeSend:function(a,e){return e.dataType===b&&a.setRequestHeader("accept","*/*;q=0.5, "+e.accepts.script),c.fire(d,"ajax:beforeSend",[a,e])},success:function(a,b,c){d.trigger("ajax:success",[a,b,c])},complete:function(a,b){d.trigger("ajax:complete",[a,b])},error:function(a,b,c){d.trigger("ajax:error",[a,b,c])}},f&&(j.url=f),c.ajax(j)}},handleMethod:function(c){var d=c.attr("href"),e=c.data("method"),f=a("meta[name=csrf-token]").attr("content"),g=a("meta[name=csrf-param]").attr("content"),h=a('<form method="post" action="'+d+'"></form>'),i='<input name="_method" value="'+e+'" type="hidden" />';g!==b&&f!==b&&(i+='<input name="'+g+'" value="'+f+'" type="hidden" />'),h.hide().append(i).appendTo("body"),h.submit()},disableFormElements:function(b){b.find(c.disableSelector).each(function(){var b=a(this),c=b.is("button")?"html":"val";b.data("ujs:enable-with",b[c]()),b[c](b.data("disable-with")),b.attr("disabled","disabled")})},enableFormElements:function(b){b.find(c.enableSelector).each(function(){var b=a(this),c=b.is("button")?"html":"val";b.data("ujs:enable-with")&&b[c](b.data("ujs:enable-with")),b.removeAttr("disabled")})},allowAction:function(a){var b=a.data("confirm"),d=!1,e;return b?(c.fire(a,"confirm")&&(d=c.confirm(b),e=c.fire(a,"confirm:complete",[d])),d&&e):!0},blankInputs:function(b,c,d){var e=a(),f,g=c||"input,textarea";return b.find(g).each(function(){f=a(this);if(d?f.val():!f.val())e=e.add(f)}),e.length?e:!1},nonBlankInputs:function(a,b){return c.blankInputs(a,b,!0)},stopEverything:function(b){return a(b.target).trigger("ujs:everythingStopped"),b.stopImmediatePropagation(),!1},callFormSubmitBindings:function(c){var d=c.data("events"),e=!0;return d!==b&&d.submit!==b&&a.each(d.submit,function(a,b){if(typeof b.handler=="function")return e=b.handler(b.data)}),e},disableElement:function(a){a.data("ujs:enable-with",a.html()),a.html(a.data("disable-with")),a.bind("click.railsDisable",function(a){return c.stopEverything(a)})},enableElement:function(a){a.data("ujs:enable-with")!==b&&(a.html(a.data("ujs:enable-with")),a.data("ujs:enable-with",!1)),a.unbind("click.railsDisable")}},a.ajaxPrefilter(function(a,b,d){a.crossDomain||c.CSRFProtection(d)}),a(c.linkDisableSelector).live("ajax:complete",function(){c.enableElement(a(this))}),a(c.linkClickSelector).live("click.rails",function(d){var e=a(this);if(!c.allowAction(e))return c.stopEverything(d);e.is(c.linkDisableSelector)&&c.disableElement(e);if(e.data("remote")!==b)return c.handleRemote(e),!1;if(e.data("method"))return c.handleMethod(e),!1}),a(c.inputChangeSelector).live("change.rails",function(b){var d=a(this);return c.allowAction(d)?(c.handleRemote(d),!1):c.stopEverything(b)}),a(c.formSubmitSelector).live("submit.rails",function(d){var e=a(this),f=e.data("remote")!==b,g=c.blankInputs(e,c.requiredInputSelector),h=c.nonBlankInputs(e,c.fileInputSelector);if(!c.allowAction(e))return c.stopEverything(d);if(g&&e.attr("novalidate")==b&&c.fire(e,"ajax:aborted:required",[g]))return c.stopEverything(d);if(f)return h?c.fire(e,"ajax:aborted:file",[h]):!a.support.submitBubbles&&c.callFormSubmitBindings(e)===!1?c.stopEverything(d):(c.handleRemote(e),!1);setTimeout(function(){c.disableFormElements(e)},13)}),a(c.formInputClickSelector).live("click.rails",function(b){var d=a(this);if(!c.allowAction(d))return c.stopEverything(b);var e=d.attr("name"),f=e?{name:e,value:d.val()}:null;d.closest("form").data("ujs:submit-button",f)}),a(c.formSubmitSelector).live("ajax:beforeSend.rails",function(b){this==b.target&&c.disableFormElements(a(this))}),a(c.formSubmitSelector).live("ajax:complete.rails",function(b){this==b.target&&c.enableFormElements(a(this))})})(jQuery),$(function(){$("#youtube-playlists").length==1&&($.youtubeUser="mmrambotics",populatePlaylists(),$("tr.playlist").live("click",function(){openPlaylist($(this))}),$("#carousel-up").live("click",function(){moveCarousel(-4)}),$("#carousel-down").live("click",function(){moveCarousel(4)}),$(".carousel-video").live("click",function(){switchLightboxVideo($(this))}))}),$(function(){$("#albums-thumb-button").click(function(a){return $("#albums-thumbnails").css("display")=="none"&&($("#albums-listing").slideUp(500),$("#albums-thumbnails").slideDown(500)),!1}),$("#albums-list-button").click(function(a){return $("#albums-listing").css("display")=="none"&&($("#albums-thumbnails").slideUp(500),$("#albums-listing").slideDown(500)),!1}),$("#albums-thumbnails .image").hover(function(){$("#album-header-info").html($(this).children("a:first").attr("title"))},function(){$("#album-header-info").html("")})}),$(function(){$("#next-photo").attr("data-remote",!0),$("#prev-photo").attr("data-remote",!0)}),$(function(){$("#feedback-anchor").click(function(){return $("#feedback-form").fadeIn(500),$("#feedback-browser").val(getBrowser()),$("#feedback-os").val(navigator.userAgent),$("#feedback-width").val($(window).width()),$("#feedback-height").val($(window).height()),!1})}),$(function(){if($("#twitter-feed").length==1){var a=calculate_tweet_quantity();$("<script src='http://api.twitter.com/1/statuses/user_timeline.json?screen_name=mmrambotics&count="+a+"&callback=twitter_callback'></script>").appendTo("body"),$("#twitter-feed").show()}}),$(function(){$(".rotating-ad").length>=1&&($.currentAd=-1,$.numberOfAds=$(".rotating-ad").length,showNextAd(),setInterval(showNextAd,3e3)),$("#bar").click(function(){$("#slide-down").slideToggle(1e3)}),$("#lightbox-header").click(function(){hideLightbox()}),$("#postings-hr").click(function(){$("#slide-down").slideToggle(1e3)}),$("#lightbox").click(function(a){outsideLightboxContent(a.pageX,a.pageY)&&hideLightbox()}),$(document).click(function(a){$("#slide-down").css("display")!="none"&&a.pageY>$("#slide-down").position().top+$("#slide-down").outerHeight()&&$("#slide-down").slideToggle(1e3);if($("#feedback-form").css("display")!="none"){if($(a.target).is("select"))return;(a.pageY<$("#feedback-form").position().top||a.pageX<$("#feedback-form").position().left)&&$("#feedback-form").fadeOut()}}),$(".tabs").each(function(){$(this).tabs()})})
