jQuery document.ready not working
<p>I've been working on this for a couple of days now and have been unable to find a solution. Basically, I have to JS scripts in my head that won't execute the <code>$(document).ready(...)</code>. The strange thing is that I have other scripts that work with it just fine. Here are the two I am having problems with: (I've added a couple comments about what I have tried)</p>

<pre><code>&lt;% content_for(:head) do %&gt;
&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
        $('.button-print-ticket').click(function(e) {
            e.preventDefault();
            var header = $('.social-header');
            header.queue(function() {
              var search_string ='#map-canvas img[src=https://maps.gstatic.com/mapfiles/google_white.png]';
              var glink = $(search_string).parent().parent();
              glink.replaceWith(glink.html());
              $(this).dequeue();
            });
            header.hide();
            header.queue(function() {
              window.print();
              $(this).dequeue();
            });
            header.queue(function() {
              $('.social-header').show();
              $(search_string).parent().replaceWith(glink);
              $(this).dequeue();
            });
        });
    });
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//an alert here works
if(screen.width &gt;= 800) {
  //an alert here works too
  $(document).ready(function() {
    //an alert here only works in the console
    $(document).ready(function(){
      $('#overlay').fadeIn('fast',function(){
          $('#box').animate({'top':'160px'},500);
      });
    });
    $('#boxclose, #bt-fbshare, #bt-tweet, #bt-email').click(function(){
        $('#box').hide("drop", { direction: "up" }, 100, function(){
            $('#overlay').fadeOut('fast');
        });
    });
    $(document).keyup(function(e) {
      if (e.keyCode == 27){
         $('#box').hide("drop", { direction: "up" }, 100, function(){
             $('#overlay').fadeOut('fast');
         });
      }
    });

  });
}
&lt;/script&gt;
&lt;% end %&gt;
</code></pre>

<p>I also included the Ruby On Rails tag because it is the only difference that I can discern. (The JS IS shown in Firebug) I don't have an <code>onload</code> in my <code>&lt;body&gt;</code> tag either. Another oddity is that it used to work and I don't recall making any changes to either of these scripts.</p>

<p>Edit 2:
One other thing: I can also put <code>console.log($)</code> just before <code>if (screen-width &gt;= 800)</code> and it tells me that <code>$</code> is a function.</p>

<p>Edit:
Here is the generated HTML:</p>

<pre><code>&lt;head&gt;
&lt;style type="text/css"&gt;@media print {  .gmnoprint {    display:none  }}@media screen {  .gmnoscreen {    display:none  }}&lt;/style&gt;
&lt;title&gt;Web Page&lt;/title&gt;

&lt;meta content="text/html;charset=UTF-8" http-equiv="content-type"/&gt;
&lt;meta content="ALL" name="robots"/&gt;
&lt;meta content="5 Days" name="revisit-after"/&gt;
&lt;meta content="EN" name="language"/&gt;
&lt;meta charset="utf-8"/&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale = 1.0"/&gt;


&lt;link type="text/css" rel="stylesheet" media="screen, projection, print" href="/stylesheets/screen.css?1347374478"/&gt;
&lt;link type="text/css" rel="stylesheet" media="screen, projection, print" href="/stylesheets/global.css?1346943598"/&gt;
&lt;link type="text/css" rel="stylesheet" media="print" href="/stylesheets/print.css?1343928684"/&gt;

&lt;!--[if lt IE 9]&gt;
&lt;script src="//html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;

&lt;!--[if lte IE 7]&gt;&lt;link href="/stylesheets/ie7.css?1343928684" media="screen, projection" rel="stylesheet" type="text/css" /&gt;&lt;![endif]--&gt;
&lt;!--[if !IE]&gt;&lt;link href="/stylesheets/media.css?1343928684" media="screen, projection" rel="stylesheet" type="text/css" /&gt;&lt;![endif]--&gt;

&lt;script type="text/javascript" src="/javascripts/jquery.min.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/jquery.ui.min.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/jquery.ajax-submit.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/modernizr-2.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/date.format.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/geo.js?1343928684"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/spin.min.js?1343928684"&gt;&lt;/script&gt;&lt;style&gt;&lt;/style&gt;
&lt;script type="text/javascript" src="/javascripts/application.js?1347326686"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/javascripts/global.js?1345692570"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
    var logged_in = true;

    $(function() {
        if (logged_in) {
            $('.signed-in').show();
            $('.signed-out').hide();
        } else {
            $('.signed-in').hide();
            $('.signed-out').show();
        }

        $('.sign-out-link').click(function(e) {
            e.preventDefault();
            $('.signed-in').hide();
            $('.signed-out').show();
            logged_in = false;e
            window.location='/customers/destroy_session';
        });
    });
