$(document).ready(function()
{
	// Fancybox	screenshots
	$('a.screenshots').fancybox(
	{
		'transitionIn'			: 'elastic',
		'transitionOut'			: 'elastic',
		'speedIn'				: 600, 
		'speedOut'				: 400, 
		'hideOnOverlayClick' 	: true,
		'hideOnContentClick' 	: true,
		'overlayOpacity' 		: '0.8',
		'padding'				: '0',
		'overlayColor' 			: '#000',
		'titleShow'				: false
	});
	
	// Purchase handling
	if($('input[name=qty]').length > 0) {
		$('input[name=qty]').keyup(function() {
			purchaseUpdatePriceTotal();
		});
		$('input[name=qty]').change(function() {
			purchaseUpdatePriceTotal();
		});
		purchaseUpdatePriceTotal();
	}
	if($('input#cancel').length > 0) {
		$('input#cancel').click(function(e) {
			$('div#purchase').animate({
				opacity: 0.0,
				top: '0%',
				height: 'toggle'
			}, 250);
			$('div#modal-bg').fadeOut();
		});
	}
	$('a.activate-purchase').click(function(e) {
		e.preventDefault();
		$('div#purchase').css({'opacity': 0, 'top': '0%'}).animate({
			opacity: 1.0,
			top: '50%',
			height: 'toggle'
		}, 250);
		$('div#modal-bg').css('height', $(document).height()).fadeIn();
	})
	$('div#purchase form').submit(function(e) {
		var email = $('input[name=email]').val();
		var qty = parseInt($('input[name=qty]').val());

		if(!purchaseValidateEmail(email)) {
			alert("Please enter a valid email address");
			e.preventDefault();
		}
		if(isNaN(qty) || qty.length == 0 || qty <= 0) {
			alert("Please provide a valid quantity");
			e.preventDefault();
		}
	});

	// Downloads
	$('a.download').click(function(e) {
		e.preventDefault();
		$('div#download').css({'opacity': 0, 'top': '0%'}).animate({
			opacity: 1.0,
			top: '50%',
			height: 'toggle'
		}, 250);
				
		$('div#modal-bg').css('height', $(document).height()).fadeIn();
		_gaq.push(['_trackPageview', '/download_goal.php']);
		setTimeout("setLocation('" + $(this).attr('href') + "')", 1500);
		
		var helpRedirect = setTimeout(function()
		{
			window.location.replace('http://trackrecordapp.com/help');;
		}, 10000);
		
	});
	$('div#download a').click(function(e) {
		e.preventDefault();
		$('div#download').animate({
			opacity: 0.0,
			top: '0%',
			height: 'toggle'
		}, 250);
		$('div#modal-bg').fadeOut();
	});
	
	$('a.newtab').click(function (e) 
	{
        e.preventDefault();            
        window.open($(this).attr('href'));
    });
	
	if($('body#home').length > 0)
	{				
		$("div#masthead li a").click(function(e) 
		{
			e.preventDefault();
		});
		
		$("div#free-trial a#blue-dl-button").mouseenter(function() 
		{			
			$("div#dl-requirements").fadeIn(250);
	
		}).mouseleave(function() 
		{			
			$("div#dl-requirements").fadeOut(250);
		});
		
	}
}); 
