$(document).ready(function(){	
	
	$("#services .contents").jCarouselLite({btnNext: ".next",btnPrev: ".prev"});
	$("#feedback").newsticker();
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\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 pattern.test(emailAddress);
	}

	function isNum(number) {
		var pattern = new RegExp('[0-9]');
		return pattern.test(number);
	}
	
	$('#contact-name').focus(function() {
		if($('#contact-name').val() == 'This field is required' ) $('#contact-name').val('');
	}).blur(function() {
		if($('#contact-name').val() == 'This field is required' ) $('#contact-name').val('');
	});
	
	$('#contact-message').focus(function() {
		if($('#contact-message').val() == 'This field is required' ) $('#contact-message').val('');
	}).blur(function() {
		if($('#contact-message').val() == 'This field is required' ) $('#contact-message').val('');
	});

	$('#contact-email').focus(function() {
		if($('#contact-email').val() == 'This field is required.Please enter a valid email: E.g. yourname@domain.com' ) $('#contact-email').val('');
	}).blur(function() {
		if($('#contact-email').val() == 'This field is required.Please enter a valid email: E.g. yourname@domain.com' ) $('#contact-email').val('');
	});
	
	$('#contact-tel').focus(function() {
		if($('#contact-tel').val() == 'This field is required. Please enter a valid phone.' ) $('#contact-tel').val('');
	}).blur(function() {
		if($('#contact-tel').val() == 'This field is required. Please enter a valid phone.') $('#contact-tel').val('');
	});

	$('#contact-form').submit(function() {
		var is_submit = false;
		var is_contact = false;
		var is_email = false;
		var is_phone = false;
		var is_messenger = false;
		
		if($('#contact-name').val() == '' ){
			is_contact = false;
			$('#contact-name').val('This field is required');
			
		}else {
			is_contact = true;
		}
	
		
		if(!isValidEmailAddress($('#contact-email').val())){
			is_email = false;
			$('#contact-email').val('This field is required.Please enter a valid email: E.g. yourname@domain.com');
		}else{
			is_email = true;
		}
		
		if(!isNum($('#contact-tel').val())){
			is_phone = false;
			$('#contact-tel').val('This field is required. Please enter a valid phone.');
		}else{
			is_phone = true;
		}
		
		if($('#contact-message').val() == '' ){
			is_messenger = false;
			$('#contact-message').val('This field is required');
			
		}else {
			is_messenger = true;
		}
		
		if(is_contact && is_email && is_phone && is_messenger){
			is_submit = true;
		}
		else{
			is_submit = false;
		}
			
		
		
		return is_submit;
	});
	
	$('#chat-name').focus(function() {
	if(	$('#chat-name').val() == 'Name' || 	$('#chat-name').val() == 'Your name is required.' ) 
		$('#chat-name').val('');
	}).blur(function() {
		if(	$('#chat-name').val() == '' ) 
			$('#chat-name').val('Name');
	});
	
	$('#chat-company').focus(function() {
		if(	$('#chat-company').val() == 'Company' || 	$('#chat-company').val() == 'We require your company name.' ) 
			$('#chat-company').val('');
	}).blur(function() {
		if(	$('#chat-company').val() == '' ) 
			$('#chat-company').val('Company');
	
	});
	
	$('#chat-message').focus(function() {
		if(	$('#chat-message').val() == 'Type Message' || 	$('#chat-message').val() == 'We require a subject for your call.' ) 
			$('#chat-message').val('');
	}).blur(function() {
		if(	$('#chat-message').val() == '' ) 
			$('#chat-message').val('Type Message');
	});
	
	$('#nearest').focus(function() {
		if(	$('#nearest').val() == 'Enter Post Code' ) 
			$('#nearest').val('');
	}).blur(function() {
		if(	$('#nearest').val() == '' ) 
			$('#nearest').val('Enter Post Code');
	});
	
	$('#pcode').focus(function() {
		if(	$('#pcode').val() == 'Postcode, Area' ) 
			$('#pcode').val('');
	}).blur(function() {
		if(	$('#pcode').val() == '' ) 
			$('#pcode').val('Postcode, Area');
	});
	
	$('#popup').click(function() {
		$('#frm-chat-now').submit();
	});
	$('#frm-chat-now').submit(function() {
	
		submit_form = true;
	
		if( $('#chat-name').val() == '' || $('#chat-name').val() == 'Name' || $('#chat-name').val() == 'Your name is required.' )
		{
			$('#chat-name').val('Your name is required.');
			submit_form = false;
		}
	
		if( $('#chat-company').val() == '' || $('#chat-company').val() == 'Company' || $('#chat-company').val() == 'We require your company name.' )
		{
			$('#chat-company').val('We require your company name.');
			submit_form = false;
		}
	
		if( $('#chat-message').val() == '' || $('#chat-message').val() == 'Type Message' || $('#chat-message').val() == 'We require a subject for your call.' )
		{
			$('#chat-message').val('We require a subject for your call.');
			submit_form = false;
		}
		
		if( submit_form )
		{
			window.open('http://84.22.168.199/instantChat.php', 'chat_window', 'width=340,height=400,resizeable,noscrollbars');
			this.target = 'chat_window';
			return true;
		}
		return false;
	
	});
	
	$('#live-sales-chat').click(function() {
		window.open('http://84.22.168.199/instantChat.php', 'chat_window', 'width=340,height=400,resizeable,noscrollbars');
		this.target = 'chat_window';
		return false;
	});
});

