$(document).ready(function () {
	
	$.easing.exponential = function (x, t, b, c, d, s) {
		t /= d/2;
		if (t < 1) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b;
		t--;
		return c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b;
	};

	$.easing.quadratic = function (x, t, b, c, d, s) {
		t /= d/2;
		if (t < 1) return c/2*t*t*t*t + b;
		t -= 2;
		return -c/2 * (t*t*t*t - 2) + b;
	};

	$.easing.sin = function (x, t, b, c, d, s) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	};
	
	$.fn.animateRibbon = function() {
		
		topPos = $(this).offset().top - $('#highlight').offset().top - 4;
		//console.log(topPos);
		
		$('#ribbon').stop();
		$('#ribbon').animate({
			top: topPos,
			queue: false
		}, 600, 'quadratic');	
		
		$('#ribbonLink a:first-child').stop();
		$('#ribbonLink a:first-child').animate({
			marginTop: -topPos - 4,
			queue: false
		}, 600, 'quadratic');
		
		newHeight = 12 -(((topPos + 4) / 206) * 12);
		//console.log(newHeight);
		$('#ribbon3D > img').stop();
		$('#ribbon3D > img').animate({
			height: newHeight,
			width: 10
		}, 600, 'quadratic');
		
	}
	
	var topPos;
	var newHeight;
	
	$('.highlightLinks a').click(function(){
		
		$(this).blur();
		
		$('#highlightMain').stop();
		$('#highlightMain').trigger( 'start' );

		
//		$(this).animateRibbon();
		//console.log("Click");
		
		return false;
		
	});
	
	$('#highlightMain').serialScroll({
		axis:'x',
		duration: 600,
		items: 'div.highlightBlocks', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		navigation: '#highlightLinks a',
		easing: 'quadratic',
		force: true,
		constant: false,
		onBefore:function( e, elem, $pane, $items, pos ){			
			$('#highlightLinks a[href="#'+$(elem).attr('id')+'"]').animateRibbon();
		}
	});


});

function send(datastr){
	$.ajax({	
		type: "POST",
		url: "/scripts/mail.php",
		data: datastr,
		cache: false,
		success: function(html){
			_gaq.push(['_trackPageview','/Questions-Quotes']);
			//$("#response").fadeIn("slow");
			$("#response").html(html);
			setTimeout('$("#response").fadeOut("slow")',4000);
		}
	});
}
