/***********************************************************************************************************
														BEGINNING OF JAVASCRIPT WRITTEN BY CLINTON MONTAGUE
***********************************************************************************************************/

	/*Clickable blocks function*/
$.fn.clickableBlocks = function ()
{
	return this.each (function () {
		var $this = $(this);
		var $anchor = $this.find("a");
		if ($anchor.length)
		{
			$this.css("cursor", "pointer").click (function ()
			{
				location.href = $anchor[0].href;
			});
		}
	});
}


$(function () {

	
	// this is a rather naughty hack to get SF menus working without poisoning the mark-up
	// It's so nasty that I'm not even giving it a name and running it automatically ;)
	// commented out as it causes empty ul not required anymore...
	/*(function () {
		$("#nav_main li").each (function () {
			if (!$(this).children("li").length)
			{
				$(this).append("<ul><li></li></ul>");
			}
		});
	})();*/
	// /END OF THE HACK
	
	/** Nav main superfish stuff **/
	$actives = $("#nav_main .active");
		
	$("#nav_main").superfish({
		dropShadows: false,
		autoArrows: false,
		pathLevels: 3,
		onInit: function () { $actives.addClass("active");},
		pathClass: 'active'
	});
	/*$("#nav_main>li").hover (function () {
		$(this).addClass('hover');
		if (!$(this).children('ul').length)
		{
			$("#nav_main ul.active").hide();
		}
	}, function () {
		$(this).removeClass('hover');
		$("#nav_main ul.active").show();
	});*/
	$(".kwick").hover (function () {
		$(".kwick").removeClass('hover');
		$(this).addClass('hover');
	}, function () {
		$(this).removeClass('hover');
		$("#home_buyers_guide").addClass('hover');
	});
	
	
	/** Home page kwicks **/
	$(".kwick ul").kwicks({
		max: 470,
		spacing: 10
	});
	$(".kwick ul li").css({'cursor':'pointer'});
	$(".kwick ul li").children().css({opacity:0, 'cursor':'pointer'});
	$(".kwick ul li").hover (function () {
		var contH = $(this).children('.hover_cont').height();
		$(this).children('.hover_cont').stop().animate({opacity:1}, 500);
		$(this).children('.hover_mask').css({height:contH});
		$(this).children('.hover_mask').stop().animate({opacity:0.75}, 500);
		$(this).addClass("active");
		}, function () {
		$(this).children().stop().animate({opacity: 0}, 250);
		$(this).removeClass("active");
	});
	


	//Get a click on any part of the li to go to the location the a tag points to...
	$(".kwick ul li.active").live("click", function()	{
		window.location = $(this).find('a').attr('href');
	});
	// end kwicks


});



/************ Interesting use of jQuery Objects may replicate in future **************/
/***** NO LONGER NEEDED *****/
/* buyer's guide lighting */
/*
$(function () {
	$halogens = $("a[href^=/buyers-guide/lighting/halogen]", "#content");
	$leds = $("a[href^=/buyers-guide/lighting/led]", "#content");
	$optics = $("a[href^=/buyers-guide/lighting/fibre-optic]", "#content");
	$flourescents = $("a[href^=/buyers-guide/lighting/fluorescent]", "#content");
	$halogens.hover (function () {
		$halogens.addClass('hover');
	}, function () {
		$halogens.removeClass('hover');
	});
	$leds.hover (function () {
		$leds.addClass('hover');
	}, function () {
		$leds.removeClass('hover');
	});
	$optics.hover (function () {
		$optics.addClass('hover');
	}, function () {
		$optics.removeClass('hover');
	});
	$flourescents.hover (function () {
		$flourescents.addClass('hover');
	}, function () {
		$flourescents.removeClass('hover');
	});
});
*/

/******************************** END OF CLINTON'S JAVASCRIPT ********************************/

/***********************************************************************************************************
														BEGINNING OF JAVASCRIPT WRITTEN BY ADAM ONISHI
***********************************************************************************************************/


/**************************************
		jQuery for Showcases Section
**************************************/