$(document).ready(function(){
	$('#success-folder').hide();
	var sub_open 			= false;
	var it_support_open 	= false;
	var company_open	= false;
	
	$('#subs').css({'opacity' : '0'});
	$('#it-support_child').css({'opacity' : '0'});
	$('#company_child').css({'opacity' : '0'});
	
	$('#it-support').click(function(){
		if(company_open){
			$('#company_child').animate({ 'opacity' : '0', 'height' : '0px'})
			$('#company').removeClass('active');
			company_open = false;
		}
		if(it_support_open){
			showSubsMenu('close', '0px');
			$('#it-support_child').animate({ 'opacity' : '0', 'height' : '0px' })
			$('#it-support').removeClass('active');
			it_support_open = false;
		}
		else{
			showSubsMenu('open', '144px');		
			$('#it-support_child').css({	'display' : 'block','height' : '189px'	})
			$('#it-support_child').animate({'opacity' : '1'}, 750)
			$('#it-support').addClass('active');
			it_support_open = true;
		}
		return false;
	})

	$('#company').click(function(){
		if(it_support_open){
			$('#it-support_child').animate({'opacity' : '0',	'height' : '0px'	})
			$('#it-support').removeClass('active');
			it_support_open = false;
		}
		if(company_open){
			showSubsMenu('close', '0px');
			$('#company_child').animate({'opacity' : '0','height' : '0px'	})
			$('#company').removeClass('active');
			company_open = false;
		}
		else{
			showSubsMenu('open', '144px');
			$('#company_child').css({'display' : 'block','height' : '189px'	})
			$('#company_child').animate({'opacity' : '1'}, 750)
			$('#company').addClass('active');
			company_open = true;
		}		
		return false;
	})
	
	function showSubsMenu (action, height){
		if(action == 'open' || !sub_open){
			$('#subs').css({'opacity' : '1','display' : 'block',	'overflow' : 'hidden'})
			$('#subs').animate({'height' : height}, 750)
			sub_open = true;
		}else if(action == 'close'){
			$('#subs').animate({'height' : '0px'}, 250)
			sub_open = false;
		}
	}
})

/* show sub menu when hover */
$(document).ready(function(){
	
	$('#it-services_child > ul > li').mouseenter(function(){
		$('#it-services_child > ul > li > div').css({'display' : 'none'})
		$(this).children('div').css({	'display' : 'block'	})
	});

	/*
		  $("#benefits > li > div").each(function(){
				$(this).height($(this).children("p").each($(this).height()));
		  })
	
	*/
			var i = 0;
			$("#benefits > li > .content").each(function(){
				 i++;
				 if(i < 3){$(this).show();}else{
					$(this).hide();
				 }
				
			})

		  $("#benefits > li > span > a").click(function(){
				$(this).parent().parent().children(".content").slideToggle("slow");
				return false;
		  })
		  
})


/*
 * caculator price section
 */
