﻿/// <reference path="~/Scripts/ByteStorm/_BSC_Interface.js" />
function callback22(hash)
{
	//GO(hash);
	alert(hash);
	// do stuff that loads page content based on hash variable
}
(function() {
    BSC.P = function() {
        var currentWindow = null;
        var maxTop = 42;
        var maxBottom = 83;
        var isFirstLoad = true;
        var mainMenuClick = false;


        var getSilverlightVersion = function() {
            var SLVersion = 0;
            //            try
            //            {
            //                try
            //                {
            //                    var control = new ActiveXObject('AgControl.AgControl');
            //                    if (control.IsVersionSupported("3.0"))
            //                        SLVersion = 3;
            //                    else
            //                        if (control.IsVersionSupported("2.0"))
            //                        SLVersion = 2;
            //                    else
            //                        SLVersion = 1;
            //                    control = null;
            //                }
            //                catch (e)
            //                {
            //                    var plugin = navigator.plugins["Silverlight Plug-In"];
            //                    if (plugin)
            //                    {
            //                        if (plugin.description === "1.0.30226.2")
            //                            SLVersion = 2;
            //                        else
            //                            SLVersion = parseInt(plugin.description[0]);
            //                    }
            //                    else
            //                        SLVersion = 0;
            //                }
            //            }
            //            catch (e)
            //            {
            //                SLVersion = 0;
            //            }
            return SLVersion;
        };

        //var history = window.dhtmlHistory;
        //history.create({toJSON:BSC.D.JSON.ToString,fromJSON:BSC.D.JSON.Parse});
        return {
            MaxTop: maxTop,
            MaxBottom: maxBottom,
            OnDocumentClick: function(e) {

                $(".CloseDocClick").hide();
                // Reset Taskbar menu
                $("#TaskbarContextMenu").hide().unbind("click", BSC.P.OnTaskbarMenuClick);
                if (BSC.M.GetActiveId())
                    BSC.M.HideActiveSubmenu();
            },
            OnSelectorClick: function(e) {
                e.preventDefault(); e.stopPropagation();
                if (this.id == "sound") return;
                $("#" + this.id + "Selector").toggle();
                return;
            },
            BeforeUnload: function() {
            },
            Unload: function() {
                BSC.D.UnsubscribeChannels();
            },
            Load: function() {

                //				var html = "<div id='div1'>div1</div><div id='div2'>div2</div><div id='div3'>div3</div>";
                //				var j = $(html);
                //				var d = $(j).find("div#id");
                //				alert(j.html() + "\n\n" + html);

                //				return false;

                // SocialStream
                BSC.UI.SocialStream.Init();

                pageTracker._setVar('SLVersion ' + getSilverlightVersion());


                BSC.E.Bind("#WallpaperList", "click", function(e) {
                    var el = BSC.E.GetElement(e, "ul", "li");
                    if (!el.id) return;
                    var id = ((el.id).split("_"))[1];
                    BSC.D.Wp.Set(id);
                });

                BSC.E.Bind("#LanguageSelectorList", "click", function(e) {
                    var el = BSC.E.GetElement(e, "ul", "li");
                    var id = ((el.id).split("_"))[1];
                    BSC.D.P.SetLanguage(id);
                });

                // Wallpaper
                BSC.D.Wp.Set(BSC.C.Get("wallpaper"));
                // Flash upload
                //BSC.F.SetFlash(new SWFUpload(BSC.F.Settings));

                // Map Menu Href's

                $("#menu a").map(function() {
                    this.rel = '';
                    $(this).click(function() {
                        this.rel = '';
                        BSC.M.HideActiveSubmenu();
                        BSC.P.MainMenuGo((this.href).replace(/http:\/\/[^\/]+/i, ""));
                        return false;
                    });
                });

                // Menu drag binding
                $('#menu').jqDrag("#menuhandler").mouseover(BSC.M.OnMouseover).mouseout(BSC.M.OnMouseout);
                $('#broadcast').jqDrag("#broadcasthandler");


                // Disable selection on Menus
                BSC.UI.DisableSelection($("#broadcasthandler"));
                BSC.UI.DisableSelection($("#menu"));
                BSC.UI.DisableSelection($("#TaskbarList"));



                // Map Href's
                BSC.E.MapHrefs();

                // Bind Clicks
                $(document).click(BSC.P.OnDocumentClick);
                $("#TaskbarList").click(BSC.P.OnTaskbarClick);
                $("#CloseLink").click(BSC.P.OnSignout);
                $("#TopSelectors .clickable").click(BSC.P.OnSelectorClick);
                $("#TaskbarList").bind("contextmenu", BSC.P.OnTaskbarContextClick);


                $("ul.star-rating a").mouseover(function() 
                { 
                    
                })


                // Keyboard binding
                $(document).bind('keypress', { combi: 'esc', disableInInput: true }, BSC.UI.W.CloseActive).bind('keypress', { combi: 'Alt+w', disableInInput: true }, BSC.UI.W.CloseActive);

                //				$(document).bind('keypress', { combi: 'a', disableInInput: true }, fn);
                //				$.hotkeys.add('esc', { propagate: true }, BSC.UI.W.CloseActive);
                BSC.D.P.Init(BSC.P.InitCB);
            },
            InitCB: function() {
                // Remove blur
                $("#bluroverlay").addClass("none");

                BSC.D.Init();

                // Page Sound
                if (BSC.D.P.IsMute()) {
                    $("#page_speaker").addClass("mute");
                }
                $("#page_speaker").click(function(e) {
                    if (BSC.D.P.IsMute()) {
                        BSC.D.P.Setting("sound_mute", "false");
                        $("#page_speaker").removeClass("mute");
                    }
                    else {
                        BSC.D.P.Setting("sound_mute", "true");
                        $("#page_speaker").addClass("mute");
                    }
                });


                var r = window.location.href;
                var i = r.indexOf("#");
                var hash = (i >= 0) ? r.substr(i + 1) : "";
                if (!hash || hash.length == 0 || hash == "/")
                    GO("/home");
                else
                    GO(hash);


                //$.historyInit(callback22);
                //			    history.initialize();
                //		        history.addListener(BSC.P.GoBack);
                //			    if(history.isSafari || history.isIE)
                //			    {
                //			        //$(body).css("height","90%");
                //			        GO(history.getCurrentHash());
                //			    }
            },
            ParsePath: function(p) {
                // Has Access to menu
                if (p === "/") p = "";
                if (p.indexOf("/") != 0) p = "/" + p;
                if (!p || (p && p == "/") || (p && p.length == 0)) return 400;
                var access = BSC.D.P.GetAccess(p);


                // Not logged in, and no access
                if (!access && !BSC.D.P.IsLoggedIn()) {
                    BSC.UI.AlertLogin(p);
                    return 400;
                }
                // Logged in, and no access
                if (access && BSC.D.P.IsLoggedIn() && access.ofm && !BSC.D.P.IsFullMember()) {
                    BSC.UI.AlertOnlyFullMembers();
                    return 400;
                }
                // Logged in, and no access
                if (!access && BSC.D.P.IsLoggedIn())
                {
                    if (BSC.D.P.IsApplicant())
                        BSC.UI.Alert("OK", null, "Access denied for applicants", "As an applicant, you don't have access to this feauture!", null, null, "info");
                    else
                        BSC.UI.Alert("OK", null, "Page not found", "The page you are looking for does not exist.", null, null, "info");
                    
                    return 400;
                }
                // Logged in, and no access
                if (access.opp && !BSC.D.P.IsPaying()) {
                    BSC.UI.Alert("Renew subscription", "Cancel", "Only paying members!", "You at valid subscription to view this page.", function() { GO('/home'); }, null, "info");
                    return 400;
                }

                if (BSC.D.P.IsFullMember() && !BSC.D.P.IsPaying() && (access.identifier == "broadcast.create")) {
                        BSC.UI.AlertCurrentlyFREE();
                    return 400;
                }

                p = access.p;
                return access;
            },
            GoBack: function(p) {
                GO(p);
            },
            ChangeURI: function(p) {
                BSC.UI.Banner.Rotate(p);

                pageTracker._trackPageview(p);
                window.location.hash = p;

                gemius_obj_bscset();

                if (BSC.UI.Ws.GetActiveId())
                    BSC.UI.Ws.Get(BSC.UI.Ws.GetActiveId()).uri = p;


                // $.historyLoadNoCallback(p);

                return false;
            },
            LoadHtml: function(guid) {
                var w = BSC.UI.Ws.Get(guid);
                if (!w) return;

                var key = w.tabgroup;
                var isset = ($("#" + guid + "_tabs_content_ul").attr("bsctab") == key);

                // Load tabs
                if (key && !BSC.D.C.HasKey(key) && w.showtabs) {
                    // load tabs
                    $.get("/website/tabs/" + key, { __guid: guid }, function(res)
                    //BSC.D.Send({ key: key }, "Site", "Loadtabs", function(res)
                    {
                        var tabs = res;
                        if (tabs) {
                            BSC.D.C.Put(key, tabs);
                            var ul = $("#" + guid + "_tabs_content_ul");
                            $("#" + guid + "_tabs_content_ul li").remove();

                            BSC.UI.Ws.Get(guid).showtabs = (key != null && tabs != null);
                            // Set Height - tabs
                            BSC.UI.W.SetTabs(guid);

                            for (id in tabs) {
                                var tab = tabs[id];

                                var color = (tab.Color) ? tab.Color + " " + tab.ID : " blue " + id;
                                var c = (w.tabshow === id && tab.Color) ? " class=\"" + id + " selected " + color + "\"" : (w.tabshow === id && !tab.Color) ? " class=\"" + id + " first\"" : (tab.Color) ? " class=\"" + id + " " + tab.Color + "\"" : "";
                                var lc = id; //(i == 0) ? " class=\"first\"" : "";
                                var t = BSC.D.Ts.Get("TabItem");
                                t = t.replace(/\{link\}/g, tab.Link);
                                t = t.replace(/\{title\}/g, tab.Title);
                                t = t.replace(/\{listclass\}/g, c);
                                //t = t.replace(/\{linkclass\}/g, "");
                                ul.append(t);
                            }
                            $("#" + guid + "_tabs_content_ul").attr("bsctab", key);
                            BSC.E.Trigger(BSC.E.SubscribeTypes.TabsLoaded, [guid], w.Key());
                        }
                    }, "json");
                }
                else if (BSC.D.C.HasKey(key) && isset && w.showtabs) {
                    // Select tab
                    $("#" + BSC.UI.Ws.GetActiveId() + "_tabs_content_ul li.selected").removeClass("selected");
                    $("#" + BSC.UI.Ws.GetActiveId() + "_tabs_content_ul li." + w.tabshow).addClass("selected");
                    //BSC.E.Trigger(BSC.E.SubscribeTypes.TabsLoaded, [guid], w.Key());
                }
                else if (w.showtabs) {
                    // Render cached tabs
                    if (key) {
                        var tabs = BSC.D.C.Get(key);

                        BSC.UI.Ws.Get(guid).showtabs = (key != null && tabs != null);
                        // Set Height - tabs
                        BSC.UI.W.SetTabs(guid);

                        var ul = $("#" + guid + "_tabs_content_ul");
                        $("#" + guid + "_tabs_content_ul li").remove();
                        for (id in tabs) {
                            var tab = tabs[id];

                            var color = (tab.Color) ? tab.Color + " " + tab.ID : " blue " + id;
                            var c = (w.tabshow === id && tab.Color) ? " class=\"" + id + " selected " + color + "\"" : (w.tabshow === id && !tab.Color) ? " class=\"" + id + " first\"" : (tab.Color) ? " class=\"" + id + " " + tab.Color + "\"" : "";
                            var lc = ""; //(i == 0) ? " class=\"first\"" : "";
                            var t = BSC.D.Ts.Get("TabItem");
                            t = t.replace(/\{link\}/g, tab.Link);
                            t = t.replace(/\{title\}/g, tab.Title);
                            t = t.replace(/\{listclass\}/g, c);
                            t = t.replace(/\{linkclass\}/g, lc);
                            ul.append(t);
                        }
                        $("#" + guid + "_tabs_content_ul").attr("bsctab", key);
                        BSC.E.Trigger(BSC.E.SubscribeTypes.TabsLoaded, [guid], w.scriptkey);
                    }
                }



                // Load topmenu
                if (!BSC.D.C.HasKey(w.wguid)) {

                }
                // Render Topmenu

                var q = (w.query) ? w.query : {};
                q["__guid"] = guid;

                /// TODO: Log this error, and show doas not exists alertt
                //                $("#" + guid + "_content").ajaxError(function(event, request, settings)
                //                {
                //                    $(this).html("<h4 style>" + settings.url + "</h4>" + request.responseText);
                //                });
                if (w.cachehtml && BSC.D.C.HasKey(w.id + "_content")) {
                    // Render Html
                    var topmenu = ("" + BSC.D.C.Get(w.id + "_topmenu")).replace(/\{id\}/g, guid);
                    var left = ("" + BSC.D.C.Get(w.id + "_left")).replace(/\{id\}/g, guid);
                    var content = ("" + BSC.D.C.Get(w.id + "_content")).replace(/\{id\}/g, guid);
                    var right = ("" + BSC.D.C.Get(w.id + "_right")).replace(/\{id\}/g, guid);

                    if (topmenu && topmenu != "null" && topmenu.length > 0) {
                        $("#" + guid + "_topmenu div").remove();
                        $("#" + guid + "_topmenu ul.topmenu").remove();
                        $("#" + guid + "_topmenu").append(topmenu);
                    }
                    if (left && left.length > 0)
                        $("#" + guid + "_left").html(left);
                    if (content && content.length > 0)
                        $("#" + guid + "_content").html(content);
                    if (right && right.length > 0)
                        $("#" + guid + "_right").html(right);
                    w.Init();
                    BSC.UI.W.EventBind(guid);
                }
                else {

                    BSC.UI.ShowStatus(guid, "Loading...");

                    var query = BSC.U.ParseQuery(w.query);
                    if (w.cachehtml) query.__cache = true;


                    BSC.D.AjaxAbort(guid);
                    var d1 = new Date();
                    BSC.D.AjaxGet(w.cleanpath, query, function(res, text) {
                        var d2 = new Date();

                        var dd = (d2 - d1);

                        var topmenu = "";
                        var left = "";
                        var content = "";
                        var right = "";

                        //						var html = $(res);
                        //						var l = html.length;
                        //						for (i = 0; i < l; i++)
                        //						{
                        //							if (html[i].id == "BSCContent") content = $(html[i]).html();
                        //							else if (html[i].id == "BSCTopMenu") topmenu = $(html[i]).html();
                        //							else if (html[i].id == "BSCLeft") left = $(html[i]).html();
                        //							else if (html[i].id == "BSCRight") right = $(html[i]).html();
                        //						}
                        var tID = BSC.U.NewGUID();
                        $("#HtmlHelper").after("<div id=\"" + tID + "\" style=\"display:none;\">" + res + "</div>");
                        var topmenu = $("#" + tID + " div.BSCTopMenu").html();
                        var left = $("#" + tID + " div.BSCLeft").html();
                        var content = $("#" + tID + " div.BSCContent").html();
                        var right = $("#" + tID + " div.BSCRight").html();
                        $("#" + tID).remove();

                        // Cache Html if set
                        if (w.cachehtml) {
                            BSC.D.C.Put(w.id + "_topmenu", topmenu);
                            BSC.D.C.Put(w.id + "_left", left);
                            BSC.D.C.Put(w.id + "_content", content);
                            BSC.D.C.Put(w.id + "_right", right);
                        }
                        // Render Html
                        if (topmenu && topmenu != "null" && topmenu.length > 0) {
                            topmenu = topmenu.replace(/\{id\}/g, guid);
                            $("#" + guid + "_topmenu div").remove();
                            $("#" + guid + "_topmenu ul.topmenu").remove();
                            $("#" + guid + "_topmenu").append(topmenu);
                        }
                        if (left && left.length > 0) {
                            left = left.replace(/\{id\}/g, guid);
                            $("#" + guid + "_left").html(left);
                        }
                        if (content && content.length > 0) {
                            content = content.replace(/\{id\}/g, guid);
                            $("#" + guid + "_content").html(content);
                        }
                        if (right && right.length > 0) {
                            right = right.replace(/\{id\}/g, guid);
                            $("#" + guid + "_right").html(right);
                        }
                        w.Init();
                        BSC.UI.W.EventBind(guid);
                        BSC.UI.HideStatus(guid, 200);
                    }, "html", guid);
                }
            },

            MainMenuGo: function(p) {
                mainMenuClick = true;
                var cw = BSC.P.ParsePath(p);
                if (cw === 400)
                    return
                else if (!cw) {
                    BSC.UI.Alert("OK", null, "Page not found", "The page you are looking for does not exist.");
                    //alert("Invalid Url");
                    return false;
                }
                BSC.P.GoD(cw, p);
            },
            SetTitle: function(p1, p2) {
                var guid = p1;
                var title = p2;

                // Change Title
                document.title = "BeautifulPeople - " + title;
                $("#" + guid + "_title").html(title);

                BSC.UI.Ws.Get(guid).title = title;
            },
            Go: function(p) {
                //SWFAddress.setValue(p);
                var cw = BSC.P.ParsePath(p);
                if (cw === 400)
                    return
                else if (!cw) {
                    BSC.UI.Alert("OK", null, "Page not found", "The page you are looking for does not exist.");
                    //alert("Invalid Url");
                    return false;
                }
                BSC.P.GoD(cw, p);
            },
            GoD: function(cw, p) {
                var forceNewWindow = false;
                var animateFocus = false;
                var reset = mainMenuClick;
                mainMenuClick = false;

                // Is new window
                var newWindow = (forceNewWindow || !BSC.UI.Ws.GetWIDGuid(cw.WindowID));
                var w = (newWindow) ? new BSC.UI.W(cw, p) : BSC.UI.Ws.GetByWGUID(cw.WindowID);

                // If not active window, reset active window
                if (BSC.UI.Ws.GetActiveId() !== w.guid) {
                    if (BSC.UI.Ws.GetActiveId())
                        BSC.UI.W.Blur(BSC.UI.Ws.GetActiveId());
                }

                if (newWindow) {
                    // Load Window Frame
                    var wi = parseInt($("#TaskbarList").css("width"));
                    var newW = wi + 125;
                    $("#TaskbarList").css("width", newW);
                    var taskitem = "<div id=\"Taskbar_" + w.guid + "\"><a href=\"javascript:void(0)\"><span>" + w.title + "</span></a></div>";
                    $("#TaskbarList").append(taskitem);
                    $('#Taskbar_' + w.guid).addClass("active");
                    var html = BSC.D.Ts.Get("Window"); html = html.replace(/\$ID\$/gi, w.guid); html = html.replace(/\$TITLE\$/gi, w.title);

                    $("#Windows").append(html);
                    w.Init();
                    //BSC.UI.W.Focus(w.guid, false);
                    //animateFocus = false;

                    if (!BSC.UI.Ws[w.script]) {
                        $.getScript(BSC.BASE_STATIC_PATH + "Scripts/Content/BSC.UI.Ws." + w.script + ".js", function() {
                            // Change Title
                            BSC.P.SetTitle(w.guid, cw.Title);

                            //BSC.P.ChangeURI(cw.p);
                            BSC.UI.W.Focus(w.guid, animateFocus);
                            // Load Content
                            BSC.P.LoadHtml(w.guid);
                        });
                        return;
                    }
                }
                else {
                    if (BSC.UI.Ws.Get(w.guid).cleanpath != cw.cp) {
                        BSC.E.Trigger(BSC.E.SubscribeTypes.Unload, [w.guid], w.scriptkey);
                        //BSC.E.Trigger(BSC.E.SubscribeTypes.Unbind, [w.guid], w.scriptkey);
                    }

                    if (reset) BSC.UI.W.SetDefaultSizePosition(w.guid, w.wguid);
                    $("#Tab_" + w.guid + "_" + w.tabshow).addClass("selected");
                    $("#" + w.guid + "_Template").removeClass();
                    $("#" + w.guid + "_Template").addClass(cw.Template);
                    BSC.UI.Ws.Get(w.guid).page = cw.PageKey;
                    BSC.UI.Ws.Get(w.guid).tab = cw.TabKey;
                    BSC.UI.Ws.Get(w.guid).tabshow = cw.TabKeyToShow;
                    BSC.UI.Ws.Get(w.guid).showtabs = cw.ShowTabs;
                    BSC.UI.Ws.Get(w.guid).tabgroup = cw.TabGroupID;
                    BSC.UI.Ws.Get(w.guid).title = cw.Title;
                    BSC.UI.Ws.Get(w.guid).query = cw.Query;
                    BSC.UI.Ws.Get(w.guid).uri = p;
                    BSC.UI.Ws.Get(w.guid).id = cw.ID;
                    BSC.UI.Ws.Get(w.guid).path = cw.p;
                    BSC.UI.Ws.Get(w.guid).key = cw.Key;
                    BSC.UI.Ws.Get(w.guid).data = cw.Data;
                    BSC.UI.Ws.Get(w.guid).accessid = cw.AccessID;
                    BSC.UI.Ws.Get(w.guid).cleanpath = cw.cp;
                    BSC.UI.Ws.Get(w.guid).template = cw.Template;
                    BSC.UI.Ws.Get(w.guid).cachehtml = cw.CacheHtmlLocal;
                    BSC.UI.Ws.Get(w.guid).scriptkey = cw.ScriptID;
                    BSC.UI.Ws.SetActiveId(w.guid);
                }
                BSC.UI.W.Focus(w.guid, animateFocus);

                BSC.P.SetTitle(w.guid, cw.Title);

                //BSC.P.ChangeURI(p);
                // Load Content
                BSC.P.LoadHtml(w.guid);
            },
            OnSignout: function() {
                top.location = "/Signout"; return;
                //BSC.D.Send(null,"Public","Signout",function(){top.location="/";return;});
            },
            OnResize: function() {
                /// <summary>Javascript data cache 4</summary>
                /// <param name="name">Person's name</param>
                /// <return>Ninja</return>
                //				var w = parseInt($("#TaskbarList").css("width"));
                //				var cw = parseInt($("#Taskbar").css("width"))-49;
                //				if(w>cw)
                //				{
                //					$("#TaskbarNext").removeClass("inactive");
                //					$("#TaskbarNext").bind("click",BSC.P.OnTaskbarNext);
                //				}
                //				else
                //				{
                //					$("#TaskbarNext").addClass("inactive");
                //					$("#TaskbarNext").unbind("click",ByteStorm.Page.TaskbarNext);
                //					if(parseInt($("#TaskbarList").css("left"))<0)
                //					{
                //						$("#TaskbarList").animate({left:0},100);
                //						$("#TaskbarPrev").addClass("inactive");
                //						$("#TaskbarPrev").unbind("click",ByteStorm.Page.TaskbarPrev);
                //					}
                //				}
            },
            OnTabClick: function(e) {
                var el = BSC.E.GetElement(e, "ul", "a");
                if (!el.id) return;
                // Reset GUI selected
                $("#" + BSC.UI.Ws.GetActiveId() + "_tabs_content_ul li.selected").removeClass("selected");
                $(el).parent().addClass("selected");
                var h = el.href;
                GO((h).replace(/http:\/\/[^\/]+/i, ""));

                return false;
            },
            OnTaskbarClick: function(e) {
                var el = BSC.E.GetTarget(e);
                while (el.id !== "TaskbarList") {
                    if (el.nodeName.toLowerCase() == "div")
                        break;
                    else
                        el = el.parentNode;
                }

                //alert(el.nodeName.toUpperCase());
                var id = (el.id).replace(/Taskbar_/g, '');
                // Menu click
                if (id === "Menu") { $("#menu").css("z-index", BSC.UI.Ws.GetNextZIndex()); return; }
                // Window Item Click
                var w = BSC.UI.Ws.Get(id);
                if (!w.minimized && BSC.UI.Ws.GetActiveId() === id) {
                    BSC.UI.W.Minimize(id);
                    return false;
                }
                if (w.minimized && BSC.UI.Ws.GetActiveId() === id) {
                    BSC.UI.W.Restore(id);
                    return false;
                }
                if (!w.minimized && BSC.UI.Ws.GetActiveId() !== id) {
                    BSC.UI.W.Blur(BSC.UI.Ws.GetActiveId());
                    BSC.UI.W.Focus(id);
                    return false;
                }
                if (w.minimized && BSC.UI.Ws.GetActiveId() !== id) {
                    BSC.UI.W.Blur(BSC.UI.Ws.GetActiveId());
                    BSC.UI.W.Restore(id);
                    return false;
                }
                return false;
            },
            OnTaskbarContextClick: function(e) {
                /// <summary>Javascript data cache 4</summary>
                /// <param name="name">Person's name</param>
                /// <return>Ninja</return>
                var el = BSC.E.GetTarget(e);
                while (el.id !== "TaskbarList") {
                    if (el.nodeName.toUpperCase() === "DIV") {
                        e.stopPropagation();
                        var menuId = (el.id).replace(/Taskbar_/g, "");
                        if (menuId === "Menu") return;

                        var uilist = $("#TaskbarList");
                        var c = uilist.children();
                        var cl = c.length;
                        var i = 0;
                        var _menuId = null;
                        for (; i < cl; i++) {
                            _menuId = (c[i].id).replace(/Taskbar_/g, "");
                            if (_menuId === menuId)
                                break;
                        }
                        var uimenu = $("#TaskbarContextMenu");
                        var left = (120 * i) + 3
                        uimenu.css({ display: "block", bottom: 25, left: left });
                        uimenu.bind("click", { id: menuId }, BSC.P.OnTaskbarMenuClick);
                        return false;
                        break;
                    } else {
                        el = el.parentNode;
                    }
                }
            },
            OnTaskbarMenuDblClick: function(e) {
                var el = BSC.E.GetTarget(e);

                while (el.id !== "TaskbarList") {
                    if (el.nodeName.toLowerCase() === "div") {
                        e.stopPropagation();
                        var id = (el.id).replace(/Taskbar_/g, "");
                        if (id === "menu") return;
                        var w = BSC.UI.Ws.Get(id);
                        //						if(w.maximized) 
                        //				            BSC.UI.W.Restore(id);
                        //				        else
                        //					        BSC.UI.W.Minimize(id);

                        return false;
                        break;
                    } else {
                        el = el.parentNode;
                    }
                }


            },
            OnTaskbarMenuClick: function(e) {
                /// <summary>OnTaskbarMenuClick: Is fired when User Click the taskbar at the bottom of the site</summary>
                /// <param name="name">The event</param>
                var el = BSC.E.GetElement(e, "dl", "dd");
                var id = e.data.id;
                var a = (el.id).replace(/TaskMenu_/g, "");
                var w = BSC.UI.Ws.Get(id);
                if (a === "min") {
                    if (w.minimized)
                        BSC.UI.W.Restore(id);
                    else
                        BSC.UI.W.Minimize(id);
                    return;
                }
                if (a === "max") {
                    if (w.maximized)
                        BSC.UI.W.Restore(id);
                    else
                        BSC.UI.W.Maximize(id);

                    return;
                }
                if (a === "close") {
                    BSC.UI.W.Close(id);
                    return;
                }
                if (a === "closeothers") {
                    var list = BSC.UI.Ws.GetList();
                    for (k in list) {
                        if (k === id) continue;
                        BSC.UI.W.Close(k);
                    }
                    return;
                }
                if (a === "restore") {
                    BSC.UI.W.Restore(id);
                    return;
                }
                return;
            },
            PlaySound: function(key) {
                if (BSC.D.P.IsMute())
                    return;

                // click, notice
                try {
                    //   BSC.UI.GetFlash("FlashSound").playsound(key);
                }
                catch (e)
                { }
            }
        };
    } ();
    window.GO = BSC.P.Go;
})();

//   $.history.callback = function(reinstate, cursor)
//   {
//   	alert('now the value is: ' + reinstate);
//   };
