//------------------------------------
//	SEC1.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.4.2
//------------------------------------

//CUFON
Cufon.replace('#content h2:not(.noCufon),h3,#services dt,h4,#contact_button');

$(function(){
//BEGIN jQuery

	// FORM VALUE TITLE SWAP THINGY	
	
	$('form input[title]:not([value])').each(function(){
		$(this).attr('value', $(this).attr('title'));
	});
	$('form input[title]').live('focus',function(){
		if($(this).attr('value') == $(this).attr('title')){
			$(this).attr('value', '');
		}
	});
	$('form input[title]').live('blur',function(){
		if($(this).attr('value') == $(this).attr('title') || $(this).attr('value') == ''){
			$(this).attr('value', $(this).attr('title'));
		}
	});

	// VARIABLES

	sHover = false;
	nHover = false;

	// ENTER

	$('#navigation li.services').mouseenter(function(){
		nHover = true;
		navState('hover');
		$('#services').show();
	});
	
	$('#services').mouseenter(function(){
		sHover = true;
		navState('hover');
		$('#services').show();
	});
	
	// LEAVE
	
	$('#navigation li.services').mouseleave(function(){
		if(sHover == false){
			nHover = false;
			$('#services').hide();
			navState('off');
		}
	});
	
	$('#services').mouseleave(function(){
		if(nHover == false){
			sHover = false;
			$('#services').hide();
			navState('off');
		}
	});
	
	// NAV STATE
	
	function navState(e){
		if(e == 'hover'){
			$('#navigation li.services a').addClass('hover');
		}else{
			$('#navigation li.services a').removeClass('hover');
		}
	}
	
	
	// CALL BACK COLORBOX
	
	$('#callusnow a').colorbox({
		iframe : 		true,
		scrolling :		false,
		speed :			200,
		initialWidth :	479,
		initialHeight :	333,
		innerWidth :	479,
		innerHeight :	333
	});
	
	$('#thankyou a').live('click',function(){
		$.fn.colorbox.close();
		return false;
	});


//END jQuery
});

/*
 * jQuery Timer Plugin
 * http://www.evanbot.com/article/jquery-timer-plugin/23
 *
 * @version      1.0
 * @copyright    2009 Evan Byrne (http://www.evanbot.com)
 */

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

//EASING

jQuery.extend(jQuery.easing,{
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutExpo: function(x,t,b,c,d){
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}
});


// MINI PLUGINS

(function($){
	$.fn.theHop = function(kind,alt) {
		e = this.get(0).tagName;
		if(!alt) return this.closest(kind).siblings(kind).find(e);
		if(alt) return this.closest(kind).siblings(alt).find(e);
	};
})(jQuery);

(function($){
	$.fn.kidnapClass = function(c) {
		e = this.get(0).tagName;
		return this.addClass(c).siblings(e).removeClass(c);
	};
})(jQuery);


//CHECK FOR VALID ENTRYS

function checkphone(phone_number) {
	return phone_number.length > 9 && phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/);
}

function checkMphone(phone_number) {
	return phone_number.length > 9 && phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
}
