$(function() {

	$('#black-out').fadeOut(800);
	
	function colHeightFix() {
		var rightColHeight = $('#main-right').height(); 
		var windowHeight = $(window).height(); 
		if(rightColHeight>windowHeight) { 
			$('#copyright-container').addClass("copyright-container-fix");
			$('#copyright').addClass("copyright-fix")
		} else {
			$('#copyright-container').removeClass("copyright-container-fix");
			$('#copyright').removeClass("copyright-fix")
		}
	}
	
	$(window).resize(function() {
		colHeightFix();
	});
	
	colHeightFix();
	
	$('#share-link').click(function() {
		
		$('#social').toggle('fast');
		
	});	
	
	$contactForm = $("#contact-form");
	
	$contactForm.submit(function() {
	
		$contactForm.find("input").removeClass("required-field");
		
		var submit = true;
		var requiredText = "Required field";
		
		$contactName = $contactForm.find("#contact-name");
	
		if($contactName.val()=="") {
			$contactName.addClass("required-field");
			$contactName.val(requiredText);
			submit = false;
		}
		
		$contactEmail = $contactForm.find("#email-address");
		
		if($contactEmail.val()=="") {
			$contactEmail.addClass("required-field");
			$contactEmail.val(requiredText)
			submit = false;
		}		
		
		return submit;
	
	});

	Cufon.replace('h1, h4', { fontFamily:'Helvetica Neue LT Std', fontWeight:'250' });	
	Cufon.replace('h2, #service-list, #address, #projectFilter li', { fontFamily:'Helvetica Neue LT Std', hover: true });
		
	$("#mailing-submit").click(function() {
		
		var val = $("#mailing-list").val();

		if(val!="Mailing list" && val!="") {
			$.post("send-email.php",{ mailingList: val }, function(data) {				
				document.getElementById("mailing-list").value="";			
				 $("#mailing-status").fadeIn("slow");			
			});	
		} else {
			// No post
		}
		
		return false;
		
	});
			
	$frontCycle = $("#front-cycle");

	$frontCycle.cycle({
		fx: 'fade',
		speed: 700,
		timeout: 5000,
		cleartype: 0,
		cleartypeNoBg:true
	});
	
	$frontCycle.find(".view-project").hover(function() {
	
		$this = $(this);
		$frontCycle.cycle('pause');
		
		$this.find("img").stop(true,true).animate({ opacity: 0.2 } ,500);
	
	
	}, function() {
	
		$this.find("img").stop(true,true).animate({ opacity: 1 } ,500);	
		$frontCycle.cycle('resume');
	
	});

	$('#project-cycle').after('<div id="project-nav">').cycle({
		fx: 'fade',
		speed: 700,
		timeout: 5000,
		pager: '#project-nav', 
		cleartype: 0,
		cleartypeNoBg:true
	}); 

	$projectFilter = $("#projectFilter");
	
	$("#sub-client").find("a").click(function() {
	
		$this = $(this);
		$("#sub-client").find("li").removeClass("active");
		$this.parent().addClass("active");
		var className = $this.attr("class");
		className = className.split("-");
		className = className[1];
		
		if(className=="all") {
			$projectFilter.find("a").removeClass("not-active");
		} else {
			$projectFilter.find("a").removeClass("not-active");
			$projectFilter.find("a").not("."+className).addClass("not-active");
		}
		
		Cufon.refresh();
		
		return false;
	
	});
	

		
});

$(window).load(function(){  // Wait till everything has finished loading.
	$(function() {
		if($("#imageScroller").length<1) {
			$("#preloader").fadeOut("slow", function() {
				$("#main-right").fadeIn(800);
			});	
		}
	});
});
