/*  File: basic.js          */
/*  By:   Jeremy Tredway    */
/*  Ver:  2008-09-28        */


// extend browseer object to define IE6
$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);


// obfuscate address function
function obfsMail(s,e,h,d,c) {
	//if (e == "" || h == "") { return; }
	if (d == "") { d = "com"; }
	var x = e + "&#x40;" + h + "&#x2E;" + d;
	if (c == "") { c = x; }
	var y = "href=\"ma" + "ilto:" + x + "\"";
	var z = (s == "") ? ("<a " + y + ">" + c + "</a>") : ("<a class=\"" + s + "\" " + y + ">" + c + "</a>");
	return z;
}


// onload routines
$(function(){

	// init print store locator
	$('.print-store-location').click(function() {
		window.print();
		return false;
	});


	// initialize header navigation active state
	$("#header_nav").find("a").each(function() {
		if (location.href.indexOf(this.href) != -1) {
			$(this).addClass("active");
		}
	});

	// initialize grub landing navigation for IE6
	if ($.browser.msie6) {
		$("#grub_nav li img").each(function() {
			var img_src = $(this).attr('src').replace('/img/grub/', '/img/grub/ie6/');
			$(this).attr('src', img_src);
		});
	}

	// fix grub landing navigation large image click
	$("#grub_nav li img").click(function() {
		var grub_url = $(this).parents('a').attr('href');
		location.href = grub_url;
	});

	// initialize grub landing navigation hover state
	$("#grub_nav a").hover(
		function() { $(this).addClass("hover"); }, 
		function() { $(this).removeClass("hover"); }
	);

	// initialize drilldown navigation hover and active state
	$("#drilldown_nav a").hover(
		function() { $(this).parent().addClass("hover"); }, 
		function() { $(this).parent().removeClass("hover"); }
	);
	$("#drilldown_nav").find("a").each(function() {
		if (location.href.indexOf(this.href) != -1) {
			$(this).parent().addClass("active");
		}
	});

	// fix footer navigation borders
	$("#footer_nav ul").find("li:last").addClass("last");

	// initialize obfuscated addresses
	$(".obfmail").each(function() {
		var $this = $(this);
		var params = $this.attr("rel").split(":");
		if (params[0] == "email") {
			var addr = obfsMail("",params[1],"gamergrub","","");
		}
		$this.html(addr);
	});

	// set external links
	$("a[@href^=http]").each(function () {
		if(this.href.indexOf(location.hostname) == -1) {
			$(this).attr("target", "_blank");
		}
	});

});


