/* Would need to check to make sure link doesn't include anchor... */
$(document).ready(function(){
	
	if(undefined != jQuery.url.attr("anchor")) {
		var anchor = jQuery.url.attr("anchor");
		var thefirst = anchor;
	} else {
		var thefirst = "shop";
	}
	
	// element loaded up.
	$("#central li").not("#"+thefirst).hide();
	$("#view-menu a#"+thefirst+"-link").addClass("focus");


	// Adding a class this way allows us to do all
	// JavaScript-dependent styles as '.js element' in the style sheets.
	$("body").addClass("js");

	// Remove title and create as EM tag.
	// This allows you to then style w/ CSS so it shows up on hover.
	// Makes me happy.
	$("#topnav a").each(function() {
		var title = $(this).attr("title");
		var href = $(this).attr("href");
		var txt = $(this).text();
		$(this).replaceWith("<a href=\""+href+"\"><em>"+title+"<\/em> "+txt+"<\/a>");
	});

	/*
	Next 2 add support for :focus to IE,
	and then go on to add .focus class to labels. Sweet.
	DID have to spell out the elements rather than write 'form *' for focus for Firefox/Win. Odd.
	*/
	$("form input, form select, form textarea").focus(function() {
		$(this).addClass("focus");
		var lid = $(this).attr("id");
		$("label[for="+lid+"]").addClass("focus");
	});

	$("form *").blur(function() {
		$(this).removeClass("focus");
		var lid = $(this).attr("id");
		$("label[for="+lid+"]").removeClass("focus");
	});

	// The main sexy menu styles
	$("#view-menu a").hover(
		function() {
			$("#view-menu a").removeClass("focus");
			$(this).addClass("focus");
			var rel = $(this).attr("rel");
			$("#central li").not("#"+rel).hide();
			$("#"+rel).show();
		},
		function() {
		}
	);
	
	// I think we've covered everything in googlefix.js
	// Thanks Jon Jensen! http://code.jenseng.com/google/
	// Last bit - binding to different thingy for Firefox - came from studying code @
	// http://www.west-wind.com/weblog/posts/478985.aspx
	// That's not the last bit.
	// Firefox is returning RGB values. Ugh. THANKS ALSO TO:
	// http://www.phpied.com/auto-filler-toolbars-and-the-colors-of-the-inputs/
	if ($.browser.mozilla) {
		var binder = 'DOMAttrModified';
		var googlefill = 'background-color: rgb(255, 255, 160);';
	} else {
		var binder = 'propertychange';
		var googlefill = 'BACKGROUND-COLOR: #ffffa0';
	}
	$("input, select").bind(binder,function(e) {
		if( $(this).attr('style') == googlefill ) {
			// testing $("#contact h1").text($(this).css('background-color')+$(this).attr("id") );
			$(this).addClass("autofill");
			if( $("#googleblurb").length == 0 ) {
				$("form").append("<div id=\"googleblurb\" class=\"autofill\">AutoFill highlighted fields with Google toolbar</div>");
			}
			return false;
		}
	});
});
