
$(document).ready(function() {


	makeDropDowns();


	
});





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');
		
		var parent_width = $(this).width();
		var dropdown_width = $(this).find('ul').width();
		
		var offset = dropdown_width - parent_width + 27;
		
		$(this).find('ul').css('margin-left', -1 * offset);
		
		
	}

	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;
		}
	}
}


