/*
* Skeleton V1.1
* Copyright 2011, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 8/17/2011
*/


$(document).ready(function() {

	/* Navigation
	================================================== */

	$('.show_nav').click(function() {
	  $('#nav ul').slideToggle();
	});

	/* 'Back to top' Scroll
	================================================== */
		
	$('.top').click(function() {

		$('html,body').animate({ scrollTop: $('#header').offset().top }, { duration: 'slow', easing: 'swing'});
	});


	/* PPI Claim Calculator
	================================================== */

	$('#calculate').click(function(e) {
	
		e.preventDefault();
		
		// Calculate claim amount
		var monthly_payment = $('#monthly_payment').val();
		var length_of_loan = $('#length_of_loan').val();		
						
		if ( isNaN(monthly_payment) || monthly_payment < 1 || monthly_payment > 2000 )
		{
			alert('Please enter your monthly payment amount in pounds (max. 2000)');
		
		}
		else if ( isNaN(length_of_loan) || length_of_loan <= 0 || length_of_loan > 25 )
		{
			alert('Please enter the length of your loan in years (max. 25)');		
		}
		else
		{		
		
			var amount = (monthly_payment * 12) * length_of_loan;			
			var claim = (amount / 100) * 21.6;			
			claim = claim.toFixed(2);	
			
			// Display result		
			$('#result strong').html('&pound;' + claim);
			$('#result').show();
			$('html,body').animate({ scrollTop: $('#result').offset().top }, { duration: 'slow', easing: 'swing'});
			$('#calculate').html('Recalculate');
		
		}
	
	});

	/* Tabs Activiation
	================================================== */

	var tabs = $('ul.tabs');

	tabs.each(function(i) {

		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {

			//Get Location of tab's content
			var contentLocation = $(this).attr('href');

			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {

				e.preventDefault();

				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');

				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

			}
		});
	});
	
	
	/* Analytics Event Tracking
	================================================== */
		
	$("#calculate").click(function(){
		_gaq.push(['_trackEvent', 'PPI Calculator', 'Calculate Clicked']);
			
	});
	
	$("#form-submit").click(function(){
		event = $(this).attr("value") + " Clicked";
		_gaq.push(['_trackEvent', 'Form Submit', event]);
		
	});
	
});

