// JavaScript Document

jQuery(function() {
	
	// to not use target="_blank" to keep the w3c validator happy
	$("a[rel=external]").each(function(){$(this).attr("target", "_blank")});

	$("a.linkBox").each(function(i, e) {
		var $link = $(this);
		
		var t = $link.attr('title');
		
		//$link.find('img').replaceWith("<div class='linkTitle'>" + t + "</div>");
		$link.append("<div class='linkTitle'>" + t + "</div>");
		var $img = $link.find('img');
		$link.css('background-image', $img.attr("src"));
	});
	
	
	var url = window.location.href;
	url = url.replace(/.*?\/\/.*?\//i, '/');
	url = url.replace(/\?.*/, "");
	
	if (url == "/") {	// all the links start with / so make this a special case
		var $currentLink = $("#sideMenu a[href='" + url + "']").addClass('current');
	} else {
		var $currentLink = $("#sideMenu a[href^='" + url + "']").addClass('current');
	
		// if this is a sub link, find the parent one and make that current too
	
		$currentLink.addClass('current')					// make the current link current
		.parents('.subSideMenu').addClass('current')		// if this is a sub menu link, add '.current' to the div containing the sub menu to make it appear 
		.parents('li').find("a:first").addClass('current');	// find the parent menu item (for when this is a sub menu link) and make that current too
		
		$currentLink.siblings('.subSideMenu').addClass('current');	// if this is a top level menu - show any applicable sub menu		
	}
	

});