$(function () {
	
	var mveMarg = 0;
	var mveMax = -732;
	
	$sc_imageContainer = $("#image-container ul");
	//left and right... left moves the list right - right moves the list left!!
	$("#navi-left a").click(function() {
		if(mveMarg != 0){
			$("li.nav-number a#img-2").removeClass("active");			
			mveMarg = mveMarg + 732;
			$sc_imageContainer.stop().animate({marginLeft: mveMarg}, 1000);
			$("li.nav-number a#img-1").addClass("active");		
		}
		
		return false;
	});
	
	$("#navi-right a").click(function() {
		if(mveMarg != mveMax){
			$("li.nav-number a").removeClass("active");
			mveMarg = mveMarg - 732;
			$sc_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
			
			$("li.nav-number a#img-2").addClass("active");	
		}
		
		return false;
	});
	
	//individual image button click...
	$("li.nav-number a#img-1").click( function() {
		$("li.nav-number a").removeClass("active");
		$(this).addClass("active");
		//alert("hello world");
		mveMarg = 0;
		$sc_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
		
		return false;
	});
	
	$("li.nav-number a#img-2").click( function() {
		$("li.nav-number a").removeClass("active");
		$(this).addClass("active");
		//alert("hello world");
		mveMarg = -732;
		$sc_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
		
		return false;
	});
		
});


$(function () {
	if ($("#years-container").length) // only use this easing for the timeline page
	{
	/*
	 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
	 *
	 * Uses the built in easing capabilities added In jQuery 1.1
	 * to offer multiple easing options
	 *
	 * TERMS OF USE - jQuery Easing
	 * 
	 * Open source under the BSD License. 
	 * 
	 * Copyright å© 2008 George McGinley Smith
	 * All rights reserved.
	 * 
	 * Redistribution and use in source and binary forms, with or without modification, 
	 * are permitted provided that the following conditions are met:
	 * 
	 * Redistributions of source code must retain the above copyright notice, this list of 
	 * conditions and the following disclaimer.
	 * Redistributions in binary form must reproduce the above copyright notice, this list 
	 * of conditions and the following disclaimer in the documentation and/or other materials 
	 * provided with the distribution.
	 * 
	 * Neither the name of the author nor the names of contributors may be used to endorse 
	 * or promote products derived from this software without specific prior written permission.
	 * 
	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	 * OF THE POSSIBILITY OF SUCH DAMAGE. 
	 *
	*/
	
	// t: current time, b: begInnIng value, c: change In value, d: duration
	jQuery.easing['jswing'] = jQuery.easing['swing'];
	
	jQuery.extend( jQuery.easing,
	{ // CM: put this on a diet as we don't need it all
		def: 'easeOutExpo',
		swing: function (x, t, b, c, d) {
			//alert(jQuery.easing.default);
			return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
		},
		easeOutExpo: function (x, t, b, c, d) {
			return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
		}
	});
	
	/*
	 *
	 * TERMS OF USE - EASING EQUATIONS
	 * 
	 * Open source under the BSD License. 
	 * 
	 * Copyright å© 2001 Robert Penner
	 * All rights reserved.
	 * 
	 * Redistribution and use in source and binary forms, with or without modification, 
	 * are permitted provided that the following conditions are met:
	 * 
	 * Redistributions of source code must retain the above copyright notice, this list of 
	 * conditions and the following disclaimer.
	 * Redistributions in binary form must reproduce the above copyright notice, this list 
	 * of conditions and the following disclaimer in the documentation and/or other materials 
	 * provided with the distribution.
	 * 
	 * Neither the name of the author nor the names of contributors may be used to endorse 
	 * or promote products derived from this software without specific prior written permission.
	 * 
	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	 * OF THE POSSIBILITY OF SUCH DAMAGE. 
	 *
	 */
	
	
	} // end easing for timeline
});

	//move values 
	var mvAmount = 306;
	var mvMarg = 336;
	//max and mins of moving...
	var mvMax = 336;
	var mvMin = -5254;
	//marker margin variables
	var markerMvA = 49;
	var markerMvM = 6;
	//offset variables for pages
	var pageOffset = 0;
	var offsetSet = 'false';
	var resizeSet = 'false';
	var curPos = 0;

$(window).resize(function() {
	resizeSet = 'true';
	offsetSet = 'false';
});

