jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#content', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
});

	$(document).ready(function() {  
		
			var myFile = document.location.toString();
		
			if (myFile.match('#')) {
				var myAnchor = '#' + myFile.split('#')[1];		
				$("a[href='"+myAnchor+"']").parent().siblings().removeClass('current');
				$("a[href='"+myAnchor+"']").parent().addClass('current');
			} 
			else 
			{
				$('ul#navigation li:first').addClass("current");
			}
	
			$('.sup a').click(function(){
				$(this).parent().siblings().removeClass('current');
				$(this).parent().addClass('current');
			});
			
			
			window.setTimeout(function() {
			 $('#cta span').fadeIn("20");
			}, 6000);
			
			// Expand Panel
			$("#open").click(function(){
				var p = $("ul#navigation");
				var position = p.position();
				
				$("div#panel").slideDown("slow");	

			});	

			// Collapse Panel
			$("#close").click(function(){
				$("div#panel").slideUp("slow");	
			});		

			// Switch buttons from "Log In | Register" to "Close Panel" on click
			$("#toggle a").click(function () {
				$("#toggle a").toggle();
			});
	
		});
		
function showpanel() {
	$("div#panel").slideDown("slow");	
}


function validate_email(bait,em)
{
	if(bait == 'bait') { //spam honeytrap ... 'bait' still there then not spam
	
		if($('#epos').val() == '')
		{
			alert("Please fill in your email address.");
			return;
		}
		else
		{
			$('#oops_email').html('checking...');

			if (echeck($('#epos').val())) {
				$('#oops_email').html('');
				sendcv();
			}
			else
			{
		
				$('#oops_email').html('Problem with email format');
				//$('username').style.border = '1px red solid';
				//DOMCall('password').focus();
			}
		}
	} //bait
}



function echeck(str) 
	{

		var at="@"
		var dot="."
		var var_email_check = "Email Ok"
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return false	
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false	
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   return false
		 }

		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true		
	}


function sendcv()
{
	//Basic error checking
	

		//Construct the AJAX object, add all form fields in the register_form to the paramaters
			$.ajax({
				url : "ajax.php",
				data : 'm=cv&' +  $("#sendcv").serialize(),
				dataType : "text",
				type: "POST",
			  	success: function (t) 
				{
					if(t="1") 
					{
						$("#sendcv").hide();
						$('#cvlink').fadeIn("20");
					}
					else if(t="0") 
					{
						$('#oops_email').html = 'Sorry there was a problem with the followup email.';
					}
				}
			});
			

}


function send_sms(bait,contactname,telnr)
{
	//Basic error checking
	

	if(bait == 'bait')  //spam honeytrap ... 'bait' still there then not spam
	{	
		if($('#contactname').val() == '' || $('#telnr').val()  == '')
		{
			alert("Please fill in your contact details.");
			return;
		}
		else
		{
			//Construct the AJAX object, add all form fields in the register_form to the paramaters
			$.ajax({
				url : "ajax.php",
				data : 'm=sms&' +  $("#contactme").serialize() +'&msisdn=27833263496',
				dataType : "text",
				type: "POST",
			  	success: function (t) 
				{
					if(t="1") 
					{
						$("#contactme").hide();
						$('#smslink').fadeIn("20");
					}
					else if(t="0") 
					{
						$('#oops_sms').html = 'Sorry there was a problem with SMS processing.';
					}
				}
			});
		}
	} //bait

}

