$(document).ready(function() {    
     $('#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)'               
               });          
          }     
     );
     
    var h = $('div#middle_right').outerHeight() - 78;
    $('div#patient_professional_info').css( 'height', h );

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

    var options = {
      newsList: "#news",
      startDelay: 10,
      loopDelay: 3000,
      placeHolder1: " |",
      placeHolder2: "_"
    }                   
    $().newsTicker(options);                
      $('#news').show();

    $('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/form_buttons/read_more_hover.png' );
      },
      function() {
        $(this).attr( 'src', '/images/form_buttons/read_more.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' } );

    $('ul#switcher li').click(function(event) {
        $('.active').addClass( 'inactive' ).removeClass( 'active' );
        if ( $(this).hasClass( 'inactive' ) ) {
              $(this).removeClass( 'inactive' );
              $(this).addClass( 'active' );
        } else {
              $(this).addClass( 'active' );
        }
        
        // Hide all sections
        $('.info').hide();
        
        // Which section to show?
        var content_to_show = $(this).attr( 'rel' );
        $('#' + content_to_show).fadeIn( 600 );
    });

    // Find a lipidologist form mojo
    $('#Zip').val('Zip Code');  // when the page loads, set the value of the field as a hint to the user.
    $('#Zip').focus(function() { // when the user clicks on it, empty the field value if (only if) it still says, "City."
      if ( $(this).val() == 'Zip Code' ) {
        $(this).val('');
      }
    });
    $('#Zip').blur(function() {
      if ( $(this).val() == '' ) { // If (only if) the field value is empty when the user focuses away from the field, set it back to "City."
        $(this).val('Zip Code');
      } 
    });

    // 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']").attr('target', '_blank');

     //Apply CSS class to all A links that end in .doc
     $("a[href$='.doc'], a[href$='.docx']").addClass("DOC");
     
     //Apply CSS class to all A links that end in .xls
     $("a[href$='.xls'], a[href$='.xlsx']").addClass("XLS");
     
     //Apply CSS class to all A links that end in .ppt
     $("a[href$='.ppt'], a[href$='.pptx']").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");
     
     //Apply CSS class to all A links that start with http://
     $("a[href^='http://']").addClass("ExternalLink");     
     
     //Remove CSS class to all A links that start with http://www.YOURDOMAINHERE.co.uk
     $("a[href^='http://www.lipidfoundation.org']").removeClass("ExternalLink");
     
     //Remove CSS class to all A links that start with http://www.YOURDOMAINHERE.co.uk
     $("a[href^='http://fsdds.dyndns.org']").removeClass("ExternalLink");                   

     // 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'
        });
      }
    );

    // CTA menu interactivity (that couldn't be defined solely with CSS)
    $('ul.actions li').hover(
      function() {
        $(this).find('a').css({color: '#696745'});
      },
      function() {
        $(this).find('a').css({color: '#82805f'});
      }
    );
              
              
    $('#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'
              });
        }
    ); 
    
    $('#carousel').innerfade({         
         speed: 'fast', 
         timeout: 5000, 
         type: 'sequence',
         containerheight: '315px' 
    }); 
});
