// JavaScript Document

var link = base_url + 'rsm/';
var tick = 0;
var scrollStop;

$.ajaxSetup({
    cache: false
}); // for IE

Cufon.replace('h2', { fontFamily: 'Century Gothic', hover: true });
Cufon.replace('#left h3', { fontFamily: 'Century Gothic', hover: true });
//Cufon.replace('p', { fontFamily: 'Century Gothic', hover: true });
Cufon.replace('h1', { fontFamily: 'Franchise' });

Cufon.now(); // for IE

$(document).ready(function(){
	
	$.easing.custom = function (x, t, b, c, d) {
		var s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}
	
	$.easing.easeInQuad = function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	}
	
	$("#flowPanes").scrollable({size: 1, circular: true, clickable: false, easing: 'custom', speed: 700}).autoscroll({autoplay: true, interval: 5000});
	
	$("#caseStudyPanes").scrollable({size: 1, easing: 'easeInQuad'});
	
	$("#contactForm").validator({
		message: '<div><em/></div>',
		position: 'top left',
		offset: [3, 40]
	});
	
	var triggers = $(".navContact").overlay({
		mask: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.9
		},
		closeOnClick: false,
		onBeforeClose: function(e) {
			$(".error").hide();	
		} 
	});
	
	$("#contactForm").submit(function() {
		$("#submitAction p").html('Sending...'); 
		var uid = $(this).find('input[name=uid]').val();  
		var ip = $(this).find('input[name=ip]').val();  
		var name = $(this).find('input[name=nameField]').val();  
		var email = $(this).find('input[name=emailField]').val();  
		var twitterID = $(this).find('input[name=twitterField]').val();  
		$.post(link + "contact/submit", { uid: uid, ip: ip, name: name, email:email, twitterID: twitterID, ajax: '1' }, function(data){ 
			if (data == 'true') {
				$("#submitAction p").html('Success!  You will now be receiving a confirmation email - you must click on the link in the email to be signed up to our mailing list.'); 		 
			} else if (data == 'duplicate') {
				$("#submitAction p").html('Your email address is already in our database!'); 
			} else if (data == 'email') {
				$("#submitAction p").html('We were able to add you to our database - but unable to send you a confirmation email... please click <a href="'+link+'contact/confirm/'+uid+'">here</a> to confirm'); 
			} else {
				$("#submitAction p").html('There was a problem adding you to our mailing list... this is what the function said:'+data); 
			} 
		});  
		return false;
	});  
	
	// services page scrolly
	$('#servicesNav li a').click(function() {
		$(this).addClass("active");
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("div.servicesDiv").height(570);
		$("div.servicesDiv").scrollTo(elementClicked, 2000, 'easeInOutCubic');
		return false;
	});
	
	$('h2.servicesH2 a').click(function() {
		$(this).addClass("active");
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("div.servicesDiv").height(1400);
		$("div.servicesDiv").scrollTo(elementClicked, 2000, 'easeInOutCubic');
		return false;
	});
						   
});