$(document).ready( function() {
	$("img#marker").css({marginLeft: 748});
	$("#years-container ul.year-list").css({marginLeft: -4254 });
	curPos = 15;
	mvMarg = -4254;
	markerMvM = 748;
	resizeSet = 'true';
	offsetSet = 'false';
	
	
});
$(function () {
	

	$("img#marker").draggable({ containment: 'parent' , axis: 'x', grid:[49,0] , 
		start: function(event, ui) { 
			
			if(offsetSet=='false'){
				var markerPos = $(this).offset();
				
				if(resizeSet=='true'){
					var currentMOffset = curPos * 49;
					pageOffset = markerPos.left - currentMOffset;
				}
				else {
					pageOffset = markerPos.left;
				}
								
				offsetSet = 'true';
			}
			
		},
		stop: function(event, ui) { 
			var markerPos = $(this).offset();
			//work out the new position of the list using markerPos.left
			var trythis = markerPos.left - pageOffset;//alert(trythis);
			//alert(mvMarg+"=>"+trythis);
			trythis = trythis / 49;
			curPos = trythis;
			mvMarg = (trythis * -306) + 336;
			$("#years-container ul.year-list").animate({marginLeft: mvMarg}, 750);
			
		}
	});
	
	
	//beggining of arrow controlling movement
	
	
	$("a#years-left").click( function () {
		//move the list right!
		//by addition...
	
		if(mvMarg<mvMax){
		
			mvMarg = mvMarg + mvAmount;	
			$("#years-container ul.year-list").animate({marginLeft: mvMarg }, 750);
			//alert(mvMarg);
			
			markerMvM = markerMvM - markerMvA;	
			$("img#marker").animate({marginLeft: markerMvM}, 500);
	
			if(offsetSet=='false'){ 
				curPos--;	
				resizeSet = 'true'; 
			}
		}
		
	});
	
	$("a#years-right").click( function () {
		//move the list left!
		//by subtraction...
		if(mvMarg>mvMin){
			mvMarg = mvMarg - mvAmount;		
			$("#years-container ul.year-list").animate({marginLeft: mvMarg}, 750);
			//alert(mvMarg);
		
			markerMvM = markerMvM + markerMvA;	
			$("img#marker").animate({marginLeft: markerMvM }, 750);
	
			if(offsetSet=='false'){ 
				curPos++;	
				resizeSet = 'true'; 
			}
		}

	});
	
	
	$(".case-hover").css({marginTop: '15px'});
	$(".case-hover").clickableBlocks();
	
	$(".year-list li .case-study").hover(
    function () {
    	$(".year-list li .case-study").css({'z-index':'1'});
    	$(this).css({'z-index':'9999'});
    	
    	$(this).find(".case-hover").stop().animate({marginTop: '0px'}, 300).show();
    }, 
    function () {
    	$(this).find(".case-hover").stop().animate({marginTop: '15px'}, 200,
    		function() {
    			$(this).hide()
    			$(this).css({'z-index':'1'});
    		}
    	);
  	}
  );
});



/*******************************************
 	  	jQuery for Case Studies Map Page
*******************************************/

/**
 * CM: Apologies for the rather rushed an almost certainly shoddy comments
 */
