// JavaScript Document
// alert('hi');

$(document).ready(function(){ 
       
		
		// prepend a circle to any nav link
		$("div#nav li").prepend("&bull;&nbsp;");
		
		
		
		
		// $("ul#foot_main_links li").prepend("&bull;&nbsp;");
		
		
		// Colour the main heading to match category colour code
		if($("div#sidepanel > ul.category_menu")) {
		
			//alert($("div#sidepanel > ul.category_menu").css("background-color"));
			// $("td > h1").css("color", $("div#sidepanel > ul.category_menu").css("background-color"));
			// $("td > h1").css("border-color", $("div#sidepanel > ul.category_menu").css("background-color"));
			
			
			// prepend an arrow to category lists
			$("td ul.category_mainpanel_list li").prepend("&rArr;&nbsp;&nbsp;&nbsp;");
			// colour these arrows
			$("td ul.category_mainpanel_list").css("color", $("div#sidepanel > ul.category_menu").css("background-color"));
		}
		
		
		
		
		if($("#overview > img.illustration")) {
		
			// start the timer
			changeIll = setInterval ("nextIll()", 5000 );
		
		
		}
		
		
	

		// IE <=6 Conditional Stuff
		var ie6 = false;
		var ie = false;
		
		if (jQuery.browser.msie) {
		  
		  ie = true;
		  
		  if(parseInt(jQuery.browser.version) <= 6) {
			
			
			ie6 = true;
			
			
			if($("a.logo_home img[src$='.png']")) {
				var logo_img = $("a.logo_home img").attr('src');
				var gif_logo = logo_img.replace(".png", ".gif");
				$("a.logo_home img").attr('src', gif_logo);
			}
			
			if($("img.illustration[src$='.png']")) {
				var ill_img = $("img.illustration").attr('src');
				var gif_ill = ill_img.replace(".png", ".gif");
				$("img.illustration").attr('src', gif_ill);
			}

			
			
			// 
			
			
			
		  }
		} 
		
		
	// set up twitter stuff
	$("#twitter").getTwitter({
		userName: "bourkecollege",
		numTweets: 1,
		loaderText: "Loading tweets...",
		slideIn: true,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: false
	});



		
		
	   
}); 




function nextIll() {

	var stt = $("#overview > img.illustration");

	//alert(stt.attr('src'));
	img_name = stt.attr('src');
	img_no = img_name.charAt(13);


	next_no = (img_no * 1) + 1;
	//alert(next_no);


	if(next_no > 3) {

		next_no = 1;	

	}

	
	//alert(next_no);
	if(ie6) {
		
		stt.attr('src', 'media/rotate_' + next_no + '.gif');
	
	} else {
		
		stt.attr('src', 'media/rotate_' + next_no + '.png');
	
	}


	

}




function validateOnSubmitTrainerCV() {


	var fieldPrefix = 't';
	var errorString = '';
	
	if (!document.getElementById(fieldPrefix + 'name').value) {
		errorString += "\n- Please enter your first name.";
	}
	
	// test for valid email address
	contactEmail = document.getElementById(fieldPrefix + 'email').value;
	var emailRE = /^[a-zA-Z][\w\+\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	if (!(emailRE.test(contactEmail))) {
		// not valid
		errorString += "\n- Please enter a valid email address.";
	}
	
	
	// test whether there's a valid phone number in the field
	contactTel = document.getElementById(fieldPrefix + 'phone').value;
	var telRE = /^[0-9 +)(-]{7,16}$/;
	if (!(telRE.test(contactTel))) {
		// not valid
		errorString += "\n- Please enter a valid phone number.";
	}

	
	if (!document.getElementById(fieldPrefix + 'area').value) {
		errorString += "\n- Please enter your area of expertise.";
	}
	
	
	if (!document.getElementById(fieldPrefix + 'cv').value) {
		errorString += "\n- Please attach your CV before submitting this form.";
	}
	
	
	if(errorString.length>0) {
		alert('Please correct the error(s) below before continuing:' + errorString);
		return false;
	}
	else {
		// alert("no errors found");
		return true;
	}

}




