
var sgcn = {
	load: function() {
		sgcn.menuHidden = true;
		sgcn.timer = 0;
		sgcn.currentItem = null;
		sgcn.defaultImage = $("#headerImage").attr("src");


		$("#mainSubNav").css('opacity',0).css('width','0').hide();
		$("#mainNav li a").mouseover(function() {sgcn.showNav($(this));}).mouseout(function() {sgcn.startTimer();});
		$("#mainSubNav").mouseover(function() {sgcn.stopTimer();}).mouseout(function() {sgcn.startTimer();});

	},

	showNav: function(el) {
		sgcn.stopTimer();
		sgcn.currentItem = el.attr('rel');

		$("#mainNav a").removeClass('activated');
		el.addClass('activated');

		$('#mainSubNav').empty();

		if (typeof sgcnItems[el.attr('rel')] == 'undefined') {
			sgcn.hideNav();
			return;
		}

		$('#mainSubNav').append('<ul id="subNavItems"></ul>');

		// Append Each Child
		jQuery.each(sgcnItems[el.attr('rel')], function() {
			$('#subNavItems').append('<li><a href="' + SG_URL_PREFIX + this[1] + '">' + this[0] + '</a></li>');
		});

		// Animate
		if (sgcn.menuHidden) {
			$("#mainSubNav").show().animate({ width: "200px", opacity: 0.8 }, 600);
			sgcn.menuHidden = false;
		}
	},

	hideNav: function() {
		$("#mainNav a").removeClass('activated');
		if (!sgcn.menuHidden) {
			$("#mainSubNav").hide().animate({ width: 0, opacity: 0 }, 250);
			sgcn.menuHidden = true;
		}
	},

	stopTimer: function() {
		if (sgcn.timer) {
			clearTimeout(sgcn.timer);
			sgcn.timer = 0;
		}
	},

	startTimer: function(e) {
		sgcn.timer = setTimeout("sgcn.hideNav()", 250);
	}

}

