$(document).ready(function() {
	if($('html').hasClass('ie6')) {
		$('#wrapper').hide();	
		var overlay = $('<div>').css({
				position:'absolute',
				display:'block',
				top:0,
				left:0,
				width:'100%',
				height:'100%',
				backgroundColor:'#333',
				zIndex:10001
			})
			.addClass('ie_overlay')
			.appendTo('body');
		var container = $('<div>').css({
				position:'relative',
				display:'block',
				margin:'0 auto',
				width:'640px',
				backgroundColor:'#ccc',
				zIndex:10002,
				border:'12px #FFF solid'
		}).html('<h1 style="font-size:30px; padding:16px; line-height:32px; text-align:left; color:#666;">This page does not support your browser</h1><p style="text-align:left; padding:0 16px 16px; text-shadow:none">You are using an out-of-date version of Internet Explorer and will not be able to view this website properly, use <a style="font-weight: bold; color: #333; text-decoration: underline" href="http://www.mozilla.com/firefox/" target=_blank>firefox</a>, <a style="font-weight: bold; color: #333; text-decoration: underline" href="http://www.google.com/chrome" target=_blank>chrome</a> or <a style="font-weight: bold; color: #333; text-decoration: underline" href="http://www.opera.com/download/" target=_blank>opera</a>.</p><p style="margin-bottom:12px"><a style="margin-left:8px" href="http://windows.microsoft.com/en-US/internet-explorer/downloads/ie"><img src="images/ie.jpg" width="118" height="150" /></a><a style="margin-left:8px" href="http://www.google.com/chrome"><img src="images/chrome.jpg" width="118" height="150" /></a><a style="margin-left:8px" href="http://www.opera.com/download/"><img src="images/opera.jpg" width="118" height="150" /></a><a style="margin-left:8px" href="http://www.mozilla.com/firefox/"><img src="images/firefox.jpg" width="118" height="150" /></a><a style="margin-left:8px" href="http://www.apple.com/safari/download/"><img src="images/safari.jpg" width="118" height="150" /></a></p>').appendTo('body');
		$('html, body').css({'overflow':'hidden', 'height':'100%'});
		$('body').css({'paddingTop':'12%'});
	} else {
		$.localScroll({
			target: window,
			queue:true,
			duration:1000,
			hash:true,
			offset:1,
			onBefore:function( e, anchor, $target ){},
			onAfter:function( anchor, settings ){
				$('li', '#main-nav').removeClass('active');
				$('li.' + anchor.id, '#main-nav').addClass('active');
			}
		});

		$('input[placeholder]', '#contact').placeholder();
		$('.top').addClass('hidden');
		$.waypoints.settings.scrollThrottle = 30;
		$('#wrapper').waypoint(function(event, direction) {
			$('.top').toggleClass('hidden', direction === "up");
		}, {
			offset: '-50%'
		}).find('#main-nav-holder').waypoint(function(event, direction) {
			$('#wrapper').toggleClass('sticky', direction === "down");
			event.stopPropagation();
		});
		$('#works a').lightBox({
			imageLoading: 'images/lightbox/ico-loading.gif',
			imageBtnClose: 'images/lightbox/close.gif',
			imageBtnPrev: 'images/lightbox/prev.gif',
			imageBtnNext: 'images/lightbox/next.gif',
			imageBlank: 'images/lightbox/blank.gif'
		});
		
		$('header, section').waypoint(function(event) {
			var target = (event.target.id)?'.' + event.target.id:'.home';
			$('li', '#main-nav').removeClass('active');
			$(target, '#main-nav').addClass('active');
			event.stopPropagation();
		}, {
			triggerOnce: false
		});
		
		$('footer').waypoint(function(event) {
			$('li', '#main-nav').removeClass('active');
			$('.contact', '#main-nav').addClass('active');
			event.stopPropagation();
		}, {
			triggerOnce: false,
			offset: 'bottom-in-view'
		});

		var wst = 0;
		$('#mountains_1').css({backgroundPosition:'0px 0%'});
		$('#mountains_2').css({backgroundPosition:'0px 0%'});
		$('#mountains_3').css({backgroundPosition:'0px 0%'});
		
		var mountainAnim = function() {
			wst++;
			$('#mountains_1').css({backgroundPosition:parseInt(wst*3) + 'px 0%'});
			$('#mountains_2').css({backgroundPosition:parseInt(wst*1) + 'px 0%'});
			$('#mountains_3').css({backgroundPosition:parseInt(wst*0.5) + 'px 0%'});
			
			setTimeout(mountainAnim, 50);
		}
		
		mountainAnim();
	}
}); 

function submit_form(form) {
	var filter		= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var pass		= true;

	form.email.className = form.name.className = form.comments.className = '';
		
	if(form.email.value == '' || !filter.test(form.email.value)) {
		form.email.className = 'invalid';
		form.email.onfocus = function() {
			this.className = '';
		}
		pass = false;
	}
	if(form.comments.value == '') {
		form.comments.className = 'invalid';
		form.comments.onfocus = function() {
			this.className = '';
		}
		pass = false;
	}
	if(form.name.value == '') {
		form.name.className = 'invalid';
		form.name.onfocus = function() {
			this.className = '';
		}
		pass = false;
	}
	
	if(pass) {
		var val		= {name:form.name.value, email:form.email.value, comments:form.comments.value};
		var $form	= $(form);
		$('#form_msg').remove();
		$form.fadeOut('fast', function() {
			var $enquiry_form = $("div.enquiry", "#contact");
			$enquiry_form.append("<div class='progress'><img width='180' height='18' src='images/progress.gif' /></div>");
			$.post('enquiry.php', val, function(data) {
				if(data.response == 'success') {
					$('.progress', $enquiry_form).fadeOut('fast', function(){
						$(this).remove();
						$enquiry_form.append("<div id='form_msg'><h2>Thank you for getting in touch.</h2><p>We hope to respond within two working days. If you have not heard from us after this time, please feel free to contact us.</p></div>");
					});
					$("#name, #email, #comments").val('');
				} else {
					$('.progress', $enquiry_form).fadeOut('fast', function() {
						$enquiry_form.prepend("<div id='form_msg'>Please enter a valid email address.</div");
						$(this).remove();
						form.email.className = 'invalid';
						$('form', $enquiry_form).fadeIn('fast');
					});
				}
			}, 'json');
		});
		
	}

	return false;
}
