﻿

(function()
{
	jQuery(function()
	{
		if($.boxModel==false)
		{
			$(".Page-ContentArea").each(function()
			{
				// reduce the inner width of children of content area divs by the horizontal padding
				var nHPad = parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"));
				var oChildren = $(this).children();
				$(oChildren).each(function()
				{
					var nInnerWidth = $(this).innerWidth();
					if(nInnerWidth < nHPad) { return; }
					$(this).css({width: ($(this).innerWidth()-nHPad)});
				});
			});
			$(".Page-FormSection").each(function()
			{	// reduce the width of each form section by it's own padding
				var nHPad = parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"));
				$(this).css({width: ($(this).innerWidth()-nHPad)});
			});
		}
	});	
	
	var _AttachQuickMenu = function()
	{
		var oTopBar = $("#Page-TopBar .Center");
		if($(oTopBar).html()==null)
		{
			oTopBar = $("#Page-DlgTopBar .Center");
			if($(oTopBar).html() == null) return;
		}
		
		$(oTopBar).css({
			backgroundImage: "url(/NmConsole/Mobile/_Nm/_Page/images/QmLaunchButton.png)",
			backgroundRepeat: "no-repeat",
			backgroundPosition: "top center",
			cursor: "default"
			});
		
		
		// testing
		$.ajaxSetup({error:function(oXMLHttpRequest)
		{
			$(".Page").html(oXMLHttpRequest.responseText);
			//alert(oXMLHttpRequest.responseText);
		}});
		
		
		$(oTopBar).click(function()
		{
			if($("#AjxQuickMenu").html()==null)
			{
				$.get("/NmConsole/Mobile/AjxQuickMenu.asp", function(oData)
				{
					$(".Page").append("<div id=\"AjxQuickMenu\" style=\"display:none;\">"+oData+"</div>");
					$("#AjxQuickMenu").css({
						background: "#000000",
						position: "absolute",
						top: "0px",
						width: parseInt($(".Page").innerWidth()),
						height: Math.max(parseInt($("body").innerHeight()), parseInt($(".Page").innerHeight()))			
						});
					$("#oButtonQmCancel").removeAttr("onclick");
					$("#oButtonQmCancel").click(function(){$("#AjxQuickMenu").slideToggle();});
					$("#oButtonQmHome").removeAttr("onclick");
					$("#oButtonQmHome").click(function(){document.location = "/NmConsole/Mobile/";});		
					$("#oButtonQmDevices").removeAttr("onclick");
					$("#oButtonQmDevices").click(function(){document.location = "/NmConsole/Mobile/Device/DeviceList/DeviceList.asp";});		
					$("#oButtonQmReports").removeAttr("onclick");
					$("#oButtonQmReports").click(function(){document.location = "/NmConsole/Mobile/Reports/Reports.asp";});		
					$("#oButtonQmLogOut").removeAttr("onclick");
					$("#oButtonQmLogOut").click(function(){document.location = "/NmConsole/Mobile/?__EVENTTARGET=oButtonLogOut&__EVENTTYPE=Form.ButtonClicked";});
					$("#AjxQuickMenu").slideToggle();			
				});
			}
			else
			{
				$("#AjxQuickMenu").slideToggle();
			}
		});
			
		/*
		$("#oButtonQmFavorites").css({color:"white", cursor:"default"});

		$("#oButtonQmFavorites").click(function()
		{
			if()
			{
				_bAjaxCalled = true;				
				$.get("/NmConsole/Mobile/Favorites/AjxFavorites.asp", function(oData)
				{
					$("#oButtonQmFavorites").append("<div id=\"AjxFavorites\" style=\"display:none;\">"+oData+"</div>");
					$("#AjxFavorites").slideToggle();			
				});
			}
			$("#AjxFavorites").slideToggle();
		});
		*/
	}		
})();
