// JavaScript Document


$(document).ready(function() {

     $('ul.sf-menu').superfish();

     //PNG Fix
     $(document).pngFix(); 
     
     //Background Fix on Window Resize
     $(window).wresize( resizeWindow );
     resizeWindow();
    
     lastBlock = $("#a1");
     maxWidth = 498;
     minWidth = 52;	

     $("ul li div.ani").click (
          function(){
          
               $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
               $(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
               
               //update active img          
               var lsrc = $(lastBlock).find(".atab img").attr('src');
               lsrc = lsrc.replace("-active.jpg",".jpg");
               $(lastBlock).find(".atab img").attr('src', lsrc);
               
               var tsrc = $(this).find(".atab img").attr('src');
               tsrc = tsrc.replace(".jpg","-active.jpg");
               $(this).find(".atab img").attr('src', tsrc);
               
               lastBlock = this;
          }
     );
    
     /*
     jQuery(".atab img").click(
          function()
          {
               this.src = this.src.replace(".jpg","-active.jpg");
          },
          function()
          {
               this.src = this.src.replace("-active.jpg",".jpg");
          }
     );
     */
     
     ///////////////////////////////////////////////////////////
     // Top Links default, hide popovers  
     $('.topnav a').mouseover(function() {
          $('.cu-struct').hide();
          $('.ql-struct').hide();
     });

     // Contact Us Popover
     $('#cu').mouseover(function() {
          $('.cu-struct').show();
          $('.ql-struct').hide();
     });
     
     $('.cu-pop').mouseleave(function() {
          $('.cu-struct').hide();
     });
     
     // Quick Links Popover
     $('#ql').mouseover(function() {
          $('.cu-struct').hide();
          $('.ql-struct').show();
     });
     
     $('.ql-pop').mouseleave(function() {
          $('.ql-struct').hide();
     });
     
     $('div.topsearch').mouseover(function() {
          $('.cu-struct').hide();
          $('.ql-struct').hide();
     });
     
     ///////////////////////////////////////////////////////////
     // Search Box      
     $('#q').each(function() {
          var default_value = this.value;
          $(this).focus(function() {
               if(this.value == default_value) {
               this.value = '';
          }
          });
          
          $(this).blur(function() {
               if(this.value == '') {
               this.value = default_value;
          }
          });
     });
     
     $('.searchbtn img').click( enterSearch );
     $('#q').keyup(function(e) {
          if(e.keyCode == 13) {
               enterSearch();
          }
     });



     // STAFF Page
     $('select#dp').change(function() {
          window.location = $(this).val();
     });

     

});

/**
 * activate search bar
 */ 
function enterSearch(){
     var search_val = $('#q').val();
     if( search_val != '' ){
          window.location = "/fm/search/?query="+escape(search_val);
     }
}


/**
 * this function fixes the floating background on 
 * the div.struct and body tags when the browser resolution
 * is smaller than 1017 (site width)  
 */ 
function resizeWindow() {
  var new_width = $(window).width();
  if( new_width < 1017 ) {
     //fix background
     $('.struct').css('background-position','-265px 0px');
     $('.struct').css('width','1017px');
     $('.topstruct').css('width','1017px');
     $('body').css('background-position','-265px 0px');
  } else {
     $('.struct').css('background-position','top center');
     $('.struct').css('width','auto');
     $('.topstruct').css('width','auto');
     $('body').css('background-position','top center');
  }
}



/**
 * Outputs email address
 */ 
function eout( part1, part2 ) {

     var em = part1 + '@' + part2;
     var str = '';
     
     str = str + '<a href="mailto:'+ em +'">';
     str = str + em;
     str = str + '</a>';
     
     document.write(str);

}





