$(document).ready(function() {
	Cufon.replace("h1, h2, .gillSansLight", {fontFamily: 'Gill Sans MT Light'});
	Cufon.replace(".gillSansBold", {fontFamily: 'Gill Sans MT Extra Bold'});
	
	$('.play').click(function() {
		$(this).hide();
		$('.loadingFlash').show().css({'opacity': 0}).animate({'opacity': 1.0}, 900);
		setTimeout("doFlashLoad();", [1500]);
	});
	$('.exit').click(function() {
		$('#flashMovie').remove();
		$('.flashHolder').append('<div id="flashMovie"></div>');
		$(this).hide();
		$('.play').show();
	});
	
	$('.tablink').click(function() {
		$('.tablink').removeClass('activeTab');
		$(this).addClass('activeTab');
		$('.tabcontent').hide();
		$("#"+$(this).attr('rel')).show();
		return false;
	});
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
});

function doFlashLoad() {
	$('.loadingFlash').hide(0, function() {
		var flashvars = {};
		var params = {menu: "false",wmode: "transparent", scale: "noscale"};
		var attributes = {}; 
		swfobject.embedSWF("images/flash/movie.swf", "flashMovie", "225", "154", "9.0.0", "", flashvars, params, attributes);
		$('.exit').show();
	});
}

$(function() {
	$('#banner').after('<div id="nav">').cycle({
		fx:     'fade',
		speed:  '400',
		timeout: 6000,
		pager:  '#nav'
	});
	$('#portfolioPictures').after('<div id="portfolioNav">').cycle({
		fx:     'uncover',
		speed:  '400',
		timeout: 4500,
		pager:  '#portfolioNav'
	});
});

function htmlspecialchars(string) { 
	var safeText = $('<span>').text(string).html();
	safeText = safeText.replace("'","&#39;").replace('"','&quot;');
	return safeText;
}

$(function() {
	$('#contactForm').submit(function() {
		var name = htmlspecialchars(this.contactName.value);
		var email = htmlspecialchars(this.contactEmail.value);
		var subject = htmlspecialchars(this.contactSubject.value);
		var message = htmlspecialchars(this.contactMessage.value);
		if(name == "" || email == "" || ((email.indexOf(".") > 2) && (email.indexOf("@") > 0)) == false || message == "") {
			alert("Enter your name, email address and message.");
			return false;
		} else {
			$('.submitButton').blur().attr('disabled','disabled');
			$('.emailStatus').animate({'opacity': 0.3}, 400);
			$('.loading').fadeIn(900);
			
			var dataString="name="+name+"&email="+email+"&subject="+subject+"&message="+message
			$.ajax({
			  type: "POST",
			  url: "includes/processform.php",
			  data: dataString,
			  timeout: 10000,
			  error: function() {
				endMessage = "Sorry, your request couldn't been sent at this time. Please reload and try again.";
			  },
			  success: function() {
				endMessage = "Thanks, your email has been sent to our team.";
			  },
			  complete: function() {
				$('.loading').fadeOut(550); $('.emailStatus').fadeOut(550, function() {
					$('.emailStatus').animate({'opacity': 1.0}, 0).html('<p class=thanks>'+endMessage+'</p>').fadeIn(600);
				});
			  }
			});
			return false;
		}
	});
});