////////////////////////////////////////
// Over Label
////////////////////////////////////////
jQuery.fn.overlabel = function() {
    this.each(function(index) {
        var label = $(this); var field;
        var id = this.htmlFor || label.attr('for');
        if (id && (field = document.getElementById(id))) {
            var control = $(field);
            label.addClass("overlabel-apply");
            if (field.value !== '') {
                label.css("display", "none");
            }
            control.focus(function () {label.css("display", "none");}).blur(function () {
                if (this.value === '') {
                    label.css("display", "block");
                }
            });
            label.click(function() {
                var label = $(this); var field;
                var id = this.htmlFor || label.attr('for');
                if (id && (field = document.getElementById(id))) {
                    field.focus();
                }
            });
        }
    });
};
$(document).ready(function(){
  // Drop Downs
  $('#primaryNav>ul>li').hover(function(){
    $(this).addClass('hover');
  }, function(){
    $(this).removeClass('hover');
  });
  
  // Carousel 
  if (jQuery.fn.cycle) {
    var pages = $('#feeds .carousel ul');
    if (pages.length >= 0) {
      $('#feeds .carousel').after('<div id="pager_wrap"><a class="prev">&lt;</a><ul id="pager" /><a class="next">&gt;</a></div>').cycle({
        fx: 'scrollHorz',
        timeout: 5000,
        prev: '.prev',
        next: '.next',
        speed: 700,
        pager : '#pager',
        pagerAnchorBuilder: function(idx, slide) { 
          return '<li><a>'+ (idx+1) +'</a></li>'; 
        }
      });
    }
  }
  
  // Overlabel
  $('#searchForm label, #newsLetter label').overlabel();
  
  //  Home Page Slide Replacement
  $('#pageHeader .slide').each(function(){
    var src = $(this).find('img').attr('src');
    $(this).css({
      'background' : 'url('+src+') 50% 50% no-repeat'
    });
  });
  
  // Feed Hovers
  $('#feeds .carousel li').hover(function(){
    $(this).addClass('hover');
  }, function(){
    $(this).removeClass('hover');
  });
  
  $('#feeds .carousel  li').click(function(){
    window.location=$(this).find("a").attr("href");
    return false; 
  });
  
  // Form Validation
  if( jQuery.fn.validate) {
    $('#rescuePartnersForm').validate();
  }
  
  // Press Media Icons
  $('#press-page ul.listing h3 a[href$=.pdf]').parents('li').addClass('pdf');
  $('#press-page ul.listing h3 a[href$=.swf]').parents('li').addClass('swf');
  $('#press-page ul.listing h3 a[href$=.wmv]').parents('li').addClass('wmv');
  $('#press-page ul.listing h3 a[href$=.mpeg]').parents('li').addClass('mpeg');
  
  
  // Fancybox
  if(jQuery.fn.fancybox) {
    $('#banner_ads .fancy_box').fancybox({
      padding: 30,
      showNavArrows: false,
      // showCloseButton: false,
      titleShow: false,
      autoScale: false,
      width: 627,
      height: 860,
      autoDimensions: true
    });
  }
  
});

