/*
 * Javascript Ajax Code to load in contact form for the Valdemar Site
 *
 * This is quite a bad implementation because we simply load the entire
 * form including HTML and errors each time.
 * Should really use /contact/ajax/ and look through the error classes
 *
 * other improvement is to use Event Bubbling to set the .ajaxForm binding
 *
 * (c) Goran Stefkovski : goran@adventuremedia.com.au
 */
 
// JQuery

var $j = jQuery.noConflict();

var opts = {
   target: $('#quoteFormContainer'),
   url: '/contact/',
   type: 'POST',
   //data_type: 'json',
   beforeSubmit: hideForm,
   success: processForm
};

$j(function () {
   $j('#quoteForm').ajaxForm(opts);
});

function hideForm() {
   var loadingtext="<div style='text-align:center;margin:20px 5px;'><p>We are processing your request. Please wait.</p>" + 
                   "<br/><br/><img src='/media/img/loader.gif'/></div>";
   $j('#quoteForm input.submit').attr("disabled", "disabled");
   $j('#quoteFormContainer').toggleClass('loading').html(loadingtext);
}
function processForm(data) {
   $j('#quoteFormContainer').html(data).fadeIn('slow').toggleClass('loading');
   $j('input.submit').click(function() {pageTracker._trackPageview("/goal/submit/form-button")});
   $j('#quoteForm').ajaxForm(opts);
}

/*
 * SLIDER CODE
 */
//easing equation, borrowed from jQuery easing plugin
//http://gsgd.co.uk/sandbox/jquery/easing/
$j.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};


jQuery(function( $ ){
	$('#testimonialSet').serialScroll({
		items:'div.testimonial',
		duration:900,
		force:true,
		axis:'y',
		lazy:true,
		interval:10000,
		easing: 'easeOutQuart',
		navigation: 'ul.nav',
	});	
	
});

/* Analytics Hack Code */

$j(function ( ) {
    // Top Button
   $j('#quote a').click (function () {
       pageTracker._trackPageview("/goal/submit/top-button");
   });
   $j('input.submit').click( function() {
       pageTracker._trackPageview("/goal/submit/form-button");
   });
});
