$(document).ready(function() {

	if ($('#Quote .items').length > 0) {
		
		$('#Quote .readMore').show();
	
		$('#Quote .items').cycle({ 
	    	fx: 'fade', 
	    	speed: 'fast', 
	    	timeout: 0, 
	    	next: '#Quote .readMore'
	   	});
	}
	
	if ($('#Music .items').length > 0) {
		$("#Music .items").jCarouselLite({
	    	btnNext: "#Music .readMore"
	   	});
	}
	
	
	// hide and show default input values
	$('#Subscribe input[type="text"]').focus(function() {
        if (this.value == this.defaultValue) {
        	this.value = '';
    	}
        if(this.value != this.defaultValue) {
	    	this.select();
        }
    });

    $('#Subscribe input[type="text"]').blur(function() {
        if (this.value == ''){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
    
    $('#Form_SubscribeForm').submit(function() {

		var formData = $('#Form_SubscribeForm').serialize();
		var action = $('#Form_SubscribeForm').attr('action');
		
		$.ajax({
			type: "POST",
			url: action,
			data: formData,
			dataType: "html",
			beforeSend: function() {			
			    $('#Form_SubscribeForm').validate({
					rules: {
						Email: {
							required: true,
							email: true
						}
					},
					messages: {
						Email: "A valid email is required."
					},
					errorPlacement: function(error, element) {
						error.insertAfter('#Form_SubscribeForm .clear');
   					}
				});
							
				if ($('#Form_SubscribeForm').valid() == true) {
					// show loading animation
					$('#Subscribe').html('<span class="loading">Submitting Email Address...</span>'); 
				} else {
					return false;
				}
			},
			success: function(data, textStatus) {		
				// load result data
				$('#Subscribe').html($(data).filter('#SubscribeResult'));
			}
		});	
    	return false;
    });
});		
