jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function imgOff(img) {
	img.attr("src",img.attr("src").replace("_hover", "_off"));
}

function imgHover(img) {
	img.attr("src",img.attr("src").replace("_off", "_hover"));
}

function docready(hash)
{
	var submenu = $("#" + hash + "_link");
	submenu.trigger('click');
}

$(document).ready(function() {
	$.preloadImages("images/liarrow_hover.png","images/liarrowdown_hover.png","images/backover.png","images/werehiring_hover.png",
	"images/ico_di_hover.png", "images/ico_f_hover.png", "images/ico_m_hover.png", "images/ico_b_hover.png", "images/werehiring_hover.png");

	$(".submenu").click(function() {
		var show = $(this).next(".submenuContent").is(':hidden');

		$(".submenu").children("img").attr('src','images/liarrow.png');
		$(".submenu").removeClass("hover");
		$(this).addClass("hover");
		$(".submenuContent").hide();
		if(show) {
			$(this).next(".submenuContent").show();
			$(this).children("img").attr('src','images/liarrowdown_hover.png');
			
			var exploded = $(this).attr('id').split("_");
			var hash = exploded[0];
			$.history.load(hash);
		} else {
			$(this).next(".submenuContent").hide();
			$(this).children("img").attr('src','images/liarrow_hover.png');
			
			var exploded = $(this).attr('id').split("_");
			var hash = exploded[0];
			$.history.load("");
		}

		return false;
	});
	
	$(".submenu").hover(
		function() {
			if($(this).next(".submenuContent").is(':hidden')) {
				$(this).addClass("hover");
				$(this).children("img").attr('src','images/liarrow_hover.png');
			}
		},
		function() {
			if($(this).next(".submenuContent").is(':hidden')) {
				$(this).removeClass("hover");
				$(this).children("img").attr('src','images/liarrow.png');
			}
		}
	);
	
	$("#goback").hover(
		function() {
			$(this).attr('src','images/backover.png');
		},
		function() {
			$(this).attr('src','images/back.png');
		}
	);
	
	$("#hiring").hover(
		function() {
			$(this).attr('src','images/werehiring_hover.png');
		},
		function() {
			$(this).attr('src','images/werehiring.png');
		}
	);
	
	 $(".buttonImg").bind("mouseover",function() {
		 imgHover($(this));
	 });
	 
	 $(".buttonImg").bind("mouseout",function() {
		 imgOff($(this));
	 });
	 
	 $.history.init(docready);
});