$(document).ready(function() {
	
	// Cufon
	Cufon.replace('h2.pageTitle, .itemMain h2, #feedback_wrap h3');
	
	// Logo
	$('h1.logo a').hover(function() {
		$('h1.logo a').animate({'top' : '15px'}, 300);
	},
	function() {
		$('h1.logo a').animate({'top' : '7px'}, 200);
	});
	
	// Cycle
	$('.shuffle').cycle({
		fx: 'fade', 
   		speed: 500, 
	    timeout: 0, 
	    next: '.store_next a', 
	    prev: '.store_prev a'
	});
	
	// Add 'Choose One'
	$('#customize select').prepend('<option value="" selected="selected">-- Choose one --</option>');
		
	// Add To Cart Message
	
	$('input.button_add').click(function() {
		$('.add_confirm').fadeIn('slow').animate({opacity: 1.0}, 3500).fadeOut(5000);
	});
	
	// Form Validation
	
		// Feedback Form
		$('#form_feedback').ajaxForm({
			target: '#output',
			beforeSubmit: function() {
				$('#msg').fadeIn(300).html('Sending...');
			},
			success: function(rtn) {
				if(rtn=='success') {
					$('#form_feedback').empty();
					$('#msg').fadeIn(300).html('Thank you for your feedback!')
				} else {
					$('#msg').fadeIn(300).html('Please correct the errors.')
				}
			}
		});
		
		$('#form_feedback').validate({
			errorElement: 'em',
			rules: {
				name: 'required',
				email: {
					required: true,
					email: true
				},
				feedback: 'required'
			},
			messages: {
				name: 'Please enter your name',
				email: 'Please enter a valid email address',
				feedback: 'Please provide us with feedback'
			}
		});
		
		// Contact Form
		$('#form_contact').ajaxForm({
			target: '#output',
			beforeSubmit: function() {
				$('#msg').fadeIn(300).html('Sending...');
			},
			success: function(rtn) {
				if(rtn=='success') {
					$('#form_contact').empty();
					$('#msg').fadeIn(300).html('Thank you for contacting us!<br />We will get back to you shortly.')
				} else {
					$('#msg').fadeIn(300).html('Please correct the errors.')
				}
			}
		});
		
		$('#form_contact').validate({
			errorElement: 'em',
			rules: {
				name: 'required',
				email: {
					required: true,
					email: true
				},
				comments_questions: 'required'
			},
			messages: {
				name: 'Please enter your name',
				email: 'Please enter a valid email address',
				comments_questions: 'Please provide us with feedback'
			}
		});
	
	// Hide Quantity Box
	$('input[name=quantity]').css('display','none');
    $('input[name=quantity]').attr('value', '1');
    
    // External Links
    // open links in external window
	$("a[href^=http]").each(function() {
		if(this.href.indexOf(location.hostname) == -1) {
			$(this).click(function(){window.open(this.href);return false;
		}); 
		}
	});
	
});