$(document).ready(function(){
					
			function tooltip(id, errormess){
				$(id).html("topRight").qtip({
					content: {
						text: errormess,
						title: {
							text: '',
							button: 'x' // Show a close link in the title,
						}

					},
					position: {
						corner: {
							tooltip: "bottomLeft", // Use the corner...
							target: "topRight" // ...and opposite corner
						}
					},
					show: {
						when: false, // Don't specify a show event
						ready: true, // Show the tooltip when ready
						solo: true,
						effect: { type: 'slide' }
						
					},
					hide: false, // Don't specify a hide event
					style: {
						border: {
							width: 11,
							radius: 10,
							color: '#911D1D'
						},
						title:{
							'background': '#911D1D'
						},
					padding: 10,
					background: '#911D1D',
					textAlign: 'center',
					tip: true, 
					name: 'dark'
					}
				});
			}		
			
			var formcheck = true;
			var formopen = false;
			var fromtouch = false;
			
			var namecheck = true;
			var emailcheck = true;
			var phonecheck = true;
			var workstationcheck = true;
			var servercheck = true;
			
			var first_form = true;
			var second_form = false;
			var third_form = false
			
			var mess = "";
			var currente;
			
			nameElement = $("#quote-form").find("input[name=name]");
			emailElement = $("#quote-form").find("input[name=email]");
			phoneElement = $("#quote-form").find("input[name=phone]");
			workstationElement = $("#quote-form").find("input[name=workstations]");
			serverElement = $("#quote-form").find("input[name=servers]");
			
			$("#calculate").click(function(){
				if( first_form ){
					$("#quote-container").animate({ marginLeft : "-400px" }, 500 );
					first_form = false;
					second_form = true;
					return false;
				}else if( second_form ){
					formcheck = true;
					if( !validateName() ){
						mess = "This field is required. This field accepts alphabetic characters only.";
						formcheck = false;
						currente = nameElement;
						tooltip(currente, mess);
						return false;
					}
					if( !validateEmail() ){
						mess = "This field is required. Please enter a valid email: E.g. yourname@domain.com";
						formcheck = false;
						currente = emailElement;
						tooltip(currente, mess);
						return false;
					}
					
					if( !validatePhone() ){
						mess = "This field is required. Please enter a valid phone.";
						formcheck = false;
						currente = phoneElement;
						tooltip(currente, mess);
						return false;
					}
					
					if( !validateWorkstation() ){
						mess = "This field is required. Please enter a valid integer.";
						formcheck = false;
						currente = workstationElement;
						tooltip(currente, mess);
						return false;
					}
					
					if( !validateServer() ){
						mess = "This field is required. Please enter a valid integer.";
						formcheck = false;
						currente = serverElement;
						tooltip(currente, mess);
						return false;
					}
					
					if( formcheck ){
					$("#quote-container").animate({ marginLeft : "-800px" }, 500 );
						$('#fm-calculator').submit();
						$.post("/instantQuote.php");
						second_form = false;
						third_form = true;
						return false;
					}
					/*
					else{
						tooltip(currente, mess);
						return false;
					}
					*/
					return false;
				}else if( thirdform ) {
					$("#quote-container").animate({ marginLeft : "-400px" }, 500 );
					second_form = true;
					third_form = false;
				}
			});
			
			$("#quote-form").find("input[name=fm_name]").focus(function(){
				tooltip($(this), "This field is required. This field accepts alphabetic characters only");
			});
			
			$("#quote-form").find("input[name=fm_email]").focus(function(){
				tooltip($(this), "This field is required.Please enter a valid email: E.g. yourname@domain.com");
			});
			
			$("#quote-form").find("input[name=fm_phone]").focus(function(){
				tooltip($(this), "This field is required. Please enter a valid phone.");
			});
			
			$("#quote-form").find("input[name=fm_workstations]").focus(function(){
				tooltip($(this), "This field is required. Please enter a valid integer. The length is incorrect, it must be between 1 and 6");
			});
			
			
			$("#quote-form").find("input[name=fm_servers]").focus(function(){
				tooltip($(this), "This field is required. Please enter a valid integer. The length is incorrect, it must be between 1 and 6");
			});		
		});
	
	
		var news_open = false;
		var contact_open = false;
		var success_open = false;
	
		function open_news(){
			if(contact_open) {
				$("#contact-folder").animate({
					"opacity" : "0"
				}, 750);
				contact_open = false;
			}
			
			if(success_open) {
				$("#success-folder").animate({
					"opacity" : "0"
				}, 750);
				success_open = false;
			}
			
			if(news_open){
				showFolder("close", "0px");
				$("#news-folder").animate({
					"opacity":"0",
					"height" : "0px"
				});
				
				news_open = false;
			}else{
			
				showFolder("open", "400px");
				
				
				$("#news-folder").css({
					"height":"400px",
					"z-index" : "10",
					"visibility":"visible",
					"display":"block"
				});
				
				$("#news-folder").animate({
					"opacity":"1"
				}, 750);
				
				news_open = true;
			}
			return false;
		};
	
		function open_contact() {
			
			if(news_open){
				$("#news-folder").animate({
					"opacity" : "0"
				}, 750)
				news_open = false;
			}
			if(success_open)	{
				showFolder("close");
				$("#success-folder").animate({
					"opacity" : "0"
				}, 750)
				success_open = false;
				return false;
			}
			if(contact_open){
				showFolder("close", "0px");
				$("#contact-folder").animate({
					"opacity":"0",
					"height" : "0px"
				});
				contact_open = false;
			}else{
				showFolder("open", "425px");
				$("#contact-folder").css({
					"z-index" : "10",
					"visibility":"visible",
					"display":"block",
					"height":"425px"
				});
				$("#contact-folder").animate({
					"opacity":"1"
				}, 750);
				contact_open = true;
			}
			return false;
		};
	
		function showFolder(action, height){
			
			if(action == "open"){
				$('#content-folder').css({
					"display":"block",
					"overflow":"hidden",
					"opacity":"1"
				});
				$("#content-folder").animate({
					"height": height
					
				}, 750)
			}
			else if(action == "close"){
				$("#content-folder").animate({
					"height": "0px"
				}, 300)
			}
		}
		
		function showContactForm()
		{
			window.alert("moo");
		}
		
		function showChat()
		{
			window.open("http://messenger.providesupport.com/messenger/littlefish.html", "", "width=500, height=550");
		}
		
		function Login()
		{
			window.name = "mainwin";
			window.open('/login', 'login', 'width=690, height=350, location=0, resizable=no');
			return false;
		}
		
		function MacCallingCard()
		{
			window.name = "callingcard";
			window.location.href='/webcallingcard/channel.htm';
			window.resizeTo(385, 429);
		}
		
		function ShowRescue()
		{
			document.getElementById('client-login').style.display = "none";
			document.getElementById('client-rescue').style.display = "block";
		}
		
		function resetClientLogin()
		{
			document.getElementById('client-login').style.display = "block";
			document.getElementById('client-rescue').style.display = "none";
		}
		
		var fileThickboxLoadingImage = "http://84.22.168.199/wp-content/plugins/wp-e-commerce/images/loadingAnimation.gif";
		
		var xmlHttp;

