/// <reference path="jQuery/jquery-1.4.3.min.js" />
/*
_gSite.js:		Global site script.

Created by:		Kyle Underwood of Stoltenberg Consulting.
Created on:		11/13/2010.
Created to:		Run scripts for the entire site (globally).
*/

/*
var oShowSite;

$(document).ready(function () {


$("#divDelayNavigation").hide();
oShowSite = setTimeout("ShowSiteDelay()", 3000);

});

function ShowSiteDelay() {
$("#divDelayNavigation").fadeIn("fast");

clearTimeout(oShowSite);
oShowSite = "";
}
*/

// BeginOAWidget_Instance_2142022: #dialog

function CalcMenuCenter() {
	//alert("divMenuTop: " + $("#divMenuTop").width() + ", MenuBar1: " + $("#MenuBar1").width());
	var calcIt = parseInt($("#divMenuTop").width()) - parseInt($("#MenuBar1").width());
	$("#MenuBar1").css("margin", "0px");
	$("#MenuBar1").css("margin-left", parseInt(calcIt / 2 - 1) + "px");
}

//$("#MenuBar1").hide();

$(document).ready(function () {

	// Fix the menu padding when zoom is used in the browser...

	//alert("divMenuTop: " + $("#divMenuTop").width() + ", MenuBar1: " + $("#MenuBar1").width());

	if ($(".ie6").length != 0) IE6Fix();
	if ($(".ie7").length != 0) IE7Fix();

	CalcMenuCenter();

	$(window).resize(function () {
		CalcMenuCenter();
	});

	$("#divMenuTop").resize(function () {
		CalcMenuCenter();
	});

	$("#MenuBar1").resize(function () {
		CalcMenuCenter();
	});

	$("#divMassageTherapy").css("top", "137px");

	var userRoles = "";
	try { if ($("#ctl00_roleValues").length) userRoles = $("#ctl00_roleValues").attr("value").split(","); } catch (err) { }
	try { if ($("#roleValues").length) userRoles = $("#roleValues").attr("value").split(","); } catch (err) { }

	/*
	$("#divPageBranding p").css("border-top", "5px solid #fff");
	$("#MenuBar1").css("background-color", "#003f77");
	$("#MenuBar1 ul").css("background-color", "#003f77");
	$("#MenuBar1 ul").css("border-color", "#003f77");

	try {
	$("#divPageBranding h4").corner("top, 10px");
	$("#divPageBranding p").corner("bottom, 20px");
	$("#MenuBar1 li").corner("bottom, 15px");
	$("#MenuBar1 ul li").corner("bottom, 15px");
	}
	catch (ex) { }
	*/

	$("#MenuBar1").show();

	try {
		$("#divPageBranding").css("background-color", "#fff");
		if ($(".ie6").length == 0 && $(".ie7").length == 0) {
			$("#divPageBranding h4").corner("top, 15px");
			$("#divPageBranding p").corner("bottom, 20px");
			//$("#divPageBranding a").width("200" + "px");
		}
	}
	catch (ex) { }

	//alert("userRoles: " + userRoles);

	// ***************************************************************************
	// Check for ROLES attributes ...
	try {
		$('body').find('*[roles]').each(function (index) {
			var attrRoles = $(this).attr("roles").split(",");
			var removeObj = true;

			removeObj = true;
			for (var r1 = 0; r1 < attrRoles.length; r1++) {
				for (var r2 = 0; r2 < userRoles.length; r2++) {
					if (trim(attrRoles[r1]).toLowerCase() == trim(userRoles[r2]).toLowerCase()) removeObj = false;
				}
			}
			if (removeObj) $(this).empty().remove(); // .empty() runs faster, .remove() deletes the object from the DOM.
			else $(this).removeClass("displayNone");
		});
	}
	catch (err) { }
	// ***************************************************************************
	// Check for ROLE attributes ...
	try {
		$('body').find('*[role]').each(function (index) {
			var attrRoles = $(this).attr("role").split(",");
			var removeObj = true;

			removeObj = true;
			for (var r1 = 0; r1 < attrRoles.length; r1++) {
				for (var r2 = 0; r2 < userRoles.length; r2++) {
					if (trim(attrRoles[r1]).toLowerCase() == trim(userRoles[r2]).toLowerCase()) removeObj = false;
				}
			}
			if (removeObj) $(this).empty().remove(); // .empty() runs faster, .remove() deletes the object from the DOM.
			else $(this).removeClass("displayNone");
		});
	}
	catch (err) { }
	// ***************************************************************************

	//alert("divAdministration HTML: " + $("#divAdministration").html());

	userRoles = null;

	try {
		$("#dialog").bind('dialogclose', function (event) {
			$("#divMenuTop").show();
			//$("body").css("overflow", "auto");
			return false;
		});
	}
	catch (err) { }

	try {
		$("#dialog").dialog({
			autoOpen: false,
			modal: true,
			draggable: false,
			resizable: false,
			buttons: {
				"Register": function () {
					$(this).dialog("close");
					$("#divMenuTop").show();
					//$("body").css("overflow", "auto");
					window.location = baseUrl + "register.aspx";
					return false;
				},
				Cancel: function () {
					$(this).dialog("close");
					return false;
				}
			}
		});
	}
	catch (err) { }

	try {
		$("#linkWhyRegister").click(function () {
			//$("body").css("overflow", "hidden");
			$("#dialog").dialog("open");
			$("#divMenuTop").hide();
			return false;
		});
	}
	catch (err) { }
});

