// Email safe send
function sgSafeSend(n,d,e,t) {
    var addy = n + '@' + d + '.' + e;
    var txt = (typeof(t) == 'undefined') ? addy : t;
    document.write('<a href="mailto:' + addy + '">' + txt + '</a>');
}

// Safe Plain Text Email Address
function sgSafeSendPlain(n,d,e) {
    var addy = n + '@' + d + '.' + e;
    document.write(addy);
}


function sgRunSlideshow() {
	
	var sc = $('ul.sg-slides');
	var timer = null;
	
	var slides = $('li',sc);
	
	sc.find('li:eq(0)').show();
	
	var changeit = function() {
		
		sc.find('li:eq(0)').next('li').fadeIn(3000, function() { 
															 sc.find('li:eq(0)').appendTo(sc).hide();
															 timer = setTimeout(function() { changeit(); },3500);
															 });
		
	}
	
	timer = setTimeout(function() { changeit(); },3500);
	
}

// Drop Down Navigation Helpers
function sg_menu() {
	
	$('ul#main-nav > li').each(function(i) {
		
		// Set min-width for submenu to size of parent nav item
		//$(this).find('ul:eq(0)').css('min-width',$(this).width() + 'px');
		
		var sgtimer = null;
		$(this).hover(
			function() { 
				// Clear the timeout
				clearTimeout(sgtimer); 

				// Hide Siblings Immediately
				var siblings = $(this).siblings('li');
				siblings.find('a:eq(0)').removeClass('active');
				siblings.find('ul').stop().css('height','').hide();
				
				// Reveal Current
				$(this).find('a:eq(0)').addClass('active');
				$('ul',$(this)).show(); //slideDown(); 
				
			},
			function() { 
				var obj = $('ul',$(this)); 
				var parent = $(this);
				// Hide after 1/3ish second
				
				if (obj.length > 0) {
					sgtimer = setTimeout(function() { parent.find('a:eq(0)').removeClass('active'); obj.hide(); }, 300); 
				} else {
					parent.find('a:eq(0)').removeClass('active'); obj.hide();
				}
			}
		);
	
		
	});

}


// HANDLE ON LOAD  EVENTS //
$(document).ready(function() {
		
	// TEMPORARY - disable #links
	$('a[href="#"]').click(function() {
		alert('This is not linked to anything yet');
		return false;
	});
	
	$('a[href^="??"]').click(function() {
		var msg = $(this).attr('rel');							  	
		alert(msg);
		return false;
	});
	
});
