$(document).ready(function() {
	$('a[rel*=external]').click( function() {
		this.target = "_blank";
	});

	//jQuery Cycle
    $('#photoHead').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		cleartypeNoBg: true // enable cleartype corrections
	});
	
	//ColorBox
	$("a[rel='colorbox']").colorbox();
	
	// 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: "Please enter a valid email address"
			}
		}
	});
});

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 {
				_gaq.push(['_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 {
			_gaq.push(['_trackPageview', '/' + formType + 'Submitted']);
			$("form.retry").hide();
			$("div#spammer").hide();
			$("div#thanks").show();
		}
	}, "json");
}

/* for ie6 hover nav functinoality */
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);
