﻿/// <reference path="~/Scripts/ByteStorm/_BSC_Interface.js" />
(function()
{
	BSC.E = function()
	{
		var handlers = {};

		return {
			MapHrefs: function()
			{
				$("body a[rel='home']").map(function()
				{
					var h = this.href;
					//this.href="javascript:void(0);";
					this.rel = '';
					$(this).click(function()
					{
						GO((h).replace(/http:\/\/[^\/]+/i, ""));
						return false;
					});
				});
			},
			Bind: function(e, t, f, d)
			{
				/// <summary>Bind event to element</summary>
				/// <param name="e">Element to bind event to</param>
				/// <param name="t">Type of event, ie click</param>
				/// <param name="f">Function to bind</param>
				/// <param name="d">Data to parse to the event call</param>
				/// <return>Object</return>
				if (!d) d = null;
				return $(e).bind(t, d, f);
			},
			GetElement: function(e, parentTag, tag)
			{
				var el = BSC.E.GetTarget(e);
				while (el && el.nodeName.toLowerCase() !== parentTag)
				{
					if (el.nodeName.toLowerCase() === tag)
					{
						if (!el.id)
							el.id = BSC.U.NewGUID();
						return el;
						break;
					} else
					{
						el = el.parentNode;
					}
				}
				return { id: null };
			},
			GetTarget: function(e)
			{
				/// <summary>Get Element from which event has been trigged</summary>
				/// <param name="e">Event</param>
				/// <return>Element</return>
				return e.target;
			},
			Stop: function(e)
			{
				e.preventDefault(); e.stopPropagation();
			},
			SubscribeTypes: { Render: "render", Load: "load", Unload: "unload", Bind: "bind", Unbind: "unbind", Focus: "focus", Blur: "blur", Maximize: "maximize", Minimize: "minimize", Reload: "reload", Restore: "restore", TabsLoaded: "tabsloaded", DragStop: "stopdrag", StopResize: "stopresize", Bookmark: "bookmark", All: "all" },
			Subscribe: function(type, method, obj, scope)
			{
				if (!scope) scope = "__All__";
				if (!handlers[scope]) handlers[scope] = {};
				handlers[scope][type] = { o: obj, m: method };
			},
			Trigger: function(type, p, scope)
			{
				if (!scope) scope = "__All__";
				if (!handlers[scope] || !handlers[scope][type]) return false;
				if (!typeof (p) != "object") { var _p = []; _p.push(p); p = _p; }
				if (!p) p = [];

				var h = handlers[scope][type];
				if (h && h.m)
				{
					if (h.o)
						h.m.apply(h.o, p);
					else
						h.m.apply(null, p);

					return true;
				}
				return false;
			}
		};
	} ();
})();
// BSC.E.Trigger("BSC.UI.W.StopResize",p,"rating.main.main");
