jQuery(function() {

	// IMAGE BACKGROUND SWAP
	$('.highlight').hover(
		function () {
		
			$(this).css('backgroundPosition','0 -' + $(this).height() + 'px'); 
		},
		function () {
		
			$(this).css('backgroundPosition','0 0'); 
		}
	);
	
	$('#player1').click(function () {
	
		_gaq.push(['_trackEvent', 'Video', 'Click', 'Homepage']);
	});
	
	$('#home_tab .performance').mouseenter(function () {
	
		$('#home_tab').css('backgroundPosition','0 0');
		$('#home_features').css('display','none');
		$('#home_performance').css('display','block');
	});
	
	$('#home_tab .features').mouseenter(function () {
	
		$('#home_tab').css('backgroundPosition','0 -' + $('#home_tab').height() + 'px'); 
		$('#home_performance').css('display','none');
		$('#home_features').css('display','block');
	});
	
	// HOMEPAGE IMAGE CYCLE
	$('#homepage_animation').cycle({ fx: 'fade' });
	
	$('#home_feature_guarantee > a').fancybox({
		'autoDimensions' : false,
		'width'			: 400,
		'height'		: 120,
		'overlayShow'	: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
});


// MONTHLY SWEEPSTAKES
function giveaway_enter () {

	var error = false;
	
	if (!$('#name').val()) error = formerror('#name');
	if (!validate_email($('#email').val())) error = formerror('#email');
	
	if ($('#score').val() == 'Select') error = formerror('#score');
	if ($('#improve').val() == 'Select') error = formerror('#improve');
		
	if (error) {
	
		$('#error_message').fadeIn();
	} else {
	
		// FORM SUBMIT
		$.ajax({
      			
      		type: 'POST',
    		url: 'http://www.gripsolid.com/gs-data-giveaway-submit.php',
      		data: $('#enter_to_win').serialize(), 
      		cache: false,
      		success: function (msg) {
      			
      			$('#enter_to_win').html( $('#thank_you').html() );
      		}
      	});
	}
}

function validate_email (email) {

	if ( !email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/) ) return false;
	return true;
}

function formerror (whField) {

	$('label[for=' + $(whField).attr('id') + ']').addClass('error');
	$(whField).change(function() { $('label[for=' + $(whField).attr('id') + ']').removeClass('error'); });	
	return true;
}

