 $(document).ready(function(){
	
	/**
	*
	* Cufon font replacement
	*
	*/
	
	Cufon.replace('.din-black', { fontFamily: 'DIN_900' });
	Cufon.replace('.din', { fontFamily: 'DIN_700' });
	
	// the length of the nav, -1 to start at 0
	var nav_length 	= $('nav ul li a').length - 1,
		current_nav = 0,
		can_type	= false;
	
	$(document).keydown(function(e) {
		if (can_type == false) {
		
			e.preventDefault();
			
			if (e.keyCode == 32)
			{
				$('nav ul li a:eq('+current_nav+')').click();
			}
			current_nav++;
			if (current_nav > nav_length) { current_nav = 0; }		
		}
	});
	
	$('input, textarea').focus(function() {
		can_type = true;
	});
	
	$('input, textarea').focusout(function() {
		can_type = false;
	});
	
	/**
	*
	* Page scrolling
	*
	*/
	
	$.localScroll.hash({
		target: 'body', // Could be a selector or a jQuery object too.
		queue:true,
		offset: {top: -40},
		duration:1500
	});
	
	$.localScroll({
		target: 'body', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		offset: {top: -40},
		hash:true
	});
	
	
	
	/**
	*
	* Placeholder text on form
	*
	*/

	$('input, textarea').example(function() {
		return $(this).attr('placeholder');
	});
	
	
	
	
	/**
	*
	* Contact form
	*
	*/
	
	// ajax submit
	
	$('#submit').click(function() {
		
		var name = $('#name').val();
		var email = $('#email').val();
		var message = $('#message').val();
		
		if (name != 'Your name?' && email != 'Your email?' && message != 'What would you like to say?')
		{
			$.ajax({
				type: 'POST',
				url: 'contact.php',
				data: 'ajax=ajax&name='+name+'&email='+email+'&message='+message,
				success: function(message)
				{
					if (message == 'invalidemail')
					{
						$('.error').text('Enter a valid email');
					}
					else if (message == 'mailsent')
					{
						$('.error').text('');
						$('#success').show();
					}
				}
			});
		}
		else
		{
			$('.error').text('Fill them in...');
		}
	
		return false;
	});
	
	// clear the error text when trying to enter your details
	
	$('input, textarea').focus(function() {
		$('.error').text('');
	});
	
	// hide the success box
	
	$('#success').hide();
	
	
	/**
	*
	* run the fancybox gallery
	*
	*/
	
	$('.gallery a').fancybox({
		overlayColor: '#D7001A',
		overlayOpacity: 1
	});
	
	
	/**
	*
	* nav animation
	*
	*/
		
	$('nav ul li a').hover(function() {
		
		$(this).animate({
			'borderLeftWidth': '8px',
			'paddingLeft': '5px'
		}, 250);
		
	}, function() {
	
		$(this).animate({
			'borderLeftWidth': '0px',
			'paddingLeft': '0px'
		}, 250);
		
	});
	
	
	
	/**
	*
	* facebook anim
	*
	*/
	
	function closeFacebook()
	{
		$('.facebook-like').delay(2000).animate({
			height: '0'	
		}, 500);
		$.cookie('close_button', 'closed', { expires: 30 });
	}
	
	var is_closed = $.cookie('close_button');
	
	
	if (is_closed != 'closed')
	{
		$('.facebook-like').delay(2000).animate({
			height: '50px'
		}, 500);
	}
		
		
	$('#fb-close').click(function() {
		closeFacebook();
		return false;	
	});
	
	// parse the fb:like button
	FB.init({xfbml: true});
	
	// when you like the page, hide close the facebook holder
	FB.Event.subscribe('edge.create', function(response) {
		closeFacebook();
	});
	
	$('.fb_ltr').append('<p></p>');
	
	
	
	/**
	*
	* countdown
	*
	*/
	
	var date = new Date(2011, 8-1, 20, 20, 0, 0, 0);
	$('#countdown').countdown({until: date, compact: true, layout: '<ul><li class="days">{d10}{d1}<span>days</span></li><li class="hours">{h10}{h1}<span>hours</span></li><li class="mins">{m10}{m1}<span>mins</span></li><li class="secs">{s10}{s1}<span>secs</span></li></ul>'});
		
});
