﻿$(document).ready(RegisterClintSideScripts);

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
	if (args.get_error() == undefined)
	{
		RegisterClintSideScripts();
	}
}
function RegisterClintSideScripts()
{
	$(document).ready(function()
	{

		$(".toolbarButton").bind("mouseover",
			function(e)
			{

				var id = $(this).attr("id");
				var toolbarButtonSpan = $("#" + id + "_span");

				if (toolbarButtonSpan.size() == 0)
				{
					toolbarButtonSpan = document.createElement("span");
					toolbarButtonSpan.id = id + "_span";
					$(document.body).append(toolbarButtonSpan);
					var toolbarButtonSpan = $("#" + id + "_span");
					var image = $(this).find("img");
					var spanHtml = String.format("<img src='{0}' align='absmiddle'><span>{1}</span>", image.attr("src"), $(this).attr("title"));
					toolbarButtonSpan.html(spanHtml);
					$(this).attr("title", "")
					toolbarButtonSpan.addClass("toolbarButtonSpan");
				}
				else
				{
					var img = $("img", toolbarButtonSpan);
					if (img != null && img.length == 1)
					{
						var image = $(this).find("img");
						if (image.attr("src") != img.attr("src"))
						{
							var txt = $(this).attr("title") == "" ? $(img).next().text() : $(this).attr("title");
							var spanHtml = String.format("<img src='{0}' align='absmiddle'><span>{1}</span>", image.attr("src"), txt);
							toolbarButtonSpan.html(spanHtml);
							$(this).attr("title", "")
						}
					}
				}

				toolbarButtonSpan.css("left", $(this).position().left);
				toolbarButtonSpan.css("top", $(this).position().top + $(this).height() + 6);
				toolbarButtonSpan.attr("show", "1");
				setTimeout(function() { if (toolbarButtonSpan.attr("show") == "1") { toolbarButtonSpan.show(); } }, 200);
			}
		);

		$(".toolbarButton").bind("mouseout",
			function(e)
			{
				var id = $(this).attr("id");
				var toolbarButtonSpan = $("#" + id + "_span");
				toolbarButtonSpan.attr("show", "0");
				toolbarButtonSpan.hide();

			}
		);
		$(".toolbarButton").bind("click",
			function(e)
			{
				var id = $(this).attr("id");
				var toolbarButtonSpan = $("#" + id + "_span");
				toolbarButtonSpan.attr("show", "0");
				toolbarButtonSpan.hide();

			}
		);
		$(".toolbarMenuButton").bind("mouseover",
			function(e)
			{
				var menu = this;
				var id = $(this).attr("id");
				var submenu = document.getElementById(id + "_submenu");
				submenu.style.left = $(menu).position().left + "px";
				submenu.style.top = $(menu).position().top + $(menu).height() + 5 + "px";
				submenu.style.display = 'block';
			}
		);
		$(".toolbarMenuButton").bind("mouseout",
			function(e)
			{
				var id = $(this).attr("id");
				var submenu = document.getElementById(id + "_submenu");
				submenu.style.display = 'none';

			}
		);
		$(".toolbarSubMenu").bind("mouseover",
			function(e)
			{

				var submenu = this;
				var id = $(this).attr("id");
				var menuId = id.substr(0, id.lastIndexOf("_submenu", id.length - 1));
				var menu = document.getElementById(menuId);
				submenu.style.left = $(menu).position().left + "px";
				submenu.style.top = $(menu).position().top + $(menu).height() + 5 + "px";
				submenu.style.display = 'block';
			}
		);
		$(".toolbarSubMenu").bind("mouseout",
			function(e)
			{
				var submenu = this;
				var id = $(this).attr("id");
				var menuId = id.substr(0, id.lastIndexOf("_submenu", id.length - 1));
				var menu = document.getElementById(menuId);
				submenu.style.display = 'none';

			}
		);


	}
);
}

