function slideSwitch() {
    var $active = $('.slideshow div.active');
    if ( $active.length == 0 ) $active = $('.slideshow div:last');
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow div:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
 

jQuery(document).ready(function(){
    setInterval( "slideSwitch()", 2500 );
    
    jQuery('#menu li a').mouseover(function(){
        jQuery(this).parent().animate({backgroundPosition:"(0 0)"}, 500);
    }).mouseout(function(){
        jQuery(this).parent().animate({backgroundPosition:"(0 -18px)"}, 500);
    });
    jQuery('.btn_read').mouseover(function(){
        jQuery(this).children().animate({opacity:0}, 500);
    }).mouseout(function(){
        jQuery(this).children().animate({opacity:1}, 500);
    });     
    jQuery('#content-top a,span.entry-date').mouseover(function(){
        jQuery(this).animate({color:'#f00'}, 500);
    }).mouseout(function(){
        jQuery(this).animate({color:'#666'}, 500);
    });
    
    var init = new Array();
    jQuery('.day input').each(function(){
        init[jQuery('.day input').index(this)] = jQuery(this).val();
    }).focus(function(){
        if(jQuery(this).val() == init[jQuery('.day input').index(this)]) jQuery(this).val('').css('color','#666');
    }).blur(function(){
        if(jQuery(this).val() == '') jQuery(this).val(init[jQuery('.day input').index(this)]).css('color','#ccc');
    });
    //jQuery.metadata.setType("attr", "validate");
    if(jQuery.validator) {
        jQuery.validator.addMethod("notEqual", function(value, element, param) {
          return value != param;
        }, "");
        
        jQuery.validator.messages.required = "";
        
        jQuery("#request-form,#contact-form").validate({
            invalidHandler: function(e, validator) {
                var errors = validator.numberOfInvalids();
                if (errors) {
                    var message = errors == 1
                        ? 'You missed 1 field. It has been highlighted below'
                        : 'You missed ' + errors + ' fields.  They have been highlighted below';
                    jQuery("div.error span").html(message);
                    jQuery("div.error").show();
                    jQuery('html').animate({scrollTop : 0});                
                } else {
                    jQuery("div.error").hide();
                }
            },
          /*          
          rules: {
              day1a:{
                  notEqual: "Meal A"
              }, 
              day1b:{
                  notEqual: "Meal B"
              }, 
              day1c:{
                  notEqual: "Meal C"
              }, 
              day1d:{
                  notEqual: "Meal D"
              }, 
              day2a:{
                  notEqual: "Meal A"
              }, 
              day2b:{
                  notEqual: "Meal B"
              }, 
              day2c:{
                  notEqual: "Meal C"
              }, 
              day2d:{
                  notEqual: "Meal D"
              }, 
          },
          messages : {
              needs_food: {
                  required: "Please select Yes or No"
              },
              complete: {
                  required: "Please select Yes or No"
              }
          }
          */
        });   
    
    }
            jQuery('a.contact').click(function(){
                jQuery('#ppcf iframe').hide('slow');
                jQuery('#ppcf .close').hide(); 
                jQuery('#ppcf .loading-indicator').show();
                jQuery('#ppcf').show();

                var src = jQuery(this).attr('href');
                //var src = BASE_URL+'/popup';
                jQuery('#ppcf iframe').attr('src', src);
                jQuery('#ppcf iframe').load(function(){
                    if(jQuery(this).src != "") {                  
                        jQuery('#ppcf .loading-indicator').hide();
                        jQuery('#ppcf iframe').fadeIn('slow');
                        jQuery('#ppcf .close').fadeIn('slow'); 
                    }
                });
                return false;
            });
            jQuery('#ppcf .close').click(function(){
                jQuery('#ppcf').fadeOut('fast', function(){
                    jQuery('#ppcf iframe').hide();
                    jQuery('#ppcf .close').hide(); 
                });
                
            });   
    

});
