$(document).ready(function() {
     // IE6 is not displaying the 24-bit silk icon PNGs correctly. Remove them if running in IE6
     if (!$.support.opacity) {
          $('button span, a.button span').css({
               background:'none',
               paddingLeft: '0px'
          });
     }
     
     $('p:contains("Coming soon")').css({paddingBottom: '50px'});

     $('#sitemap ul li a').hover(
          function() {
               $(this).parent().css({
                    listStyleImage: 'url(/images/sitemap/sitemap_bullet_hover.png)'
               });
          },
          function() {
               $(this).parent().css({
                    listStyleImage: 'url(/images/sitemap/sitemap_bullet.png)'
               });
          }
     );

     if ( $('div#content_wrapper').outerHeight() > $('div#sidebar').outerHeight() ) {
          var contentHeight = $('div#content_wrapper').outerHeight() - 12;
          $('div#sidebar').css( 'height', contentHeight );
     } else if ( $('div#content_wrapper').outerHeight() < $('div#sidebar').outerHeight() ) {
          var sidebarHeight = $('div#sidebar').outerHeight() + 7;
          $('div#content_wrapper').css( 'height', sidebarHeight );
     }

     /*
     $('div#top_nav ul li').each(function() {
          $(this)
          .hide()
          .fadeIn( 2000 );
     });
     */

     $('a[href*="http://"]').attr( 'target', '_blank' );
     $('a[href*="nlaf.dyndns"]').attr( 'target', '_self' );
     $('a[href*="lipidfoundation.org"]').attr( 'target', '_self' );
     $('a[href$=".pdf"]').attr( 'target', '_blank' );

     $('.readMore').hover(
          function() {
               $(this).attr( 'src', '/images/read_more_hover.png' );
          },
          function() {
               $(this).attr( 'src', '/images/read_more.png' );
          }
     );

     $('#donate_now').hover(
          function() {
               $(this).attr( 'src', '/images/form_buttons/donate_now_hover.png' );
          },
          function() {
               $(this).attr( 'src', '/images/form_buttons/donate_now.png' );
          }
     );

     $('#donor_honor_roll').hover(
          function() {
               $(this).attr( 'src', '/images/form_buttons/donor_honor_roll_hover.png' );
          },
          function() {
               $(this).attr( 'src', '/images/form_buttons/donor_honor_roll.png' );
          }
     );

     $('.go').hover(
          function() {
               $(this).attr( 'src', '/images/form_buttons/go_hover.png' );
          },
          function() {
               $(this).attr( 'src', '/images/form_buttons/go.png' );
          }
     );

     $('div#top_nav ul li:contains("|")').css( { color: '#2a2a2a' } );

     // Slide site index - up or down
     $('#sitemap_button').toggle(
          function()
          {
               $('#sitemap_wrapper').animate({
                    height: '150px'
               }, '400', 'easeInOutCirc', function() {
                    $('#sitemap').fadeIn( 300 );
               });
               $('#sitemap_button span.left').css({
                    background: 'url(/images/sitemap/sitemap_left_up.png) 0 0 no-repeat'
               });
               return false;
          },
          function()
          {
               $('#sitemap').fadeOut( 150, function() {
                   $('#sitemap_wrapper').animate({
                        height: '0px'
                   }, '400', 'easeInOutCirc');
               });
               /*
               $('#sitemap').hide( 100, function() {
                   $('#sitemap_wrapper').animate({
                        height: '0px'
                   }, '400', 'easeInOutCirc');
               });
               */
               $('#sitemap_button span.left').css({
                    background: 'url(/images/sitemap/sitemap_left_down.png) 0 0 no-repeat'
               });
               return false;
          }
     );

     $('#sitemap_button').hover(
          function() {
               $('#sitemap_button *').css({
                    color: '#f28383'
               });
          },
          function() {
               $('#sitemap_button *').css({
                    color: '#c95151'
               });
          }
     );

     $('#aboutLink').hover(
          function() {
               $('#aboutLink').css({
                    backgroundColor: '#990000',
                    color: '#fff'
               });
          },
          function() {
               $('#aboutLink').css({
                    backgroundColor: '',
                    color: '#c0c0c0'
               });
          }
     );

     $('#TransMenu0').hover(
          function() {
               $('#aboutLink').css({
                    backgroundColor: '#990000',
                    color: '#fff'
               });
          },
          function() {
               $('#aboutLink').css({
                    backgroundColor: '',
                    color: '#c0c0c0'
               });
          }
     );

     $('form.standard input.text, form.standard textarea, form.standard select').focus(function() {
          $(this).parent().find('label').css({color:'#000'});
     });
     $('form.standard input.text, form.standard textarea, form.standard select').blur(function() {
          $(this).parent().find('label').css({color:'#5f5f5f'});
     });

     $('form.standard div.form_row input[type="text"], form.standard div.form_row textarea, form.standard div.form_row input[type="password"], form.standard div.form_row input[type="file"]').focus(function() {
          $(this).css({backgroundColor:'#eee'});
     });

     $('form.standard div.form_row input[type="text"], form.standard div.form_row textarea, form.standard div.form_row input[type="password"], form.standard div.form_row input[type="file"]').blur(function() {
          $(this).css({backgroundColor:'#f9f9f9'});
     });

     $('div.form_row:last').css({borderBottom:'0px'});

    // Hate on those stupid borders some browsers display on form buttons when you click them
    $('form.small input[type=submit], a').focus(function() {
      $(this).blur();
    });

     // Add file-type icons to links (PDF, MS Word, etc.)
     //Apply CSS class to all A links that end in .pdf
     $("a[href$='.pdf']").addClass("PDF");

     // Force all links to PDF documents to load in a new window
     $("a[href$='.pdf'], a[href$='.xls'], a[href$='.xlsx'], a[href$='.doc'], a[href$='.docx'], a[href$='.ods'], a[href$='.odt']").attr('target', '_blank');

     //Apply CSS class to all A links that end in .doc
     $("a[href$='.doc'], a[href$='.docx'], a[href$='.odt']").addClass("DOC");

     //Apply CSS class to all A links that end in .xls or .xlsx
     $("a[href$='.xls'], a[href$='.xlsx'], a[href$='.ods']").addClass("XLS");

     //Apply CSS class to all A links that end in .ppt
     $("a[href$='.ppt'], a[href$='.pptx'], a[href$='.odp']").addClass("PPT");

     //Apply CSS class to all A links that end in .jpg
     $("a[href$='.jpg']").addClass("Image");

     //Apply CSS class to all A links that end in .gif
     $("a[href$='.gif']").addClass("Image");

     //Apply CSS class to all A links that end in .png
     $("a[href$='.png'").addClass("Image");

     // Remove PDF class from all anchors that contain an image tag
     $("a[href$='.pdf']:has(img)").removeClass('PDF');

     //Apply CSS class to all A links that start with mailto:
     $("a[href^='mailto:']").addClass("Mail");

     // Place the page heading and subheading before any messages that are to be displayed to the user.
     if (  $('h1.grant_heading').next().hasClass('grant_application') ) { // We are on a form page
        $('h2.grant_application').after( $('#notice') );
        $('h2.grant_application').after( $('#error') );
        $('h2.grant_application').after( $('#success') );
     } else { // We are on a non-form page (i.e. the login page, or the grant overview page).
        $('h1.grant_heading').after( $('#notice') );
        $('h1.grant_heading').after( $('#error') );
        $('h1.grant_heading').after( $('#success') );
     }



     // Zebra stripe the grants overview table
     $('#grants_overview tr:odd').css({borderTop:'1px solid #ddd'});
     $('#grants_overview tr:odd').css({borderBottom:'1px solid #ddd'});
     $('#grants_overview tr:odd td').css({
          'background-color':'#f0f0f0',
          'border-right':'2px solid #fff',
          'border-bottom':'1px solid #ddd'
     });
     $('#grants_overview tr:odd td:has("img")').css({backgroundColor:'#fff'});

     // Hover state for help overlay icons
     $('.helpButton').hover(
        function() {
            $(this).addClass('ui-state-hover');
        },
        function() {
            $(this).removeClass('ui-state-hover');
        }
     );
});