$(function () {
	if (document.getElementById('countries'))
	{
		// disable the :hover state from the CSS
		// (there is an override rule for .hasJS)
		
		
		if (!jQuery.browser.msie || !(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) { 
				
		$("#countries").addClass("hasJS");
		
				
		// Store the current z-indexes for future use
		$("#countries > div").each(function () {
			$(this).data('zIDX', $(this).css("z-index"));
		}).click (function () {
			if ($(this).children(".list-container").is(":hidden"))
			{
				$(this).addClass('active');
				$(this).siblings().removeClass('active');
				// open child .list-container 's - close all others
				$(".list-container").fadeOut("fast");
				$(".map").each (function () {
					$(this).css('z-index', $(this).data('zIDX'));
				});
				$(this).css("z-index", 1000);
				$(this).children(".list-container").fadeIn("fast").append('<span class="case-study-map-close">Close</span>');
				// small hack to make UK appear above europe for a better UX
				if ($(this).attr("id")=='map-europe')
				{
					$("#map-uk").css('z-index', '1001');
				}
			}
		});
		// close .list-container 's if click on a place on the map that's not 'hot'
		$("#countries").click (function (e) {
				if ($(".list-container:visible").length)
				{
					if (!$(e.target).hasClass('map'))
					{
						$(".list-container").fadeOut('fast').parent().removeClass('active');
					}
				}
		});
		$(document).keyup(function(event){
			if (event.keyCode == 27) {
				$(".list-container").fadeOut('fast').parent().removeClass('active');
			}
		});
		$(".case-study-map-close").live("click", function () {
			$(".list-container").fadeOut('fast').parent().removeClass('active');
		});
	}
	
	}
});



/******************************************
jQuery for Individual Case Studies Section
******************************************/

$(document).ready(function() {
	//initialise the content area of the page by hiding the text and showing image 1 and more info buttons and nav
	$("#mask").css({opacity: 0}).show();	
	$("#cs-content-container").css({opacity: 0}).show();	
	$("a#close-button").hide();	
	
	//initialise jScrollPane...
	$("#cs-content").jScrollPane({dragMaxHeight: 50, dragMinHeight: 50});
	
}); //end of document ready function!


$(function () {

	//showing the mask and content....
	$("a#more-info").click(function() {
		$(this).hide();
		$("#img-nav").css({opacity:0}).show();
		$("a#close-button").css({opacity:0}).show();
		
		$("#mask").stop().animate ( {
			opacity:'0.69',
			width: '750px',
			height: '507px' }, 
			1000, 
			function() {
				$("#cs-content-container").stop().animate ({opacity: '1'}, 1000, 
				function() {
					$("a#close-button").stop().animate ({opacity:'1'}, 500);
				});	
			}
		);
			
		return false;	
	});
	
	//removing the mask and content....
	$("a#close-button").click(function() {
		$(this).hide();
		$("a#more-info").css({opacity:0}).show();
		$("#img-nav").css({opacity:0}).show();
		$("#cs-content-container").animate({opacity:0},400, function() {
			$("#mask").animate({width: 0, height: 0, opacity:0}, 600, function() {
				$("a#more-info").stop().animate ({opacity: '1'}, 1000);
				$("#img-nav").stop().animate ({opacity: '1'}, 1000);
			});
		});		
		
		return false;
	});
	
	//navigating the images....
	//variable for the list margin
	function assignActive(movedMarg) {
		var img_no;
		
		if(movedMarg!=0){
			img_no = movedMarg / -750 + 1;
			$("li a#" + img_no).addClass("active");
		}
		else{
			$("li a#1").addClass("active"); 
		}
	}
	
		
	var mveMarg = 0;
	//work out the maximum for moving the images
	var count_list = $("#img-nav ul").children().length - 3;
	var mveMax = -750 * count_list;
	
	//alert(mveMax);
	
	$cs_imageContainer = $("#cs-image-container ul");
	//left and right... left moves the list right - right moves the list left!!
	$("#nav-left a").click(function() {
		if(mveMarg != 0){
			$("li.nav-num a").removeClass("active");
			mveMarg = mveMarg + 750;
			$cs_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
			assignActive(mveMarg);
		}
					
		return false;
	});
	
	$("#nav-right a").click(function() {
		if(mveMarg != mveMax){
			$("li.nav-num a").removeClass("active");
			mveMarg = mveMarg - 750;
			$cs_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
			assignActive(mveMarg);
		}
		return false;
	});
	
	//individual image button click...
	$("li.nav-num a").click( function() {
		$("li.nav-num a").removeClass("active");
		var cur_id = $(this).attr('id');
		mveMarg = -750 * (cur_id - 1);
		$cs_imageContainer.stop().animate ({marginLeft: mveMarg}, 1000);
		$(this).addClass("active");
		return false;
	});
		
}); //end of functions...


/*******************************************
 	  	jQuery for Case Studies Dropdown
*******************************************/
/*

*******************************************
		NO LONGER WANTED AS A DROPDOWN
*******************************************
$(document).ready(function() {
	
	nav = navigator.platform;
	//alert(nav);
	if(/mac/i.test(nav)){
		$("#dropdown").css({marginLeft:-2});
	}
	
	
});

$(function () {
		
	$("a#dropdown-button").click( function () {
		var winH = $(document).height();
		var winW = $(document).width();
		
		if(window.location.pathname!="/case-studies/view-all/") {
			$("#dropdown").css({'display':'block'});
			$("a#dropdown-button").addClass("active");
			
			$("#dropdown-mask").css({'height':winH, 'width':winW, 'display':'block' }).show();

			return false;
		}
	});
	
	$("#dropdown-mask").click( function() {
		$("#dropdown").css({'display':'none'});
		$("a#dropdown-button").removeClass("active");
		
		$("#dropdown-mask").css({'height':'0', 'width':'0', 'display':'none' }).hide();
		
	});				
	$("a#close-dropdown").click( function() {
		$("#dropdown").css({'display':'none'});
		$("a#dropdown-button").removeClass("active");
		
		$("#dropdown-mask").css({'height':'0', 'width':'0', 'display':'none' }).hide();
	});				
		
});

*/



/********************************************
			jQuery for Buyers Guide Images
********************************************/

$("#photography .photos .hover_cont").clickableBlocks();

$(function () {
	$("#photography .photos").children('.hover_cont').css({opacity:0, 'cursor':'pointer'});
	$("#photography .photos").children('.hover_mask').css({opacity:0, 'cursor':'pointer'});
	$("#photography .photos").hover (function () {
			var cont2H = $(this).children('.hover_cont').height();
			$(this).children('.hover_cont').stop().animate({opacity:1}, 500);
			$(this).children('.hover_mask').css({height:cont2H});
			$(this).children('.hover_mask').stop().animate({opacity:0.85}, 500);
			$(this).addClass("active");
			}, function () {
			$(this).children('.hover_cont').stop().animate({opacity: 0}, 250);
			$(this).children('.hover_mask').stop().animate({opacity: 0}, 250);
			$(this).removeClass("active");
		});
	});
	
/********************************************
			jQuery for Brochure forms
********************************************/	

$(document).ready( function () {
});

$(function () {
	
	$("a#showcase_download").click( function () {
		
		if (!jQuery.browser.msie || parseInt(jQuery.browser.version) == 6) { 

			var formTop = ($(window).height() / 2) - 250;
			var formLeft = ($(window).width() / 2) - 350;
		
			var maskH = $(document).height() + 100;
			var maskW = $(document).width();
			
			$("#brochure-mask").css({'height':maskH,'width':maskW});
			
			$("#brochure-mask").stop().fadeTo(500, 0.69, function () {
    		$("#brochure-form-container").css({'top':formTop,'left':formLeft, opacity:0}).show();
				$("#brochure-form-container").stop().animate({opacity:1},300);        
   		});
		
		//alert('Back soon down for maintainance');	
		
  	}
  	else {
  		$("#ie-mask").show();
  		$("#brochure-form-container").css({'opacity':0}).stop().animate({opacity: 1},500).show();      
    
		//alert('Back soon down for maintainance');	
  	}  
    
		/* CAN USE EITHER CODE (ABOVE OR BELOW) STILL NEITHER WORKS IN IE8/7!!!!!!!!!!!!!!!!!!!!!!!
		$("#brochure-mask").css({'display':'block','opacity':'0'}).stop().animate({'opacity':'0.69'},500,function() {
			$("#brochure-form-container").css({'top':formTop,'left':formLeft, opacity:0}).show();
			$("#brochure-form-container").stop().animate({opacity:1},300);
		});
		*/
			
	});
	
	$("#brochure-form a#brochure-form-close").click( function () {
		if (!jQuery.browser.msie  || parseInt(jQuery.browser.version) == 6) { 
			//$("#brochure-mask").css({opacity:0}).hide();
			//$("#brochure-form-container").hide();
			if(location.href == 'http://www.clicknetherfield.com/news-and-events/latest-news/#') 
				location.href = 'http://www.clicknetherfield.com/news-and-events/latest-news/';
			else 
				location.href = 'http://www.clicknetherfield.com/blog/';
		}
		else {
			//$("#ie-mask").hide();
			//$("#brochure-form-container").css({'opacity':1}).stop().animate({opacity: 0},500).hide();
			if(location.href == 'http://www.clicknetherfield.com/news-and-events/latest-news/#') 
				location.href = 'http://www.clicknetherfield.com/news-and-events/latest-news/';
			else 
				location.href = 'http://www.clicknetherfield.com/blog/';
		}
	});
	
	
	$("#brochure-mask").click( function () {
		$(this).css({opacity:0}).hide();
		$("#brochure-form-container").hide();
	});
	
	if (jQuery.browser.msie || parseInt(jQuery.browser.version) == 6) { 
		$("#ie-mask").click( function () {
			$(this).hide();
			$("#brochure-form-container").css({'opacity':1}).stop().animate({opacity: 0},500).hide();
		});
	}
		
	$("#brochure-form form").submit (function () {
		var fullname = $(this).find("input[name=fullname]");
		var address1 = $(this).find("input[name=address1]");
		var postcode = $(this).find("input[name=postcode]");
		var email = $(this).find("input[name=email]");
		var name = $(this).find("input[name=name]");
		var description = $(this).find("input[name=description]");
		var role = $(this).find("input[name=role]");
		var source = $(this).find("input[name=source]");
		/*if ( VALIDATOR.isEmpty( fullname.val() ) )
		{
			alert('Please enter your name');
			fullname.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty( address1.val() ) )
		{
			alert ('Please enter your address');
			address1.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (postcode.val()) )
		{
			alert ('Please enter your postcode');
			postcode.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (email.val()) || !VALIDATOR.isEmail (email.val()) )
		{
			alert ('Please enter your email address');
			email.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (name.val()) )
		{
			alert ('Please enter your company name');
			name.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (description.val()) )
		{
			alert ('Please enter your company description');
			description.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (role.val()) )
		{
			alert ('Please enter your role');
			role.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (source.val()) )
		{
			alert ('Please enter how did you hear about ClickNetherfield?');
			source.focus();
			return false;
		}*/
		return true;
	});
	$("form#contact-us").submit (function () {
		var fullname = $(this).find ("input[name=fullname]");
		var email = $(this).find("input[name=email]");
		var company = $(this).find("input[name=company]");
		var request = $(this).find("textarea[name=request]");
		if (VALIDATOR.isEmpty (fullname.val()))
		{
			alert ('Please enter your name');
			fullname.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (email.val()) || !VALIDATOR.isEmail (email.val()) )
		{
			alert('Please enter your email address');
			email.focus();
			return false;
		}
		else if ( VALIDATOR.isEmpty (company.val()) )
		{
			alert('Please enter your company name');
			company.focus();
			return false;
		}
		else if (VALIDATOR.isEmpty (request.val()) )
		{
			alert('Please type your message into the text box');
			request.focus();
			return false;
		}
		return true;
	});
});



var VALIDATOR = {
	isEmpty: function (str) {
		return str === "";
	},
	isEmail: function (str) {
		var regex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
		return regex.test(str);
	}
};
 
 
 /************************************
 				TACTICAL BOX HOVER
 ************************************/
 
$(function () {
 
 $(".tactical_box").hover (function () {
		$(this).children("h4").css({'border-top-color':'#941521'});
	}, function () {
		$(this).children("h4").css({'border-top-color':'#221313'});
	});
});
 
/*********************************
			COMPLETE SOLUTIONS
*********************************/
$(function() {
	
	var steps = {	concept:1, 
								design:2, 
								evaluation:3, 
								manufacturing:4, 
								quality:5, 
								delivery:6, 
								installation:7, 
								support:8
							};
	
	var arrow_margins = {0:35, 1:-594, 2:-594, 3:-903, 4:-1212, 5:-1521, 6:-1830, 7:-2139, 8:-2139};
	var arrow_steps = {1:"concept", 2:"design", 3:"evaluation", 4:"manufacturing", 5:"quality", 6:"delivery", 7:"installation", 8:"support"};
	
	$("#nav_container ul li").hover(
		function(){
			$(this).children("h1").addClass("hover");
		},
		function() {
			$(this).children("h1").removeClass("hover");
		}
	);

	var distance = 0;

	$("p.discover_link a").click(function() {
		$("#nav_container ul li").removeClass("active");
		distance = 1;
		$("ul#project_cycle").stop().animate({"marginLeft":arrow_margins[distance]},800);
		$("#nav_container ul li#" + arrow_steps[distance]).addClass("active");
	});

	$("#nav_container ul li").click(function() {
		$("#nav_container ul li").removeClass("active");
		$(this).addClass("active");
		var step = $(this).attr("id");
		distance = steps[step];
		$("ul#project_cycle").stop().animate({"marginLeft":arrow_margins[distance]},800);
	});
	
	$("#main_timeline_container a#left_nav").click(function() {
		distance = distance - 1
		if(distance!=-1){
			$("#nav_container ul li").removeClass("active");
			$("ul#project_cycle").stop().animate({"marginLeft":arrow_margins[distance]},800);
			$("#nav_container ul li#" + arrow_steps[distance]).addClass("active");
		}
		else{
			distance = 0;
		}
	});

	$("#main_timeline_container a#right_nav").click(function() {
		distance = distance + 1
		if(distance!=9){
			$("#nav_container ul li").removeClass("active");
			$("ul#project_cycle").stop().animate({"marginLeft":arrow_margins[distance]},800);
			$("#nav_container ul li#" + arrow_steps[distance]).addClass("active");
		}
		else{
			distance = 8;
		}
	});


});
 

/**************************************
			jQuery for Contact Map
**************************************/

$(document).ready( function () {
	$("#contact-mask").css({'opacity':0.69});
	$("a.office-link span").css({'top':15});
});

$(function () {
	
	$("a.office-link").hover( 
		function () {
			$("a.office-link").css({'z-index':'1'});
    	$(this).css({'z-index':'9999'});
			
			$(this).children("span").stop().animate({top:5},200).show();
		},
		function () {
			$(this).children("span").css({'top':'15px'}).hide();
			$(this).css({'z-index':'1'});
		});
	
	
	$("a.office-link").click( function () {
		$(this).children("span").css({'top':'15px'}).hide();
		var o_link = $(this).attr("id");
		
		if(o_link!='scotland'&&o_link!='england'&&o_link!='america'&&o_link!='australia'&&o_link!='greece'&&o_link!='turkey'&&o_link!='australia'&&o_link!='singapore'&&o_link!='egypt'&&o_link!='qatar'&&o_link!='china'&&o_link!='japan'){
			var office = "?send=1&office=";
			office += $(this).attr("id");
			$("form#contact-us").attr("action", office);
		
			$("#contact-mask").css({'opacity':0}).show();
			$("#contact-mask").stop().animate({opacity:0.69},500, function(){			
				$("#contact-form-container").stop().animate({opacity:1},400).show();
			});
		}
		
	});
	
	$("a#scotland").click(function() {
		$("div.head-offices").hide();
		$("div#scotland-office").show();
	});
	
	$("a#england").click(function() {
		$("div.head-offices").hide();
		$("div#england-office").show();
	});
	
	$("a#america").click(function() {
		$("div.head-offices").hide();
		$("div#usa-office").show();
	});
	
	$("a#greece").click(function() {
		$("div.head-offices").hide();
		$("div#greece-office").show();
	});
	
	$("a#turkey").click(function() {
		$("div.head-offices").hide();
		$("div#turkey-office").show();
	});
	
	$("a#australia").click(function() {
		$("div.head-offices").hide();
		$("div#australia-office").show();
	});
	
	$("a#singapore").click(function() {
		$("div.head-offices").hide();
		$("div#singapore-office").show();
	});
	
	$("a#egypt").click(function() {
		$("div.head-offices").hide();
		$("div#egypt-office").show();
	});
	
	$("a#qatar").click(function() {
		$("div.head-offices").hide();
		$("div#qatar-office").show();
	});

	$("a#china").click(function() {
		$("div.head-offices").hide();
		$("div#china-office").show();
	});

	$("a#japan").click(function() {
		$("div.head-offices").hide();
		$("div#japan-office").show();
	});
	
	$("#contact-form a#contact-form-close").click( function () {
		$("#contact-mask").css({opacity:0}).hide();
		$("#contact-form-container").hide();
	});
	
	$("#contact-mask").click( function () {
		$(this).css({opacity:0}).hide();
		$("#contact-form-container").hide();
	});
			
}); 
 
/** Yeah, yeah, we know this is really really bad for accessibility - designers hated the 'dotted line around links' */

$(function () {
	$("a").click (function () {$(this).blur();});
});

// That's all, folks ;)