&lt;/script&gt;
&lt;!--&lt;script type="text/javascript"&gt;

document.write(unescape("%3Cscript src='" + ((document.location.protocol=="https:")?"https://snapabug.appspot.com":"http://www.snapengage.com") + "/snapabug.js' type='text/javascript'%3E%3C/script%3E"));&lt;/script&gt;&lt;script type="text/javascript"&gt;

SnapABug.addButton("--------","0","55%");

&lt;/script&gt;--&gt;

&lt;style type="text/css"&gt;
    #map-canvas { width : 100%; height: 100%; }
&lt;/style&gt;
&lt;script src="https://maps.googleapis.com/maps/api/js?v=3&amp;amp;sensor=true" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript" src="https://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/14/main.js"&gt;&lt;/script&gt;
&lt;script src="/javascripts/google.maps.styled-marker.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

    var directionsDisplay;  
    var directionsService = new google.maps.DirectionsService();
    var venueMarker = new google.maps.Marker;
    var pu_map;

    var map;
    $(function() {
        var latlng = new google.maps.LatLng(40.256676, -111.644755);
        var mapOptions = {
            zoom                : 13,
            center              : latlng,
            mapTypeId           : google.maps.MapTypeId.ROADMAP,
            disableDefaultUI    : true,
            zoomControl         : true
        };
        map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

        new google.maps.Marker({
            position : latlng,
            map : map
        });

    });

    $(function() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var latlng = new google.maps.LatLng(40.256676, -111.644755);
        var mapOptions = {
            zoom                : 13,
            center              : latlng,
            mapTypeId           : google.maps.MapTypeId.ROADMAP,
            disableDefaultUI    : true,
            zoomControl         : true
        };
        pu_map = new google.maps.Map(document.getElementById("popup_map_cont"), mapOptions);
        directionsDisplay.setMap(pu_map);
    });

&lt;/script&gt;



&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
        $('.button-print-ticket').click(function(e) {
            e.preventDefault();
            var header = $('.social-header');
            header.queue(function() {
                var search_string ='#map-canvas img[src=https://maps.gstatic.com/mapfiles/google_white.png]';
                var glink = $(search_string).parent().parent();
                glink.replaceWith(glink.html());
                $(this).dequeue();
            });
            header.hide();
            header.queue(function() {
                window.print();
                $(this).dequeue();
            });
            header.queue(function() {
                $('.social-header').show();
                $(search_string).parent().replaceWith(glink);
                $(this).dequeue();
            });
        });
    });
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    if(screen.width &gt;= 800) {
        $(document).ready(function() {
            $(document).ready(function(){
                $('#overlay').fadeIn('fast',function(){
                    $('#box').animate({'top':'160px'},500);
                });
            });
            $('#boxclose, #bt-fbshare, #bt-tweet, #bt-email').click(function(){
                $('#box').hide("drop", { direction: "up" }, 100, function(){
                    $('#overlay').fadeOut('fast');
                });
            });
            $(document).keyup(function(e) {
                if (e.keyCode == 27){
                    $('#box').hide("drop", { direction: "up" }, 100, function(){
                        $('#overlay').fadeOut('fast');
                    });
                }
            });

        });
    }
&lt;/script&gt;

&lt;script type="text/javascript" charset="UTF-8" src="https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/9/14/%7Bcommon,util,marker%7D.js"&gt;&lt;/script&gt;&lt;script type="text/javascript" charset="UTF-8" src="https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/9/14/%7Bmap%7D.js"&gt;&lt;/script&gt;&lt;script type="text/javascript" charset="UTF-8" src="https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/9/14/%7Bonion%7D.js"&gt;&lt;/script&gt;&lt;script type="text/javascript" charset="UTF-8" src="https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/9/14/%7Bcontrols%7D.js"&gt;&lt;/script&gt;&lt;script type="text/javascript" charset="UTF-8" src="https://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/9/14/%7Bstats%7D.js"&gt;&lt;/script&gt;&lt;script async="true" type="text/javascript" src="http://a.adroll.com/j/roundtrip.js"&gt;&lt;/script&gt;
</code></pre>

<p></p>
