/* -----------------------------------------------
   JavaScript Framework v2.0
   Copyright to James Kirby - www.jameskirby.me.uk
   Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 UK: England & Wales License (http://creativecommons.org/licenses/by-nc-nd/2.0/uk/)
----------------------------------------------- */

$(document).ready(function() {
	$(".page-item-end").addClass('end');
	tips();
});

function tips() {
	var tipall = new Array(
		"Pre race: Select a team captain, who may or may not be the \"captain\" once the race starts",
		"Pre race: Captain should make a gear checklist for everyone broken down into mandatory and other",
		"Pre race: Make sure you have all your gear well before the race; don't scramble the last day to get stuff because you may not be near the right store at the race site",
		"Pre race: Get your bike completely cleaned/lubed/checked 10 days before the race and then ride it a few times to make sure it is okay",
		"Pre race: Check 5 day forecast for your race area and bring the appropriate clothing; don't leave much behind b/c you'd rather have it than not",
		"Pre race: Do as much info gathering on the race course as you can",
		"Pre race: Try not to get to the race site at the last minute; try to get through registration and gear check-in first b/c you'll want as much time as possible to prepare and/or rest",
		"Pre race: Establish the team's goals and strategy for the race – make sure everyone is on the same page well before the race starts",
		"Pre race: Determine how much sleep the team will get, how much time between stops, etc.",
		"Pre race: If you can, do a team gear check when you get to the race site",
		"Pre race: Get your food bags ready before the race – Have several smaller ones rather than 1 large one; mix your food in the small bags so you aren't rummaging through many bags just to eat",
		"Pre race: The day of the race: continue to drink water (but not too much because you'll dilute your sodium level) and Gatorade like a madman - some people like to eat a lot of salty stuff b/c it makes you retain water which is a good thing before a race",
		"Pre race: Be organized for your gear check-in; only have your mandatory stuff (no food or other gear)",
		"Pre race: One way to do check-in is: 1. double small ziplock bag all medical stuff and put it in the backpack; 2. put mandatory lighter, headlamp, compass and extra headlamp batteries in a ziplock in the backpack; 3. wear lifejacket and have the mandatory whistle and knife attached to it and put the mandatory throw bag and dry bag in the backpack; 4. put mandatory gore-tex jacket and fleece top in the backpack; 5. wear climbing harness and have attached all required carabiners/slings/rapelling devices/jumars and put mandatory climbing helmet in backpack; 6. wear the mandatory bike helmet and take bike with lights, pump and repair kit all together.",
		"Pre race: Have a 2 or 3mm accessory cord attached to your waterproof map case so you can hang it around your neck",
		"Pre race: Wear the case so when you get your map and passport, you can put them in the case and never take the case off your neck",
		"Pre race: After check-in, go back and organize all your gear in your pack; pack unnecessary stuff at bottom and important stuff on top and in easily reached outside pockets",
		"Pre race: Mark up your route on the map(s) then cover both sides of the map with contact paper to make it waterproof and cover both sides of each page of the passport with clear heavy duty packing tape",
		"Pre race: Check your bike tires several times throughout the day to make sure there isn't a surprise flat 2 minutes before the race starts or before they take your bike away (it happens!)",
		"Pre race: Make sure at least 2 people have odometers on their bikes and set them to 0 before the race",
		"Pre race: Set your altimeter watches for reference barometric pressure and altitude",
		"Pre race: Go to the start line and have fun!!"
	);
	var tipran = Math.floor(Math.random()*tipall.length);
	var tipcontent = tipall[tipran];
	$('#tips_content').append(tipcontent);
}

/* ----------------------
   Scripts
---------------------- */


/* Popup:
popup(URL, Width, Height, Left, Top, AutoCenter[0=False, 1=True], FullScreen[0=False, 1=True])
<a href="javascript:popUp('domain', 640, 480, 50, 50, 1, 0)">Popup!</a>
*/
function popup(URL, popWidth, popHeight, popLeft, popTop, autoCenter, fullScreen) {
	day = new Date();
	id = day.getTime();
	if ( autoCenter == 1 ) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	if ( fullScreen == 1 ) {
		// Open in Full Screen window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+(screen.width-10)+",height="+(screen.height-26)+",left=0,top=0');");
	} else {
		// Open in normal window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
	}
}


/* Konami Code - Just an easter egg :D */
if ( window.addEventListener ) {
	var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
	$(document).keydown(function(e) {
		kkeys.push( e.keyCode );
		if ( kkeys.toString().indexOf( konami ) >= 0 ){
			$(document).unbind('keydown',arguments.callee);
			alert("Created by James Kirby");
			window.location = "http://www.jameskirby.me.uk/";
		}
	});
};


