$(document).ready(function() 
{
  // menusetup();
   windowLinks();
  		function addMega()
		{
        	$(this).addClass("hovering");
        }

      	function removeMega()
		{
        	$(this).removeClass("hovering");
        }

		var megaConfig = {
			 interval: 10,
			 sensitivity: 4,
			 over: addMega,
			 timeout: 100,
			 out: removeMega
		};

	    $("li.mega").hoverIntent(megaConfig);
		
		//latest jobs in left. script from http://visualrinse.com/2008/09/24/how-to-build-a-simple-rss-reader-with-jquery/
		
		//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
		$.get("http://www.protocol-education.com/jobshoptest/Candidates/Jobs/RSS.aspx?DoSearch=LatestJobs", function(d) {
			//find each 'item' in the file and parse it
			var html = "";
			var x = 0;
			$(d).find('item').each(function() {
				//name the current found item this for this particular loop run
				var $item = $(this);
				// grab the post title
				var title = $item.find('title').text();
				// grab the post's URL
				var link = $item.find('link').text();
				// next, the description
				var description = $item.find('description').text();
				//shorten description 
				
				//don't forget the pubdate
				var pubDate = $item.find('pubDate').text();
	 
				// now create a var 'html' to store the markup we're using to output the feed to the browser window
				html += "<div class=\"latestjob\"><p class=\"description\"><a href=\"" + link + "\" target=\"_blank\" style=\"text-decoration:none;\"><strong>" + title + "<\/strong><\/a>";
				//html +=  description + "</br>";
				html += "<br /><a href=\"" + link + "\" target=\"_blank\">View Job<\/a></p><\/div>";
				if(x >=5)
					return false;
				else
					x++;
				//put that feed content on the screen!
				
			});
			$("#latestjobsleft").empty();
			$('#latestjobsleft').append($(html));  
		}); /**/
 });
 

function doClear(theText) 
{
	 if (theText.value == "Email")
	{
		 theText.value = ""
	}
	 if (theText.value == "Password")
	{
		 theText.value = "";
		 theText.type = "password";
		 document.getElementById('password').type = 'password';
	}
	if(theText.value == "First name")
	{
		theText.value = "";
	}
	if(theText.value == "Surname")
	{
		theText.value = "";
	}
 }
 
 /* Menu Functions */
 	/*
	* Show the hand element on rollover of the menu
	*/
 	function showhand(hand)
	{
		var element = document.getElementById(hand);
		//element.style.background ='url(graphics/yellow-hand.jpg) no-repeat center center';
		element.className = "showhand";		
	}
	
	/*
	* Hide the hand element on rollout of the menu
	*/
	function hidehand(hand)
	{
		var element = document.getElementById(hand);
		//element.style.background ='';
		element.className = "nohand";
	}
	
	/*
	* Automatically set all the styles and actions for the menu
	*/
	function menusetup()
	{
		var id;
		var tr;
		var tds;
		var menulink;
		var linktochange;
		
		var table = document.getElementById('menutable');//get table element
		var tbody = document.getElementById('tbody');
		var alltrs = table.getElementsByTagName("tr");//get all trs
		var x = 0;
		for(x=0;x<alltrs.length;x++)
		{
			id = "";
			var count = x;
			id = 'hand'+count;
			tr = alltrs[x];
			tds = tr.getElementsByTagName("td");//get all tds
			firsttd = tds[0];
			firsttd.id = id;
			menulink = tds[1].getElementsByTagName("a");//get all tds
			linktochange = menulink[0];
			id2 = 'hand'+x;
			addOverFunc(linktochange,x);
			addLeaveFunc(linktochange,x);
		}
		
		/*
		* Add the over function
		*/
		function addOverFunc(element,id)
		{
			element.onmouseover = function() { showhand("hand"+id); }
		}
		/*
		*
		*/
		function addLeaveFunc(element,id)
		{
			element.onmouseout = function () { hidehand("hand"+id); }
		}
	}
	
	/* This is our old popup code - parts of the site still use it, so I need to keep it */
function acpopup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,scrollbars=1,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}


/* new accessible, unobtrusive popup code */

function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }
	
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
		 if (relIndex){
		 var relSplit = relIndex.split("|");
/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {
            anchor.target = "_blank";
			anchor.className = "external";
			anchor.title = "Load in new window: "+ anchor.href;
/* XHTML compliant popup attribute */
   			} else if (relSplit[0] == "popup") {
			anchor.className = "popup";
			anchor.title = "Link loads in Popup Window";
			anchor.popupWidth = relSplit[1];
			anchor.popupHeight = relSplit[2];
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			}
		}
	   }
} 
