
$(document).ready(function() {

	stickLinks();
	hoverImages();
	makeExternalLinks();
	makeDropDowns();
	loadBrowserCSS();
	makeEmailLinks();
	
});


function makeEmailLinks() {

	$('a[rel*=email]').each(function(){
		var email = $(this).attr("href").replace("#", "") + "@" + $(this).attr("title");
		$(this).attr("title", email);
		$(this).attr("href", "mailto:" + email);
		if ($(this).html() == "") $(this).html(email);
	});
	
}

function loadBrowserCSS() {

	var stylesheet = $.browser.name + "." + $.browser.versionNumber + ".css"
	
	if (stylesheet == 'msie.6.css') {
		$("#browserStyle").attr("href", "/global/css/" + stylesheet);
	}
}



function makeExternalLinks() {

	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});

}

function stickLinks() {

	$('a').each(function(i) {
	
		link_parts = this.href.split("/", 10);
		page = link_parts[(link_parts.length - 1)];
		link_section = link_parts[(link_parts.length - 2)];

		if (this.href == document.location) $(this).addClass("stick");
		if (this.href == document.location + "index.htm") $(this).addClass("stick");

	});

}

function hoverImages() {

	$(".hover").mouseover( function() {
		$(this).attr('src', $(this).attr('src').replace(/.jpg/,"_hover.jpg"));
		$(this).attr('src', $(this).attr('src').replace(/.gif/,"_hover.gif"));
		$(this).attr('src', $(this).attr('src').replace(/.png/,"_hover.png"));
	});
	$(".hover").mouseout( function() {
		$(this).attr('src', $(this).attr('src').replace(/_hover.jpg/,".jpg"));
		$(this).attr('src', $(this).attr('src').replace(/_hover.gif/,".gif"));
		$(this).attr('src', $(this).attr('src').replace(/_hover.png/,".png"));
	});
}



function makeEmail(name, domain, text) {

	if (text == '') text = name + '@' + domain;

	document.write('<a href="mailto:' + name + '@' + domain + '">' + text + '</a>');

}


function makeDropDowns() {

	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	$('#nav > li').bind('mouseover', jsddm_open);
   	$('#nav > li').bind('mouseout',  jsddm_timer);
	$(document).bind('click',  jsddm_close);
	
	function jsddm_open() {  
		jsddm_canceltimer();
   		jsddm_close();
   		ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	}

	function jsddm_close() {
		if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	}

	function jsddm_timer() {
		closetimer = window.setTimeout(jsddm_close, timeout);
	}

	function jsddm_canceltimer() {  
		if(closetimer) {  
			window.clearTimeout(closetimer);
      		closetimer = null;
		}
	}
}


