$(document).ready(function() {
	//Open External Links in a New Window/tab
	$('a[rel*=external]').click( function() {
		this.target = "_blank";
	});
	/*! jQuery Cycle Plugin (withOUT Transition Definitions) */
    $('#rotator').cycle({
		cleartypeNoBg: true // enable cleartype corrections
	});
	
	// Contact Form Functions			   	
	$("div.loading").hide();
	$("div#thanks").hide();
	$("div#spammer").hide();
	$("form.retry").hide();
	$("div#noMoreChances").hide();
	
	jQuery.validator.messages.required = "Required";
	$("form.validate").validate({
		messages: {
			email: {
				email: "Valid Email Address Please"
			}
		}
	});
	
});

function submitForm() {
	var formType = $('.type').val();
	var postdata = $('#' + formType).serialize();
	var formValid = $('#' + formType).valid();
	
	//alert(postdata);
	
	if(formValid == true) {
		$(".submit").hide();
		$("div.loading").show();
		$.get("/includes/php/mailer.php", {postdata: ""+postdata+""}, function(data){
			if(data.response == 'true') {			
				$("div.loading").hide();
				$("form#" + formType).hide();
				$("div#spammer").show();
				$(".submit").show();
				$("form.retry").show();
			} else {
				pageTracker._trackPageview('/' + formType + 'Submitted');
				$("form#" + formType).hide();
				$("div#thanks").show();
			}
		}, "json");
	}
}

function submitRetryForm() {
	var formType = $('.type').val();
	var answer = $('#answer').val();
	var postdata = $('#' + formType).serialize();

	$(".submit").hide();
	$("div.loading").show();
	$.get("/includes/php/mailer.php", {postdata: ""+postdata+"", answer: ""+answer+"", retry: "true"}, function(data){
		if(data.response == 'failure') {
			$("div.loading").hide();
			$("form.retry").hide();
			$("div#noMoreChances").show();	
			$("div#spammer").hide();
		} else {
			pageTracker._trackPageview('/' + formType + 'Submitted');
			$("form.retry").hide();
			$("div#spammer").hide();
			$("div#thanks").show();
		}
	}, "json");
}

/* for ie6 hover nav functionality */
sfHover = function() {
	var sfEls = document.getElementById("mainNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);