/* ----------------------
   Contact Functions
---------------------- */
/*
$(document).ready(function() {

	///////////////////////////////////

	$("#formFirstName").blur(function() {
		var formFirstNameError = false;
 		if ( $(this).val().length < 3 ) {
 			formFirstNameError = true;
 		}
 		if ( formFirstNameError == true ) {
 			$("#formFirstName").css('background-color','#FFDADA');
 			$("#formFirstNameError").css('color','#D20000');
 		} else {
 			$("#formFirstName").css('background-color','#FFF');
 			$("#formFirstNameError").css('color','#666');
 		}
	});
	
	
	///////////////////////////////////
	
	$("#formLastName").blur(function() {
		var formLastNameError = false;
 		if ( $(this).val().length < 3 ) {
 			formLastNameError = true;
 		}
 		if ( formLastNameError == true ) {
 			$("#formLastName").css('background-color','#FFDADA');
 			$("#formLastNameError").css('color','#D20000');
 		} else {
 			$("#formLastName").css('background-color','#FFF');
 			$("#formLastNameError").css('color','#666');
 		}
	});
	
	
	///////////////////////////////////
	
	$("#formEmail").blur(function() {
		var formEmailError = false;
 		if ( echeck($(this).val()) == false ) {
 			formEmailError = true;
 		}
 		if ( formEmailError == true ) {
 			$("#formEmail").css('background-color','#FFDADA');
 			$("#formEmailError").css('color','#D20000');
 		} else {
 			$("#formEmail").css('background-color','#FFF');
 			$("#formEmailError").css('color','#666');
 		}
	});
	
	///////////////////////////////////
	
	$("#formTelephone").blur(function() {
		var formTelephoneError = false;
 		if ( $(this).val().length < 11 ) {
 			formTelephoneError = true;
 		}
 		if ( formTelephoneError == true ) {
 			$("#formTelephone").css('background-color','#FFDADA');
 			$("#formTelephoneError").css('color','#D20000');
 		} else {
 			$("#formTelephone").css('background-color','#FFF');
 			$("#formTelephoneError").css('color','#666');
 		}
	});
	
	$("#formTelephone").keypress(function (e) { 
	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
	  	$("#formTelephone").css('background-color','#FFDADA');
			$("#formTelephoneError").css('color','#D20000');
			return false;
    }	else {
			$("#formTelephone").css('background-color','#FFF');
			$("#formTelephoneError").css('color','#666');
			return true;
    }
	});
	
	///////////////////////////////////
	
	$("#formFax").keypress(function (e) { 
	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
			$("#formFax").css('background-color','#FFDADA');
			$("#formFaxError").css('color','#D20000');
			return false;
    }	else {
			$("#formFax").css('background-color','#FFF');
			$("#formFaxError").css('color','#666');
			return true;
    }
	});
	
	///////////////////////////////////

	$("#formHotelName").blur(function() {
		var formHotelNameError = false;
 		if ( $(this).val().length < 3 ) {
 			formHotelNameError = true;
 		}
 		if ( formHotelNameError == true ) {
 			$("#formHotelName").css('background-color','#FFDADA');
 			$("#formHotelNameError").css('color','#D20000');
 		} else {
 			$("#formHotelName").css('background-color','#FFF');
 			$("#formHotelNameError").css('color','#666');
 		}
	});
	
	///////////////////////////////////

	$("#formHotelAddress").blur(function() {
		var formHotelAddressError = false;
 		if ( $(this).val().length < 3 ) {
 			formHotelAddressError = true;
 		}
 		if ( formHotelAddressError == true ) {
 			$("#formHotelAddress").css('background-color','#FFDADA');
 			$("#formHotelAddressError").css('color','#D20000');
 		} else {
 			$("#formHotelAddress").css('background-color','#FFF');
 			$("#formHotelAddressError").css('color','#666');
 		}
	});
	
	///////////////////////////////////
	
	$("#formHotelRooms").keypress(function (e) { 
	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
			$("#formHotelRooms").css('background-color','#FFDADA');
			$("#formHotelRoomsError").css('color','#D20000');
			return false;
    }	else {
			$("#formHotelRooms").css('background-color','#FFF');
			$("#formHotelRoomsError").css('color','#666');
			return true;
    }
	});
	
	///////////////////////////////////
	
	$("#formMessage").blur(function() {
		var formMessageError = false;
 		if ( $(this).val().length < 3 ) {
 			formMessageError = true;
 		}
 		if ( formMessageError == true ) {
 			$("#formMessage").css('background-color','#FFDADA');
 			$("#formMessageError").css('color','#D20000');
 		} else {
 			$("#formMessage").css('background-color','#FFF');
 			$("#formMessageError").css('color','#666');
 		}
	});
	
	///////////////////////////////////
	
	$("#submit").click(function() {
		formSubmitError = false;
		
		if ( $("#formFirstName").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( $("#formLastName").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( echeck($("#formEmail").val()) == false ) {
			formSubmitError = true;
		}
		if ( $("#formTelephone").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( $("#formHotelName").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( $("#formHotelAddress").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( $("#formMessage").val().length < 3 ) {
			formSubmitError = true;
		}
		if ( formSubmitError == true ) {
			return false;
		} else {
			return true;
		}
	});
});

function echeck(str) {
	var at="@";
	var dot=".";
	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;				
}
*/
