var application = {};

$(document).ready(function() {
//	application.loadWidget("header.tmpl.htm", $("#HEADER")); //has to run via http:// (not file://) to work on chrome/safari due to ajax security
//	application.loadWidget("footer.tmpl.htm", $("#FOOTER"));

	ui.initialize();

	/*
	 * Highlight navigation links when hovered
	 */
	$("#NAVIGATION .LIST LI").each(function(index, elm) {
		if (!$(elm).parent().hasClass("MENU")) {
			$(elm).addClass("LI");
			$(elm).addClass("LINK");
		}
	});
	
	$("#HEADER A").attr("tabindex", "1");
	$("#HEADER .CAPTION_STORE_HOURS").attr("tabindex", "1");
	$("#HEADER INPUT").attr("tabindex", "1");
	$("#CONTENT INPUT").attr("tabindex", "2");
	$("#CONTENT .DROPDOWN").attr("tabindex", "2");
	$("#CONTENT A").attr("tabindex", "2");
	$("#CONTENT A").attr("tabindex", "2");
	$("#CONTENT AREA").attr("tabindex", "3");
	
	$("#NAVIGATION .LIST .LINK").bind("mousemove", function() {
		$(this).addClass("HOVER");
	});
	$("#NAVIGATION .LIST .LINK").bind("mouseout", function() {
		$(this).removeClass("HOVER");
	});
	$("#NAVIGATION .LIST A").bind("focus", function() {
		$(this).closest(".LINK").addClass("HOVER");
	});
	$("#NAVIGATION .LIST A").bind("blur", function() {
		$(this).closest(".LINK").removeClass("HOVER");
	});

	$("#NAVIGATION .LIST .LINK").each(function(index, elm) {
		if (index<=$("#NAVIGATION .LIST .LINK").length-2) {
			$("#NAVIGATION .LIST").append("<li class='LI BORDER BORDER_" + index + "'></li>");
			$(".BORDER_" + index).insertAfter(elm);
		}
	});

	$(".CAPTION.MENU_CAPTION").append("<img src='/img/arrow_down_circle_black.png' class='FLIPPABLE' align='absmiddle' hspace='4'/>");
});

application.loadWidget = function(url, parentDOM) {
	$.ajax({
		url: url
		, type: "GET"
		, data: ""
		, contentType: "application/json"
		, dataType: "html"
		, async: false
		, cache: false
		, success: function(data, textStatus, XMLHttpRequest) {
			if (typeof parentDOM=='string') {
				$(parentDOM).append(data);
			} else {
				parentDOM.append(data);
			}
		}
		, error: application.loadWidgetFail
	});
};

