jQuery.fn.fadeToggle = function(speed) {
   return this.animate({ height: 'toggle', opacity: 'toggle' }, 'slow');
}; 

function slideSwitch() {

    var $active = $('#slideshow .active');
    var $next = $active.next(); 
    var $first = $('#slide-1');

    $active.fadeOut('slow'); // fade current
    $active.toggleClass('active'); // deactivate current image
    if ( $next.length == 0 ) { // if there is no next image
		$first.toggleClass('active');  // loop back to first image
		$first.fadeIn('slow'); // fade in first image
    }
    else {
        $next.toggleClass('active'); // activate next image
        $next.fadeIn('slow'); // fade in next image
    }
    $first.removeClass('default'); // turn off fixed display of default image | only needed for first iteration
}

jQuery(document).ready(function(){
	
	$(function() {
	    setInterval( "slideSwitch()", 5000 );
	});
								
	$(".message_close").click(function() {
		$(".message_close").parent().fadeToggle();
	});
	
	$(".message_close").hover(function () { 
		this.style.cursor='pointer';
	});
	
	$("#searchbox").css({color:'gray'});
	$("#searchbox").val('Search');
	
	$("#username").css({color:'gray'});
	
	$("#password").toggleClass('hidden');
	$("#password_placeholder").toggleClass('hidden');
	
	$("#id_address_overide").toggleClass('greyed');
	
	$("#id_address_1").change(function() { 
      $("#id_address_overide").removeClass('greyed');
      $("#id_address_overide").focus();
    });
    
    $("#id_address_0").change(function() { 
      $("#id_address_overide").addClass('greyed');
    });
    
    $(".addressaddress").click(function() { 
      $("#id_address_overide").addClass('greyed');
      $("#id_address_0").attr("checked", "checked");
    });
    
    $(".addresstext").click(function() { 
      $("#id_address_overide").removeClass('greyed');
      $("#id_address_1").attr("checked", "checked");
    });
    
	$("#searchbox").focus(function () { 
      $(this).css({color:'black'});
	  if ($(this).val() == 'Search') {$(this).val('');}
    });
    
	$("#username").focus(function () { 
      $(this).css({color:'black'});
	  if ($(this).val() == 'Username') {$(this).val('');}
    });
	
	$("#password_placeholder").focus(function () { 
	  $(this).addClass('hidden');
	  $("#password").removeClass('hidden');
	  $("#password").focus();
    });

});
