$(document).ready(function(){
	colourOptions(readCookie('ColourScheme'));
});
function colourOptions(id) {
	
		switch(id)
		{
			case 'default': 
				document.getElementById('cS').href='';
				createCookie('ColourScheme', 'default');
				break;
			case 'Green':
				document.getElementById('cS').href='green.css';
				createCookie('ColourScheme', 'Green');
				break;
			case 'Blue':
				document.getElementById('cS').href='blue.css';
				createCookie('ColourScheme', 'Blue');
				break;
			case 'Pink':
				document.getElementById('cS').href='pink.css';
				createCookie('ColourScheme', 'Pink');
				break;
			default:
				document.getElementById('cS').href='';
				createCookie('ColourScheme', 'default');
				break;
		}
	}
function homepageIntro() {
	$("#brightwellWelcome").fadeIn(1500, function(){
		$("#loadLine").animate({width: "900px"}, 1800, function() {
			$("#colourOptionsText").fadeIn(1000);
			$("#colourOptionsPantones").fadeIn(1000);
			$("#brightwellInteriorsLogo").fadeIn(1000);
			$("#navBar").fadeIn(1000);
			$("#brightwellInteriorsTelephone").fadeIn(1000);
			$("#brightwellWelcome").delay(1200).fadeOut(800, function() {
				$("#homeGallery").fadeIn(1000);
				$("#footer").fadeIn(1000);
				$('.flexslider').flexslider({
						slideshowSpeed: 3000,
						animationDuration: 500,
						pauseOnHover: true
				});
			});	
		});
	});
}
function showHideForm() {
	formHeight = $("#signUp").height();
	if(formHeight==30) {
		$("#signUp").animate({height: "320px"}, 1200);
		$("#content").animate({height: "194px"}, 1200);
	} else {
		$("#signUp").animate({height: "30px"}, 1200);
		$("#content").animate({height: "484px"}, 1200);
	}
}
function showFeatures(magName, magRow) {
	formHeight = $("#"+magName).height();
	if(formHeight==1) {
		$("#"+magName).animate({height: "140px"}, 1200);
		$("#"+magRow).animate({height: "445px"}, 1200);
	} else {
		$("#"+magName).animate({height: "1px"}, 1200);
	}
}
function checkEmailField() {
	
  var email = document.eventsForm.email.value;
  if (!isRFC822ValidEmail(email)) {
    alert("Please enter a valid email address.");
	} else {
	  document.eventsForm.submit();
	}
}
function isRFC822ValidEmail(sEmail) {

  var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  var sQuotedPair = '\\x5c[\\x00-\\x7f]';
  var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
  var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
  var sDomain_ref = sAtom;
  var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
  var sWord = '(' + sAtom + '|' + sQuotedString + ')';
  var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
  var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
  var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
  var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
  
  var reValidEmail = new RegExp(sValidEmail);
  
  if (reValidEmail.test(sEmail)) {
    return true;
  }
  
  return false;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