function showchatondelay()
{
  window.setTimeout("showchat()", 10000);
}

function showchat()
{
  if(!window.pageYOffset)
  {
    //strict mode
		if(!(document.documentElement.scrollTop == 0))
		{
			document.getElementById('chatbox').style.top = 50 + document.documentElement.scrollTop; + "px";
			document.getElementById('chatbox').style.left = 50 + document.documentElement.scrollLeft; + "px";
		}
		//quirks mode
		else
		{
			document.getElementById('chatbox').style.top = 50 + document.body.scrollTop; + "px";
			document.getElementById('chatbox').style.left = 50 + document.body.scrollLeft; + "px";
		}
  }
  else
  {		
		document.getElementById('chatbox').style.top = 50 + window.pageYOffset + "px";
    document.getElementById('chatbox').style.left = 50 + window.pageXOffset + "px";
  }
  
  document.getElementById('chatbox').style.display = "block";
}

function clearchatcookie()
{ 
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
  var url = "/includes/clearchatcookie.php";
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
 xmlDoc=xmlHttp.responseXML;
 return;
 }
} 

function GetXmlHttpObject()
{ 
  var objXMLHttp=null
  if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp;
}

function closechat()
{
  clearchatcookie();
  document.getElementById('chatbox').style.display = "none";
}