// EndOAWidget_Instance_2142022

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function trim(s) {
	return rtrim(ltrim(s));
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function ltrim(s) {
	var l = 0;
	while (l < s.length && s[l] == ' ')
	{ l++; }
	return s.substring(l, s.length);
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function rtrim(s) {
	var r = s.length - 1;
	while (r > 0 && s[r] == ' ')
	{ r -= 1; }
	return s.substring(0, r + 1);
}

function IE6Fix() {
	try { $("#linkCssSpryMenuBar").attr("href", "/SpryAssets/SpryMenuBarHorizontalOldIE.css"); } catch (err) { }
	try { $("#linkCssSprySubMenuBar").attr("href", "/SpryAssets/SpryMenuBarHorizontalOldIE.css"); } catch (err) { }

	$("#MenuBar1").css("white-space", "nowrap");
	$("#MenuBar1").css("margin-left", "0px");
	$("#MenuBar1 a").css("color", "#ffffff");
	$("#tableContent").css("top", "-2px");
	$("#tdRightColumn a").css("text-decoration", "underline");
	$("#divPageBranding").css("top", "8px");
	$("#divPageBranding").css("left", "-5px");
	$("#divPageBranding p").css("margin-bottom", "20px");
	$("#bodySub #tableContent").css("top", "16px");
	$("#bodySub #divPageBranding").css("top", "10px");
	$("#bodySub #divPageBranding").css("left", "2px");
	$("#MenuBar1 a").mouseover(function () {
		$(this).css("color", "#006");
	});
	$("#MenuBar1 a").mouseout(function () {
		$(this).css("color", "#fff");
	});
	$("#divPageBranding a").mouseover(function () {
		$(this).css("background-color", "#fff");
	});
	$("#divPageBranding h4 a").mouseout(function () {
		$(this).css("background-color", "");
	});
	$("#divPageBranding p a").mouseout(function () {
		$(this).css("background-color", "");
	});
	$(".imgPageBottom").css("width", "690px");
	$(".imgPageBottom").css("float", "right");
	$(".imgPageTop").css("width", "690px");
	$(".imgPageTop").css("float", "left");
}

function IE7Fix() {
	$("#MenuBar1").css("white-space", "nowrap");
	$("#MenuBar1 ul li a").css("width", "170px");
	$("#tableContent").css("top", "0px");
	$("#tdRightColumn a").css("text-decoration", "underline");
	$("#divPageBranding").css("top", "8px");
	$("#divPageBranding").css("left", "-5px");
	$("#divPageBranding p").css("margin-bottom", "20px");
	$("#bodySub #tableContent").css("top", "18px");
	$("#bodySub #divPageBranding").css("top", "10px");
	$("#bodySub #divPageBranding").css("left", "2px");
	$("#divPageBranding a").mouseover(function () {
		$(this).css("background-color", "#fff");
	});
	$("#divPageBranding h4 a").mouseout(function () {
		$(this).css("background-color", "");
	});
	$("#divPageBranding p a").mouseout(function () {
		$(this).css("background-color", "");
	});
	$(".imgPageBottom").css("width", "690px");
	$(".imgPageBottom").css("float", "right");
	$(".imgPageTop").css("width", "690px");
	$(".imgPageTop").css("float", "left");
}

