﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="jQ/jquery-latest-vsdoc.js" />
/// <reference path="../../jquery/ui/ui.draggable.js" />
/// <reference path="../../../Services/Pages.asmx" />
/// <reference path="../../../Services/Photos.asmx" />



// TODO: need to create a window object that stores variables to be added if the $AMS variable is not yet loaded... this will
// be an Array of objects to add
// AMS global variables
// TODO: use this to manage mouse events... manager the taskmanager

// $AMS is the top class / namespace.  it is to be more of the object manager the a page manager.
// TODO: move the win class to the page manager
// TODO: move auto fire functions to the page manager

// window.$ = jQuery;

(function () {

    //    if (window.$AMS !== undefined) {
    //        return window.$AMS;
    //    };
    var _domOnReady = null // array of commands to fire when the document is ready
    var AMSClass = function () {
        this.Init();

    };

    AMSClass.prototype = {
        classes: []
        , objs: []
        , Init: function () {
            _domOnReady = new Array();

            this.$gv = new global_var();
            this.$gf = global_func;
            this.$gf.functions = new Array();
            $(document).mousemove($.proxy(this.$gv.mloc.move, this.$gv.mloc));
            $(window).load($.proxy(this.$gv.win.WR, this.$gv.win));
            this.$gv.win._SetHW($(window).width(), $(window).height());
            $(window).resize($.proxy(this.$gv.win.WR, this.$gv.win));

            this.JQ = jQuery;

            this.$RC = this.RegisterClass;
            this.$RO = this.RegisterObject;

            this.AutoFun = new _aff();
            this.AutoFun.$gv = this.$gv;
            this.AutoFun.$gf = this.$gf;

            this.$RGF = this.RegGFunc;
            // this.classes = new Array();
            // this.objs = new Array();
            // add traking image
        }
        , RegisterClass: function (n, obj, cn) {
            var _c = false; /* sets if this class object has been added already or not true if it is */
            var _ind = -1;
            for (var ind in this.classes) {
                if (this.classes[ind] === n) {
                    /* object already registered */
                    _c = true;
                    _ind = ind;
                }
            }

            if (!_c) {
                /* register class */
                this.classes[this.classes.length] = n;
                obj.$gf = this.$gf;
                obj.$gv = this.$gv;
                obj.$RC = this.$RC;
                obj.$RO = this.$RO;
                obj.$RGF = this.RegGFunc;
                return obj;
            }
            else {
                if (cn == true) {
                    this.classes.splice(_ind, 1);
                    return this.RegisterClass(n, obj);
                }
            }


            /* end register function*/
        }
        , RegGFunc: function (n, obj) {
            var _c = false; /* sets if this class object has been added already or not true if it is */
            for (var ind in this.$gf.functions) {
                if (this.$gf.functions[ind] === n) {
                    /* function already registered */
                    _c = true;
                }
            }

            if (!_c) {
                /* register class */
                this.$gf.functions[this.$gf.functions.length] = n;
                return obj;
            }

            /* end register function*/
        }
        , RegisterObject: function (n, obj, arg, cn) {
            // n = the uniq id of the object type
            // obj = the obj to be created
            // arg = any arguments that need to be passed to the construct.
            // cn: if not undefined then see if true of false;;  if true the recreate object..
            this.$gf.ShowProgress();

            var _o = false;
            var _ind = -1;
            for (var ind in this.objs) {
                if (this.objs[ind][0] === n) {
                    _o = true;
                    _ind = ind;
                }
            }

            if (!_o) {
                var i = this.objs.length;
                this.objs[i] = new Array(n, null);
                this.objs[i][0] = n;
                var _obtmp = new obj(arg);
                _obtmp.$gf = this.$gf;
                _obtmp.$gv = this.$gv;
                _obtmp.$RC = this.$RC;
                _obtmp.$RO = this.$RO;
                _obtmp.$RGF = this.RegGFunc;
                if (_obtmp.Load !== undefined) {
                    _obtmp.Load();
                }
                this.$gf.HideProgress();
                this.objs[i][1] = _obtmp;
                return _obtmp;
            }
            else if (_ind != -1) {
                if (cn == true) {
                    // this.RegisterObject
                    this.objs.splice(_ind, 1);
                    return this.RegisterObject(n, obj, arg);
                }

                this.$gf.HideProgress();
                return this.objs[_ind][1];
            }
            else {
                // there was an error... should not reach this point
                this.$gf.HideProgress();
                return null;
            }
        }
    };

    var global_var = function () { this.Init(); }

    global_var.prototype = {
        Init: function () {
            this.elm.Init(this, this.elm);
        }
        , win: {
            size: { /* manages screen size*/
                wWidth: 0
                , wHeight: 0
                , tman: null /* manages the timer */
                    , wHeight: null
                    , wWidth: null
            }
            , WR: function (e) {

                if (this.size.tman !== null) {
                    clearTimeout(this.size.tman);
                }
                // TODO: fix this to use $.proxy
                this.size.tman = setTimeout("$AMS.$gv.win._SetHW( " + $(window).width() + "," + $(window).height() + ")", 50);
            }
            , _SetHW: function (w, h) {
                /* sets the height and width of the screen.  is fired from a timer */
                // this function is fired when the window resizes
                //                                $("#size-tracker").html(
                //                                            "d-w:" + w + " d-h:" + h
                //                                        );

                this.size.wWidth = w;
                this.size.wHeight = h;
                this.size.tman = null;
            }
        }
        , mloc: { /* manages mouse location */
            tman: null
            , x: null
            , y: null
            , move: function (e) {
                this.x = e.pageX;
                this.y = e.pageY
            }
        }
        , elm: {
            Init: function (s) {
                this.p = s;
                this.widgetCommands.Init(this);
            }
            , p: null
            , clearDiv: "<div class=\"clear\"></div>"
            , normalDiv: "<div></div>"
            , span: "<span></span>"
            , img: "<img></img>"
            , generalCmds: {
                saveIcon: ""
            }
            , widgetCommands: {
                Init: function (s) {
                    this.p = s;
                    this.settingsIcon = this._settingsIcon(this);
                    this.editIcon = this._editContentIcon(this);
                }
                , p: null
                , _settingsIcon: function (s) {
                    // var _t = this.p.p.css.cmdIcons;
                    return "<div class=\"" + this.p.p.css.cmdIcons + " " + this.p.p.css.settings + "\" title=\"Edit Widget Settings!\"></div>"
                }
                , _editContentIcon: function (s) {
                    return "<div class=\"" + this.p.p.css.cmdIcons + " " + this.p.p.css.editcontent + "\" title=\"Edit Content!\"></div>"
                }

            }
        }
        , css: {
            widgetCmdMenu: "ui-widget-commandmenu"
            , widgetCmdTitle: "ui-widget-commandmenu-title"
            , widgetCmdBar: "ui-widget-commands"
            , cmdIcons: "command-buttons"
            , cmdIconHover: "command-buttons-hover"
            , minIcon: "command-min" // minimize icon
            , restIcon: "command-restore" // restore icon
            , maxIcon: "command-max"
            , moveup: "command-moveup"
            , settings: "command-settings" // settings icon
            , editcontent: "command-editcontent"
            , del: "command-delete"
            , addZone: "command-addzone"
            , cancel: "command-cancel"
        }
    };

    /* internal AMS variables start */

    var ad = {
        apid: null /* application id - this will include the networkid */
        , rsid: null /* // this will be the rootdomainid, and subdomainid   */
        , pid: null /* this is the pages id */
        , sid: null // this is the current pages siteid
        , mid: null /* this is the local memberid */
        , mk: null /* this is the members xsorbit key */
        , ig: true /* true is member is a guest */
        , imoca: false /* true if they are a local member */
        , mn: "" /* this is the main network the member is apart of */
        , imgFileID: 0
        , hid: 0 // this is the hitid
    };

    var ad_settings_set = false
    , cv = 0; // this is the pages current view: 0 = page, 1 = dashboard

    /* internal AMS variables end */


    /* internal objects start */
    var _updatePan = null;

    var global_func = {
        functions: null
        , IsG: function () {
            return ad.ig;
        }
        , FindWidget: function (id) {
            // find widget by id
            var _item = null;
            if (id === undefined) {
                return _item;
            }

            $(".ui-widget-content").each(
                function (i) {
                    if (this.id.indexOf("_" + id + "_widget_content") >= 0) {
                        _item = $(this).parent().parent();
                        return false;
                    }
                }
            );
            return _item;
        }
        , CallUpdateP: function (id, arg) {
            // calls an update panel
        }
        , ShowProgress: function () {
            if (_updatePan == null) return;
            _ShowProgress();
        }
        , HideProgress: function () {
            if (_updatePan == null) return;
            _HideProgessBar();
        }
        , GetTrueSize: function () {
            var _rtn = 0;
            for (var i = 0; i < arguments.length; i++) {
                var _n = parseInt(arguments[i]);
                if (!isNaN(_n)) {
                    _rtn += _n;
                }
            }
            return _rtn;
        }
        , GetTrueWidthByElm: function (el, inM) {
            // returns the width of an element
            // if inM = true then includes elements margins

        }
        , GetChildrenWidth: function (el, inM) {
            // returns the total width of an element's children
            // if inM = true then includes elements margins
        }
        , GetTrueHeightByElm: function (el, inM) {
            // returns the width of an element
            // if inM = true then includes elements margins
        }
        , GetChildTallest: function (el, inM) {
            // returns the tallest child element
            // if inM = true then includes elements margins
        }
        , GetCurrentMemberimgFileID: function () {
            return ad.imgFileID;
        }
        , ShowMemberTT: function (d, trg, w, h, dir) {
            // dir = the direction to show the tooltip realtive to the target element (AMSCenterRTT) default
            // d = { img:{imgID:1, rs:1, w:80, h:80}, mem:{ pro:'', dis:'', nav:'', loc:{ city:'', state:'' } } }

            var _toolTipID = "AMSCenterRTT";
            var _toolTipDTail = "#AMSCenterInfo"

            if (dir !== undefined) {
                _toolTipID = "AMS" + dir + "RTT";
                _toolTipDTail = "#AMS" + dir + "Info";
            }


            var _tt = $find(_toolTipID);
            _tt.hide();

            $(_toolTipDTail).children().remove();
            var _ttContain = $('<div>');
            $('body').append(_ttContain);
            // TODO: edit this to use InitImage

            var _tsrc = '/images/image.aspx?imagefileid=' + d.img.imgID + '&rs=' + d.img.rs + '&w=' + d.img.w + '&h=' + d.img.h;
            var _img = $("<img oncontextmenu=\"return false;\" id=\"img_" + d.img.imgID + "\" src=\"" + _tsrc + "\" alt=\"" + d.mem.pro + "\" />")
            var _imgContain = $("<div id='TTImageContain' ></div>");
            // _imgContain.css("width", d.img.w);
            _imgContain.css("float", "left").width(d.img.w).height(d.img.h);
            _imgContain.append(_img);
            var _infoContain = $("<div id='TTInfoContain'></div>");
            _infoContain.css("float", "left").css("overflow", "visible").css("font-size", "10px").css("padding-left", "5px");

            var _memName = d.mem.pro;

            if (d.mem.dis != undefined) {
                if (d.mem.dis != "") {
                    _memName = d.mem.dis;
                }
            }

            var _inCTxt = "Member: " + _memName;

            //            var _member = $("<div id='profile'></div>");
            //            _infoContain.append(_member);
            //            var _dis = $("<div id='display'> + "</div>");
            //            _infoContain.append(_dis);



            if (d.mem.loc) {
                var _locTxt = "Location: ";
                if (d.mem.loc.city) {
                    _locTxt += d.mem.loc.city;
                }
                if (d.mem.loc.state) {
                    _locTxt += ", " + d.mem.loc.state;
                }

                _inCTxt += "<br/ >" + _locTxt;
                //                var _loc = $("<div id='loc' style='font-size:10px;'>" + _locTxt + "</div>");
                //                _infoContain.append(_loc);
            }

            _inCTxt += "<br /><p style='text-align:center;'><a href='" + d.mem.nav + "' style='font-size:14px; color:black; text-transform:none;' >Visit</a></p>"
            _infoContain.html(_inCTxt);

            _ttContain.appendTo('body');
            _ttContain.css("padding-right", "5px").css("padding-top", "5").css("padding-left", "5px");




            _ttContain.append(_imgContain).append(_infoContain);
            // _ttContain.append("<div class='clear'></div>");
            // _ttContain.wrap("<div title='test' ></div>");
            //  var _dt = _infoContain.outerWidth(true);

            //            alert(_imgContain.outerWidth(true));
            //            alert(_infoContain.outerWidth(true));
            _tt.set_targetControlID(trg);

            _ttContain.width(_imgContain.outerWidth(true) + _infoContain.outerWidth(true) + 12)
            _tt.set_width(_ttContain.outerWidth(true));
            // alert(_ttContain.outerWidth(true));
            $(_toolTipDTail).append(_ttContain);
            // alert($('#AMSCenterInfo').outerWidth());
            _tt.show();
            //  var _innW = this.GetTrueSize(_imgContain.outerWidth(true));  // _imgContain.css("width"), _imgContain.css("padding-left"), _imgContain.css("padding-right"), _imgContain.css("border-left-width"), _imgContain.css("border-right-width"));


            // _innW += this.GetTrueSize(_infoContain.outerWidth(true)); // _infoContain.css("width"), _infoContain.css("padding-left"), _infoContain.css("padding-right"), _infoContain.css("border-left-width"), _infoContain.css("border-right-width"));

            // _ttContain.width(_innW);
            // alert(_innW);

            // _ttContain.width(_ttContain.outerWidth());
            // alert(_ttContain.outerWidth());

            // var _t = _ttContain.outerWidth();


            // $('#AMSCenterInfo').append(_ttContain);
            /// alert(_t);
            // _ttContain.width(_ttContain.outerWidth(true));





            //            $('#AMSMemberInfo').width(200);
            //            var _t = $('#AMSMemberInfo').css("width"); // parseInt(_imgContain.css("padding-right")); // +_infoContain.width();
            //            var _tagain = "";




        }
        , InitImage: function (ldID, tid, imgID, rs, h, w, name, mH) {
            var tsrc = '/images/image.aspx?imagefileid=' + imgID + '&rs=' + rs + '&w=' + w + '&h=' + h;
            var img = $("<img oncontextmenu=\"return false;\" id=\"img_" + imgID + "\" src=\"" + tsrc + "\" alt=\"" + name + "\" title='" + name + "' />").appendTo(tid).hide();
            img.data("imgInfo", $.extend({}, { tid: tid, imgID: imgID, ldID: ldID, mH: mH, imH: h, imW: w }));
            img.onImagesLoaded(function (_img) {
                var d = $(_img).data("imgInfo");
                var p = $(d.tid);
                // p.append(_img);
                p.children(d.ldID).remove();

                if (d.mH != d.imH) {
                    if (img.height() < d.mH) {
                        var diff = d.mH - img.height();
                        diff = diff / 2;
                        p.css("padding-top", diff);
                        p.height(d.mH - diff);
                    }
                }

                $(_img).fadeIn(500);

            });
        }

    };

    //// these are functions that auto fire on every post back including updatepanel post backs
    var _aff = function () { };

    _aff.prototype = {
        OnLoad: function () {
            this.InitMwin();
        }
        , InitMwin: function () {
            $(".mod-windows").draggable();
        }
    };


    /* internal objects end */


    /* internal functions start */

    var _followSession = null
    , _ShowProgress = function (e) {
        $("BODY").css("cursor", "wait");
        _updatePan.css("left", $AMS.$gv.mloc.x - 14).css("top", $AMS.$gv.mloc.y - 14).show();
        // $("#updatingfollower").css("left", $AMS.$gv.mloc.x - 14).css("top", $AMS.$gv.mloc.y - 14);
        // $("#updatingfollower").show();
        _followTimer = setInterval(_UpdatingFollower, 10);
    }
    , _UpdatingFollower = function () {
        _updatePan.css("left", $AMS.$gv.mloc.x - 14).css("top", $AMS.$gv.mloc.y - 14);
        // $("#updatingfollower").css("left", $AMS.$gv.mloc.x - 14).css("top", $AMS.$gv.mloc.y - 14);
    }
    , _HideProgessBar = function () {
        clearInterval(_followSession);
        $("BODY").css("cursor", "default");
        _updatePan.hide();
    }


    /* internal function end */

    ///////////////////////////////////////////
    // window.$AMS loading
    // Expose AMS to the global object
    window.$AMS = new AMSClass;


    /* application manager start */
    (function () {

        /* app main will control networking communication actions */
        var AppMan = function () {
            this.Init();
        };

        AppMan.prototype = {
            /* variables */
            hObj: null /* this will store the online help object */

            /* functions */
            , Init: function () {

            }
            , Load: function () {

                if (!ad_settings_set && window.apd !== null) {
                    // use jQuery to build
                    $.extend(true, ad, window.apd);
                    window.apd = null;
                    ad_settings_set = true;
                    // get res $AMS.$gv.win.size.wWidth * .75, $AMS.$gv.win.size.wHeight
                    if (ad.hid !== 0 && ad.hid !== undefined) {
                        $(document).ready(function () { setTimeout(function () { $("<img src='/images/image.aspx?tk=t&hid=" + ad.hid + "&w=" + screen.width + "&h=" + screen.height + "' />").appendTo('body').hide(); }, 1000); });
                    }
                    window.onunload = this.Unload;
                }
            }
            , Getmid: function () {
                return ad.mid;
            }
            , Unload: function () {
                AMS.Web.Services.Pages.TimeLeft(ad.hid);
            }

        }; // prototype end

        $AMS.$AP = $AMS.$RO("AMS.AppManager", AppMan);

    })();

    /* application manager end */

    /* Page Manager start */

    (function () {

        /* page manager will hold page methodes */

        //    if (window.$AMS.$PM !== undefined) {
        //        return window.$AMS.$PM;
        //    };
        var _pid = null // this is the pagesid// this will be used to check the id agenst the outer variable to ensure they match
        , _isDlog = false // this is set to true if the page is a dialog page.  if so do somthing..
        , dlManager = null
        , cmds = {
            page: "/default.cmd" // page to call
            , ss: "3.3" // site settings
            , ap: "3.4" // add page to site
            , ps: "3.5" // page settings
            , lgin: "6.5" // opens login page
            , sup: "6.2" // opens signup page
        };

        /* private functions start */


        var _CreateUpDateObj = function () {
            var __div = "<div id=\"updatingPan\" style=\"position:absolute; z-index:10500; cursor:wait; background:white; padding:3px; border:solid 2px black; color:black;\">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Updating...&nbsp; </div>";
            _updatePan = $(__div).appendTo("body").hide();
        };

        /* private functions end */

        var PageManager = function () {
            // this is the objects construct
            this.Init();
        };

        PageManager.prototype = {
            /* variables
            openedWin = { rdwin = "the radwindow object", cmdid = "the commandid for this window", dOnC = "true or false, destroy on close" }
            */
            openedWin: []
            , lgnOpen: false
            , lgnWin: null
            /* functions */
            , Init: function () {
                _pid = window.pd.pid;
                window.pd = null;
            }
            , Load: function () {
                cv = 0; // sets current page view to page
                this.AddToDomReady(_CreateUpDateObj, null);
            }

            , AddToDomReady: function (fun, arg) {
                _domOnReady[_domOnReady.length] = new Array(fun, arg);
            }

            , DomReady: function () {
                // this.SPBar();

                for (var ind in _domOnReady) {
                    _domOnReady[ind][0](this, _domOnReady[ind][1]);
                }

                // this.HPBar();
            }

            , SPBar: function () {
                // shows progress bar
                if (_updatePan == null) return;
                _ShowProgress();
            }

            , HPBar: function () {
                // hides the progress bar
                if (_updatePan == null) return;
                _HideProgessBar();
            }
            , ODL: function (uri, size, loc, set) {
                // this opens a dialog window can be a command or any window
                if (dlManager == null) {
                    dlManager = GetRadWindowManager();
                }
                var oWnd = dlManager.open(uri);
                oWnd.set_visibleStatusbar(false);
                if (size) {
                    oWnd.setSize(size.width, size.height);
                }
                else {
                    oWnd.setSize($AMS.$gv.win.size.wWidth * .75, $AMS.$gv.win.size.wHeight - 30);
                }

                if (loc) {
                    oWnd.moveTo(loc.left, loc.top);
                }
                else {
                    oWnd.center();
                }

                if (set) {
                    if (set.win) { }
                    if (set.cmds) {
                        if (set.cmds.onclose) {
                            oWnd.add_close(set.cmds.onclose);
                        }
                    }
                }

                oWnd.setActive(true);
                return oWnd;
            }
            , CADL: function () {
                // closes the active dialog window
                if (dlManager == null) {
                    dlManager = GetRadWindowManager();
                }
                var aWnd = dlManager.getActiveWindow();
                aWnd.close();

            }
            , NTOCP: function () {
                // this navigates to a command page...
            }
            , OSS: function () {
                // opens the current site manager
                this.ODL(cmds.page + "?cmd=" + cmds.ss + "&siteid=" + ad.sid);
            }
            , OLin: function () {
                // opens login page
                this.lgnOpen = true;
                this.lgnWin = this.ODL(cmds.page + "?cmd=" + cmds.lgin, { height: 225, width: 460 });
                this.lgnWin.set_modal(true);
            }
            , LGGEDIN: function (shdb) {
                // this is called after they have logged in
                $('#hdnLogingIn').val(shdb);
                setTimeout(function () { __doPostBack(); }, 50);
            }
            , SUP: function () {
                // opens signup page
                if (this.lgnOpen) {
                    this.lgnWin.close();
                    this.lgnOpen = false;
                    // close window
                }
                var _jnWin = this.ODL(cmds.page + "?cmd=" + cmds.sup, { height: 400, width: 630 });
                _jnWin.set_modal(true);
            }
            , SNUP: function (trg) {
                $('#hdnLogingIn').val(trg);
                setTimeout(function () { __doPostBack(); }, 50);
            }
            , APTS: function (e) {
                // opens add new page dialog page manager
                this.ODL(cmds.page + "?cmd=" + cmds.ap + "&siteid=" + ad.sid);
            }
            , OTPS: function (pid) {
                this.ODL(cmds.page + "?cmd=" + cmds.ps + "&pid=" + pid);
            }
            , OPS: function () {
                // opens current page settings dialog
                // var newwidgeturl = "/default.cmd?cmd=3.5&pid=" + id;
                // TODO: make sure this member has permissions 1st...
                this.ODL(cmds.page + "?cmd=" + cmds.ps + "&pid=" + ad.pid);
            }
            , UpdPnl: function (id, arg) {
                // this call a postback on an update panel
                // TODO: monitor status.  make sure last post back completed before fireing this one off...
                __doPostBack(id, arg);
                setTimeout(this.HPBar, 2000);
            }
            , SP: function () {
                // saves the page.  turns of editing and update the main page panel
                $('#hdnEditMode').val("0");
                this.UpdPnl('MainPageUpdate', '');
            }
            , ReportErr: function () {
                // this calls the service to report javascript errors
            }
            , StylingPreview: function (s) {
                var _s = $(s).val();
                window.location = "?styleid=" + _s;
            }
        };

        $AMS.$PM = $AMS.$RO("AMS.PageManager", PageManager);
        $(document).ready($.proxy($AMS.$PM.DomReady, $AMS.$PM));
    })();


    /* Page Manager end */


    /* member manager start */

    //    function testing(){
    //        alert("testing");
    //    };

    (function () {

        var MemMan = function () {
            this.Init();
        };

        MemMan.prototype = {
            /* variables */
            isG: true  /* true if member is a guest */
            , isMP: false /* true if this is the members page */
            , myItems: {
                data: null
                , menu: null
            }
            , mk: null /* this is the members key */
            , db: {
                /* this is the setting for their dashboard */
                dbactive: false /* this is set when they activate their dashboard */
                , beenAct: false
                , dbdp: 0 /* this is the id of their default page. */
                , dblpage: 0 /* this is the id of their last active dashboard page */
            }

            /* functions */
            , Init: function () {

            }

            , Load: function () {
                // testing();
                var _t = "";
            }
            , Get_mid: function () {
                return ad.mid;
            }
            , OpenDD: function () {
                // this opens the members dashboard
                if (this.db.dbactive) {
                    this.CloseDD();
                }
                else {
                    if (!this.db.beenAct) {
                        __doPostBack('udpDashBoard', '');
                        this.db.beenAct = true;
                    }

                    $('#dbLoading').height($AMS.$gv.win.size.wHeight);
                    $("#PageContent").hide('slow');
                    $("#DashBoard").height($AMS.$gv.win.size.wHeight - 25).css("visibility", "visible").css("display", "block").show('slow');
                    // $("#OpenDBM").text("Close");
                    this.db.dbactive = true;
                }

            }
            , CloseDD: function () {
                // this closes the members dashboard
                $("#PageContent").show('slow');
                $("#DashBoard").hide('slow');
                // $("#OpenDBM").text("Open");
                this.db.dbactive = false;
            }
            , AppendAvatarImgTo: function (w, appTo) {
                $("<img oncontextmenu='return false;'  src='/images/image.aspx?imagefileid=" + $AMS.$gf.GetCurrentMemberimgFileID() + "&rs=1&w=" + w + "' />").appendTo(appTo);
            }
            , UpdateAvatar: function (imgFID) {
                // memberBasic_avatar_img

                var _c = $("#memberBasic_avatar_img");
                var img = $("<img src='/images/image.aspx?imagefileid=" + imgFID + "&rs=1&w=55' />").hide();
                _c.parent().append(img);
                img.show(500);
                _c.remove();
                img.attr("id", "memberBasic_avatar_img");
                _c = $("#start_menu_img");
                img = $("<img src='" + "/images/image.aspx?imagefileid=" + imgFID + "&rs=1&w=95" + "' style='margin:auto; width:95px;' />").prependTo(_c.parent());
                _c.remove();
                img.attr("id", "start_menu_img");
            }

        };

        $AMS.$MM = $AMS.$RO("AMS.MemMan", MemMan);

        /* member manager end */


    })();

    /* member manager end */

    /* taskbar manager start */

    /* taskbar manager end */

    /* dashboard manager start */

    (function () {

        function NotificationManager(obj) {
            if (obj != null) {
                $.extend(true, this, obj);
            }
            this.OnInit();
        }
        // TODO: this needs to be edited to use items as own object for better control
        NotificationManager.prototype = {
            btnNotify: null
            , imgWidth: 50
            , curItemList: []
            , curItemListJsonObj: []
            , imClicked: false
            , isOpen: false
            , notify_Box: null
            , unread_cnt_box: null
            , btnViewMore: null
            , btnViewAll: null
            , currentUnRdCnt: 0
            , cCheckingUnRd: false
            , OnInit: function () {
                var t = this;
                t.notify_Box = $('#Notify_Box');
                t.notify_Box.click($.proxy(t.Clicked, t));
                // index current list information
                var _itm_cnt = t.notify_Box.find('.item').length;
                for (var i = 0; i < _itm_cnt; i++) {
                    t.curItemList[t.curItemList.length] = $(t.notify_Box.find('.item')[i]);
                }
                t.btnNotify = $('#btn_Notify').show().click($.proxy(t.BtnNotify_Click, t));
                $('#Notify_Box .list .item').mouseenter($.proxy(t.Item_Enter, t)).mouseleave($.proxy(t.Item_Leave, t)).click($.proxy(t.Item_Click, t));
                t.currentUnRdCnt = $('#Notify_Box .list .item-unread').length;
                t.unread_cnt_box = $("<div class='unread-cnt-box' style='position:fixed; bottom:10px;'></div>"); // .css("left", t.btnNotify.position().left)
                if (t.currentUnRdCnt > 0) {
                    t.unread_cnt_box.text(" " + t.currentUnRdCnt + " ");
                }
                else {
                    t.unread_cnt_box.hide();
                }
                t.unread_cnt_box.appendTo(t.btnNotify);
                t.btnViewMore = t.notify_Box.find('#btnNotifiy_View_More').click($.proxy(t.ViewMore_Clicked, t));
                t.btnViewAll = t.notify_Box.find('#btnNotifiy_View_All').click($.proxy(t.ViewAll_Clicked, t));
                // set interval to check for more unread notifications
                setInterval($.proxy(t.CheckForUnread, t), 60000);
            }
            , BtnNotify_Click: function () {
                var t = this;
                if (t.isOpen) {
                    return false;
                }
                if (t.notify_Box == null) {
                    t.notify_Box = $('#Notify_Box');
                }

                var _readToUpdate = "";
                t.isOpen = true;
                t.notify_Box.show();
                // mark all markAsRdOV to read
                for (var i in t.curItemListJsonObj) {
                    if (t.curItemListJsonObj[i].markAsRdOV && !t.curItemListJsonObj[i].isRead) {
                        // find object to remove item-unread as read
                        $('#note_' + t.curItemListJsonObj[i].noteid).removeClass('item-unread');
                        t.curItemListJsonObj[i].isRead = true;
                        // TODO: build list to send back to web service to remove from db
                        if (_readToUpdate == "") {
                            _readToUpdate += t.curItemListJsonObj[i].noteid;
                        }
                        else {
                            _readToUpdate += "," + t.curItemListJsonObj[i].noteid
                        }
                        t.currentUnRdCnt -= 1;
                    }
                }

                t.unread_cnt_box.text(" " + this.currentUnRdCnt + " ");
                if (t.currentUnRdCnt == 0) {
                    t.unread_cnt_box.hide();
                    t.btnNotify.removeClass('notification-icon-active').addClass('notification-icon'); // notification - icon
                }

                if (_readToUpdate != "") {
                    setTimeout(function () {
                        t.UpdateRead(_readToUpdate)
                    }, 200);
                }
                t.btnNotify.addClass("notification-icon-clicked");
                $(document).bind("click.notifications", $.proxy(t.CloseNotifications, t));
                return false;
            }
            , Clicked: function () {
                this.imClicked = true;
            }
            , CloseNotifications: function () {
                if (this.imClicked) {
                    this.imClicked = false;
                    return false;
                }
                else {
                    this.btnNotify.removeClass("notification-icon-clicked");
                    this.notify_Box.hide();
                    $(document).unbind("click.notifications");
                    this.isOpen = false;
                }
            }
            , Item_Enter: function (s) {
                var _mem_name = $(s.currentTarget).find('.name');
                var _timeSpan = $(s.currentTarget).find('.time-span');
                _mem_name.addClass('hover');
                _timeSpan.addClass('hover');
            }
            , Item_Leave: function (s) {
                var _hover = $(s.currentTarget).find('.hover');
                _hover.removeClass('hover');
            }
            , Item_Click: function (s) {
                var _noteObj = null;
                var _ctargetid = $(s.currentTarget).attr('id').split('_')[1];
                if (_ctargetid == undefined) {
                    // TODO: record error
                    return;
                }
                var t = this;
                for (var i in t.curItemListJsonObj) {
                    if (_ctargetid == t.curItemListJsonObj[i].noteid) {
                        _noteObj = t.curItemListJsonObj[i];
                        break;
                    }
                }

                if (_noteObj != null) {
                    if (_noteObj.navOnClick) {
                        window.location = _noteObj.OnClick;
                    }
                    else {
                        eval(_noteObj.OnClick);
                    }
                }
            }
            , ViewMore_Clicked: function () {
                alert('view more clicked');
            }
            , ViewAll_Clicked: function () {
                alert('view all clicked');
            }
            , CheckForUnread: function () {
                var t = this;
                if (!t.cCheckingUnRd) {
                    t.cCheckingUnRd = true;
                }
                else {
                    return;
                }

                var _cl = "";

                if (t.curItemListJsonObj.length > 0) {
                    // build id list
                    for (var i = 0; i < t.curItemListJsonObj.length; i++) {
                        _cl += t.curItemListJsonObj[i].noteid;
                        if (i < t.curItemListJsonObj.length - 1) {
                            _cl += ",";
                        }
                    }
                }

                PageMethods.GetUnreadNotifies(_cl, $AMS.$MM.Get_mid(), function (rtn, uc, mn) {
                    t.UpdateList(rtn, uc, mn);
                },
                    function (rtn, uc, mn) {
                        t.cCheckingUnRd = false;
                    }
                );
            }
            , UpdateList: function (rtn, uc, mn) {
                var t = this;
                if (rtn != null) {
                    // var _t = "";
                    for (var i in rtn) {
                        t.AddItems(rtn[i]);
                    }

                    t.unread_cnt_box.text(" " + t.currentUnRdCnt + " ");
                    if (t.currentUnRdCnt == 0) {
                        t.unread_cnt_box.hide();
                    }
                    else {
                        t.btnNotify.removeClass('notification-icon').addClass('notification-icon-active');
                        t.unread_cnt_box.show();
                    }

                }
                t.cCheckingUnRd = false;
            }
            , AddItems: function (obj) {
                // need to make sure item doesn't already exits
                var t = this;
                for (var i in t.curItemList) {
                    if (obj.noteid == t.curItemList[i].attr('id').split("_")[1]) {
                        return;
                    }
                }
                t.curItemListJsonObj[t.curItemListJsonObj.length] = obj;
                var _ur = "";
                if (obj.isRead === false) {
                    t.currentUnRdCnt += 1;
                    _ur = " item-unread";
                }

                var _item = $("<div id='note_" + obj.noteid + "' class='item" + _ur + "'></div>");
                var _it = $("<table border='0' cellpadding='0' cellspacing='0' style='width:100%;'><tr><td class='profile-img'><img alt='" + obj.name + "' style='width:" + t.imgWidth + "px; height:" + t.imgWidth + "px;' src='/images/image.aspx?imagefileid=" + obj.imgFileID + "&rs=1&w=" + t.imgWidth + "' /></td>" +
                            "<td class='mem-info'><span class='name'>" + obj.name + "</span> " + obj.notes +
                            "<div class='time-span'>" + obj.timespan + "</div></td></tr></table>").appendTo(_item);
                //                var _img = $("");
                //                _it.find('.profile-img').append(_img);
                // _item.append(_it);
                t.notify_Box.children('.list').prepend(_item);
                t.curItemList[t.curItemList.length] = _item;
            }
            , UpdateRead: function (rd) {
                setTimeout(function () { PageMethods.MarkAsUpRead(rd, $AMS.$MM.Get_mid(), function (rtn, uc, mn) { }, function (rtn, uc, mn) { }); }, 200);
            }
        }

        var DBMan = function () {
            this.Init();
        };

        DBMan.prototype = {
            /* variables */
            leftWidth: 175
            , middleWidth: 575
            , rightWidth: 188
            , topHeight: null
            , bottom: null
            , NotifyMan: null
            , iframeElID: '#dbIframe'
            /* functions */
            , Init: function () {

            }
            , LoadNotifies: function (obj) {
                var t = this;
                $(document).ready(function () {
                    setTimeout(
                    function () {
                        t.NotifyMan = new NotificationManager(obj);
                    }, 2000);
                });
            }
            , Load: function () {
                var _t = "";

            }
            , LoadIF: function (url, hl, hr, hm, height) {
                // this loads a url in the frame

            }
            , ShowTop: function (sh) {
                // hides the top nav
            }
            , ShowBottom: function (sh) {

            }
            , ShowLeft: function (sh) { }
            , ShowMiddle: function (sh) { }
            , ShowRight: function (sh) {
                if (sh) {
                    $('#pnlBodyMiddle').width(this.middleWidth);
                    $('#pnlBodyRight').show();
                }
                else {
                    $('#pnlBodyRight').hide();
                    $('#pnlBodyMiddle').width(this.middleWidth + this.rightWidth);
                }
            }
            , LeftMenuClick: function () {

            }
            , PostBackReturned: function (obj) {
                //TODO: later get what their default page is
                var _hdnPostBack = $('#hdnDB1stLoad');
                if (_hdnPostBack.val() == "0") {
                    // alert('postback');
                    if (obj !== undefined) {
                        if (obj.ctype == 1) {
                            var _mpb = $find("DashBoardMain_dbLeftManu");
                            var _tm = _mpb.findItemByAttribute("mid", obj.mid);
                            _tm.click();
                        }
                        else if (obj.ctype == 0) {
                            this.LoadDBFrame(obj.navTo);
                        }
                    }
                    _hdnPostBack.val('1')
                }
            }
            , AddToMainLeftMenu: function (menu) {

                var panelBar = $find("DashBoardMain_dbControlLoadMenu");
                var _citems = panelBar.get_items();
                _citems.clear();

                var rootItem = new Telerik.Web.UI.RadPanelItem();
                rootItem.set_text(menu.text);

                if (menu.url != "") {
                    rootItem.set_navigateUrl(menu.url);
                }
                else {
                    rootItem.set_value(menu.value);
                }

                rootItem.get_attributes().setAttribute("mid", menu.mid);
                if (menu.img != "") {
                    rootItem.set_imageUrl(menu.img);
                }

                panelBar.trackChanges();
                panelBar.get_items().add(rootItem);

                for (var _ind in menu.subs) {
                    var childItem = new Telerik.Web.UI.RadPanelItem();
                    childItem.set_text(menu.subs[_ind].text);
                    if (menu.subs[_ind].url != "") {
                        childItem.set_navigateUrl(menu.subs[_ind].url);
                    }

                    childItem.set_value(menu.subs[_ind].value);

                    childItem.get_attributes().setAttribute("mid", menu.subs[_ind].mid);
                    if (menu.subs[_ind].img != "") {
                        childItem.set_imageUrl(menu.subs[_ind].img);
                    }

                    rootItem.get_items().add(childItem);
                    if (menu.subs[_ind].sel) {
                        childItem.set_selected(true);
                    }
                }

                rootItem.set_expanded(menu.expand);
                panelBar.commitChanges();


                //                var firstChild = new Telerik.Web.UI.RadPanelItem();
                //                firstChild.set_text("New First Child");
                //                var item = panelBar.findItemByText("New Root Item");
                //                item.get_items().insert(0, firstChild);



            }
            , LeftMenuClicked: function (sender, eventArgs) {

                if (sender.get_id() == "DashBoardMain_dbLeftManu") {
                    var panelBar = $find("DashBoardMain_dbControlLoadMenu");
                    var _citems = panelBar.get_items();
                    _citems.clear();
                    //                    var panelBar = $find("dbControlLoadMenu");
                    //                    if (panelBar.get_items().get_count() > 0) {
                    //                        var _citems = panelBar.get_selectedItem();
                    //                        if (_citems != null) {
                    //                            _citems.set_selected(false);
                    //                        }
                    //                    }
                }

                var _mid = eventArgs.get_item().get_attributes().getAttribute("mid");

                if (eventArgs.get_item().get_value() != null) {
                    // taskBarManager.showDialog(eventArgs.get_item().get_value(), eventArgs.get_item().get_text());
                    // $('#taskMenuPopUp').hide('slow');
                    // value cmd| ctype (0 = ajax callback to udpDashBoard, 1 = load page in iframe, 2 = javascript call, 3 = navtourl )
                    // carg = "argument for specific command type"
                    if (eventArgs.get_item().get_value() == "") {
                        return false;
                    }
                    var _itemObj = (new Function("return " + eventArgs.get_item().get_value()))();
                    if (_itemObj.ctype == 0) {
                        // do call back
                        var _cb = "";
                        $('#hdnLeftDBMenuValue').val(_itemObj.carg.ctrl);
                        __doPostBack('udpDashBoard', '');
                    }
                    else if (_itemObj.ctype == 1) {
                        // load in iframe
                        // var _t = "";
                        if (_itemObj.carg.iurl) {
                            // load internal file
                            $AMS.$DBM.LoadDBFrame("/default.cmd?" + _itemObj.carg.url + "&dbm=1"); //  
                        }
                        else {
                            $AMS.$DBM.LoadDBFrame(_itemObj.carg.url);
                        }
                    }
                    else if (_itemObj.ctype == 2) {
                        // window.frames.
                        var _t = _itemObj.carg.exe;
                        eval(_itemObj.carg.exe);
                    }

                }
                // 
                return false;
            }
            , LoadDBFrame: function (url) {
                $('#DbContentLoadingPanel').show();
                // var _t = $('#dbIframe');
                $('#dbIframe')[0].contentWindow.location = url;
                // $('#dbIframe').document.location = url;
                $('#dbIframe').show();
                setTimeout('$AMS.$DBM.IfHeight()', 100);
                // $("#frmTest").height($AMS.$gv.win.size.wHeight - 50);
            }
            , IfHeight: function () {

                var _if = $($('#dbIframe')[0].contentWindow.document.body); // $(dbIframe.document.body);
                if (_if.length == 0) {
                    setTimeout('$AMS.$DBM.IfHeight()', 100);
                    return;
                }
                var _h = _if.outerHeight(true);
                if (_h > this.$gv.win.size.wHeight) {
                    $('#dbIframe').height(_h + 20);
                    $("#DashBoard").height($('#dbIframe').height() + 25);
                }
                else {
                    $('#dbIframe').height(this.$gv.win.size.wHeight - 50);
                    $("#DashBoard").height(this.$gv.win.size.wHeight);
                }
            }
            , ResizeIfHeight: function (h) {
                if (h > $('#dbIframe').height()) {
                    $('#dbIframe').height(h);
                    $("#DashBoard").height(h + 50);
                }
            }
            , HideCLp: function () {
                $('#DbContentLoadingPanel').hide();
            }
        };

        $AMS.$DBM = $AMS.$RO("AMS.DBMan", DBMan);

        /* dashboard manager end */


    })();

    /* dashboard manager end */

    /* tooltip manager start */

    (function () {

        var ToolTipMan = function () {
            this.Init();
        };

        ToolTipMan.prototype = {
            /* variables
            tType (1='rating tooltip')
            */

            /* functions */
            Init: function () {

            }

            , Load: function () {
                var _t = "";
            }

            , ShowTT: function (arg) {
                if (arg.tType === 1) {
                    this.RatingTT.OnShow(arg);
                }
            }
        };

        $AMS.$TTM = $AMS.$RO("AMS.TTM", ToolTipMan);

    })();

    /* tooltip manager end */

    /* rating manager start */

    (function () {

        var RatingMan = function () {
            this.Init();
        };

        RatingMan.prototype = {
            /* variables */
            RatingTT: {
                id: "AMSRatingToolTip"
                , ct: "AMSRatingToolTipContent"
                , hdnID: "hdnRating"
                , title: "Rating"
                , txtBox: "txtRatingComment"
                , OnShow: function (arg) {
                    if (arg.title != null && arg.title != undefined) {
                        title = arg.title;
                    }
                    else {
                        title = "Rating";
                    }
                }
                , Submit: function () {
                    var _v = $("#" + this.hdnID).data(this.id);
                    var _cmt = $("#" + this.txtBox).val();
                    _v.cmt = _cmt;
                    PageMethods.Rating_Post(_v, this.ratingReturned, this.ratingReturnedError);
                }
                , ratingReturned: function (rtn, uc, mn) {
                    var rating = $find(rtn.rttid);
                    rating.set_enabled(false);
                    rating.set_value(rtn.avg);
                    var tooltip = $find("AMSRatingToolTip");
                    tooltip.set_targetControlID(null);
                    tooltip.hide();
                    // var _h = $AMS.$RateMan.RatingTT.txtBox;
                    $('#' + $AMS.$RateMan.RatingTT.txtBox).val("");
                }
                , ratingReturnedError: function (rtn, uc, mn) {

                }
            }

            /* functions */
            , Init: function () {
                $("#btnSubmitRating").click(function () { alert("clicked"); }); // $.proxy(this.RatingTT.Submit, this));
            }

            , Load: function () {

            }

            , Rated: function (controlRating, args) {
                var _this = $AMS.$RateMan;
                var tooltip = $find(_this.RatingTT.id);
                tooltip.hide();
                $('#' + $AMS.$RateMan.RatingTT.txtBox).val("");
                if (!controlRating.get_enabled()) {
                    return;
                }

                var _trgID = controlRating.get_id();
                var _trg = $('#' + _trgID);
                var _g = _trg.attr('jDt');
                var _data = (new Function("return " + _trg.attr('jDt')))();

                var _ttContent = $("#" + _this.RatingTT.ct);
                _ttContent.children(".title").text("Rating - " + _data.title + ": ( " + controlRating._value + " /5 )");
                _data.val = controlRating._value;
                _data.rttid = _trgID;
                $("#" + _this.RatingTT.hdnID).data(_this.RatingTT.id, _data);

                tooltip.set_targetControlID(_trgID);
                tooltip.show();
            }
        };

        $AMS.$RateMan = $AMS.$RO("AMS.RateMan", RatingMan);

    })();

    /* rating manager end */



})(window);
/* rating manager end */


/* favorite manager start */

(function () {
    var FavMan = function () {
    };

    FavMan.prototype = {
        /* variables */

        /* functions */
        Init: function () {
        }
        , Load: function () {
        }
        , AddToFave: function( ftyp, id) {
            // ftyp = favorite type, id = id of the favorite
            var _mid = $AMS.$AP.Getmid();
            $AMS.$PM.ODL('/default.cmd?cmd=7.1&ftyp=' + ftyp +'&id=' + id + '&mid=' + _mid, {width:150, height:150 });
        }
    };

    $AMS.$FavMan = $AMS.$RO("AMS.FavMan", FavMan);

})();

/* favorite manager end */




// this is the new widget manager
(function () {
    var $AMS = window.$AMS;

    var WidgetMan = function () {
        this.Init();

    };

    WidgetMan.prototype = {
        wl: null // list of widgets on page
        , Init: function () {
            this.wl = new Array();
        }
        , Load: function () {

        }
        , FILByID: function (zwcid) {
            // finds the widget in the managers list based on the wid returns null if not found
            // returns widget obj if is found
            var _rtn = null;
            for (var ind in this.wl) {
                if (this.wl[ind].zwcid === zwcid) {
                    _rtn = this.wl[ind];
                    break;
                }
            }
            return _rtn;
        }
        , FIPByID: function (elid) {
            // finds a widget on the page based on the widget ID... must find in list 1st...
            // returns null if not found.. returns the jquery obj if found
            var _rtn = null;
            var _obj = this.FILByID(elid);
            if (_obj !== null) {
                // obj was found.. now see if we can get the element on the page
                _rtn = $("#" + _obj.elid);
                if (_rtn.length == 0) {
                    _rtn = null;
                }
            }
            return _rtn;
        }
        , FILByEl: function (elid) {
            // find a widget in the list based on the elemnet id returns null if not found
            // returns widget obj if is found
            var _rtn = null;
            for (var ind in this.wl) {
                if (this.wl[ind].elid === elid) {
                    _rtn = this.wl[ind];
                    break;
                }
            }
            return _rtn;
        }
        , FIPByEl: function (elid) {
            // finds a widget on the page based on the elementid
            // returns null if not found.. returns the jquery obj if found
            var _rtn = null;
            var _obj = this.FILByEl(elid);
            if (_obj !== null) {
                // obj was found.. now see if we can get the element on the page
                _rtn = $("#" + _obj.elid);
                if (_rtn.length == 0) {
                    _rtn = null;
                }
            }
            return _rtn;
        }
        , RegWidget: function (obj) {
            // need to check ID if this widget is registered ...
            // if it is and this has been call then it should be from a post back ... need to call updated on widget not add
            // remember we are going to store the actual object in the list
            var _tmpOb;
            if (this.wl.length > 0) {
                // check if this widget exists
                var _obj = this.FILByID(obj.zwcid);
                if (_obj == null) {
                    // create obj.
                    _tmpOb = new this.WidgetClass(obj, this.WidgetClass); // $.extend(true, this.WidgetClass.prototype, this.WidgetClass, obj);
                    this.wl[this.wl.length] = _tmpOb;
                }
                else {
                    // update obj
                    _obj.Update(obj);
                }
            }
            else {
                // create obj
                _tmpOb = new this.WidgetClass(obj, this.WidgetClass); // $.extend(true, this.WidgetClass.prototype, this.WidgetClass, obj);
                this.wl[this.wl.length] = _tmpOb;
            }
        }
    };

    // remove for live
    $AMS.WidgetMan = $AMS.$RO("AMS.WidgetMan", WidgetMan);

    if ($AMS.WidgetMan === undefined) {
        $AMS.WidgetMan = $AMS.$RO("AMS.WidgetMan", WidgetMan);
    }



    var TitleBarClass = function (s) {
        // note if shown is false then only build if the current member is the owner of the page or has permissions to this widget
        return (function () {

            var _elm = null;
            var t = this;
            var Obj = function () {
                this.Init();
            };

            Obj.prototype = {
                title: ""
                , visible: false
                , Init: function () {
                    this.title = s.title;
                    _elm = "<div class=\"ui-title\">test</div>";
                }
                , OMO: function () {
                    var _p = s;
                    var _e = _elm;
                }
            };

            return new Obj();
        })();
    };

    var Widget = function (obj, a) {
        $.extend(true, this, a, obj);
        this.Init();
    };


    Widget.prototype = {
        /* variables */


        /* element info */
        elid: null /* this is the widgets elementid */
        , pelid: null /* this is the elementid of this widget */
        , upDatePanel: null /* this is the id of the update panel */
        , felid: null /* this is the element id of the footer.. once we have this build this object we'll use an object torack it. */
        , telid: null /* this is the id of the title bar... once we have this build this object we'll use an object torack it. */

        /* properties */
        , pid: null  /* this is the id of the parent... will probably encrypt // later will use zone manager to set this so dont have to pass */
        , tKey: null /* this is the widgets key */
        , zwcid: null /* this is the zonewidgetcrossid encrypted for post back use */
        , level: null /* this is the page level of the widget.  if it is app=1, root = 2, and so on */
        , name: "" /* this is the widgets name */
        , title: "" /* widgets title if different then name or title */
        , isA: null /* if widget is active on page.  only important when in editing mode */
        , isExpanded: null /* this is if the widget is currently expanded */
        , isColapsable: null /* this is only important */
        , perm: null /* =false if current person is allowed to see it.  not realy import for none editing more widget will not show up at all */
        , style: null /* this will be used if member has added custom styling */
        , showTitle: false /* if title is to be shown */
        , showFooter: false /* if footer is to be shown */
        , footerText: "" /* text to be added to the footer */
        , resizeable: false /* tells weather this widget can be resized */
        , cpos: null /* this is the current posistion of the widget in the list */
        , zt: null /* this is the zone type.. this will be used to tell when type of direction resize can be done */
        , isDmode: false /* set to true if the current widget is in dragdrop mode */
        , isInCMode: false /* if true this widget is in content editing mode */
        , ce: false /* this is true if the member can edit anything. if false do not build any menus */
        , cec: false /* this is true if the current member can edit the content */
        , ces: false /* this is true if the current member can edit the settings */
        , crz: false /* this is true if the current member can resize the widget */

        /* objects */
        , cmds: null /* this will be the object that stores the command tree */
        , cMenu: null /* this is the content editing menu */
        , dMenu: null /* this is the menu used for dragdrop */
        , appObj: null /* this is any data obj that the inner app needs to store */

        /* event listeners */
        , omoFun: null /* this is an array of function that need to fire on the mouse over event */
        , omlFun: null /* this is an array of functions that need to fire on the mouse leave event */

        /* functions */
        , Init: function () {
            //            this.elid = obj.elid;
            //            this.pelid = obj.pelid;

            this.omoFun = new Array();
            this.omlFun = new Array();
            $("#" + this.elid).mouseenter($.proxy(this.OME, this));
            $("#" + this.elid).mouseleave($.proxy(this.OML, this));
            if (this.ce) { this.BuildCMenu(); };
            this.telid = TitleBarClass(this);
        }

        /* command icon objects */
        , cmdsClass: function () {

            var _cmds = function (s) {

                // private variables
                this.custom = new Array();

                var _editIconClass = function (s) {
                    /* this is the settings construct */
                    // private variabels
                    this.ome = new Array();        /* events to fire when mouse enters this */
                    this.oml = new Array();        /* fires when leaves obj */
                    this.clickStart = new Array(); /* stores the events to fire when the click event starts before the postback is called to the event */
                    this.clickEnd = new Array();   /* stores the events to fire after the post back */
                    this.p = s;
                    this.visible = this.p.cec; // true;
                    // private functions
                    var OME = function (e) {
                        /* this fires when the settings icon is fired this will be mostly used for styling */
                        this.element.toggleClass(this.p.$gv.css.cmdIconHover);
                    };

                    var OML = function (e) {
                        /* this fires when the settings icon is fired this will be mostly used for styling */
                        this.element.toggleClass(this.p.$gv.css.cmdIconHover);
                    };

                    var Click = function (e) {

                        if (!this.p.isInCMode) {
                            this.element.toggleClass(this.p.$gv.css.cmdIconHover);
                            var _w = $("#" + this.p.elid); // $(e.currentTarget);
                            var _m = $("#wcm_" + _w.attr("id"));
                            _m.hide();
                            _m.appendTo("body");

                            //                            PageManager.Mouse.x = this.p.$gv.mloc.x;
                            //                            PageManager.Mouse.y = this.p.$gv.mloc.y;

                            var ih = this.p.elid + "_EditingMe";
                            $("#" + this.p.elid + "_ClientHeight").val($("#" + this.p.elid).height());
                            $("#" + this.p.elid + "_ClientWidth").val($("#" + this.p.elid).width());

                            if (this.clickStart.length > 0) {
                                for (var ind in this.clickStart) {
                                    this.clickStart[ind](this.p, e);
                                }
                            };

                            // old function... will be replaced

                            Widgets.StartEditingContent(this.p.elid, ih);
                        }
                    };

                    // public variables
                    // this.visible = true;           /*  if this icon is visible  */

                    // public functions
                    this.element = null;
                    this.MouseEnter = function (fun) { };
                    this.MouseLeave = function (fun) { };
                    this.OnClickStart = function (fun) { };
                    this.OnClickEnd = function (fun) { };

                    this.element = $(s.$gv.elm.widgetCommands.editIcon);
                    this.element.attr("id", this.p.elid + "_edit_icon");
                    this.element.click($.proxy(Click, this));
                    this.element.mouseenter($.proxy(OME, this));
                    this.element.mouseleave($.proxy(OML, this));

                };

                var _settingsIconClass = function (s) {
                    /* this is the settings construct */
                    // private variabels
                    this.ome = new Array();        /* events to fire when mouse enters this */
                    this.oml = new Array();        /* fires when leaves obj */
                    this.clickStart = new Array(); /* stores the events to fire when the click event starts before the postback is called to the event */
                    this.clickEnd = new Array();   /* stores the events to fire after the post back */
                    this.p = s;
                    this.visible = this.p.ces; // true;
                    // private functions
                    var OME = function (e) {
                        /* this fires when the settings icon is fired this will be mostly used for styling */
                        this.element.toggleClass(this.p.$gv.css.cmdIconHover);
                    };

                    var OML = function (e) {
                        /* this fires when the settings icon is fired this will be mostly used for styling */
                        this.element.toggleClass(this.p.$gv.css.cmdIconHover);
                    };

                    var Click = function (e) {

                        if (!this.p.isInCMode) {
                            var _w = $("#" + this.p.elid); // $(e.currentTarget);
                            var _m = $("#wcm_" + _w.attr("id"));
                            _m.hide();
                            _m.appendTo("body");
                            this.element.toggleClass(this.p.$gv.css.cmdIconHover);

                            var newwidgeturl = "/default.cmd?cmd=2.2&wid=" + this.p.zwcid;
                            var oManager = GetRadWindowManager();
                            var oWnd = oManager.open(newwidgeturl, "DialogWindow");
                            oWnd.setSize($(window).width() * .75, $(window).height() * .80);
                            oWnd.center();


                            if (this.clickStart.length > 0) {
                                for (var ind in this.clickStart) {
                                    this.clickStart[ind](this.p, e);
                                }
                            };

                        }
                    };

                    // public variables
                    // this.visible = true;           /* if this icon is visible  */

                    // public functions
                    this.element = null;
                    this.MouseEnter = function (fun) { };
                    this.MouseLeave = function (fun) { };
                    this.OnClickStart = function (fun) { };
                    this.OnClickEnd = function (fun) { };

                    this.element = $(s.$gv.elm.widgetCommands.settingsIcon);
                    this.element.click($.proxy(Click, this));
                    this.element.mouseenter($.proxy(OME, this));
                    this.element.mouseleave($.proxy(OML, this));

                };



                // public variables
                this.visible = true;

                // create setting icon
                this.settings = new _settingsIconClass(s);


                // create edit icon
                this.edit = new _editIconClass(s);

                // public functions


            };

            var _cmd = new _cmds(this);

            var _elm = $(this.$gv.elm.normalDiv);
            _elm.addClass(this.$gv.css.widgetCmdBar);

            if(_cmd.edit.visible){
                _elm.append(_cmd.edit.element);
            }

            if(_cmd.settings.visible){
                _elm.append(_cmd.settings.element);
            }
            
            // add clear object
            _elm.append(this.$gv.elm.clearDiv);

            _cmd.element = _elm;

            this.cmds = _cmd;

            // build command list

        }

        , GetCommandList: function () {
            if (this.cmds == null) {
                // build command list
                this.cmdsClass();
            }

            return this.cmds.element;
        }

        , RegContainer: function () {
            /* this register the update panel information */
        }
        , BuildCMenu: function () {

            var _cMenu = function (s) {

                this._p_ome = function (s, e) {
                    if (!s.isDmode && !s.isInCMode) {
                        var _w = $("#" + s.elid); // $(e.currentTarget);
                        var _m = $("#wcm_" + _w.attr("id"));
                        _m.appendTo(_w);
                        var _t = _w.position().top - _m.height();
                        if (_w.position().top < _m.height()) {
                            // put at bottom of widget.
                            _t = _w.position().top + _w.height();
                        }

                        if ($.browser.msie && $.browser.version < 8) {
                            // need to set width
                            _m.css("width", _w.width() * .7);
                            // also need to move down just a little
                            _t = _w.position().top - (_m.height() * .25);
                        }

                        _m.css("top", _t).css("left", _w.position().left).show();

                    }

                };

                this._p_oml = function (s, e) {
                    if (!s.isDmode && !s.isInCMode) {

                        var _w = $("#" + s.elid);
                        var _m = $("#wcm_" + _w.attr("id"));
                        _m.hide();
                        _m.appendTo("body");
                        var _t = "";

                    }

                };

                var _item = $("#" + s.elid);
                if (_item != null) {
                    if (_item.length != 0) {
                        // var _w = _item; // $("#" + _item);
                        var _m = $(s.$gv.elm.normalDiv); // this.$gf.BuildWidgetCMenu(_data.ZoneWidgetCrossID);
                        _m.hide();
                        _m.attr("id", "wcm_" + _item.attr("id")).addClass($AMS.$gv.css.widgetCmdMenu).css('visibility', 'visible');
                        _m.css("z-index", 500);

                        var _title = $(s.$gv.elm.normalDiv);
                        var _t = $(s.$gv.elm.normalDiv).appendTo(_title);

                        _t.html("<span>Menu: </span><span title='Click to edit title!'>" + s.title + " </span>");
                        _t.css("padding-left", "3px").css("padding-top", "3px")
                        .css("padding-right", "10px").css("float", "left");


                        _title.addClass(s.$gv.css.widgetCmdTitle);
                        _title.appendTo(_m);

                        var __cmdmenu = s.GetCommandList();
                        __cmdmenu.css("float", "right");
                        __cmdmenu.appendTo(_title);

                        _title.append(s.$gv.elm.clearDiv);
                        _m.append(s.$gv.elm.clearDiv);
                        _m.appendTo("body");
                        // $("body").append(_m);
                        
                    }
                }
            }

            this.cMenu = new _cMenu(this);
            this.MouseEnter(this.cMenu._p_ome);
            this.MouseLeave(this.cMenu._p_oml);
        }
        , Update: function (obj) {
            // the obj are the new settings being passed in
            // this updates an obj that already exists
            $.extend(true, this, obj);
            // i think i need to rebind mouse over objects... 
            $("#" + this.elid).mouseenter($.proxy(this.OME, this));
            $("#" + this.elid).mouseleave($.proxy(this.OML, this));

            var _t = this;
        }
        , MouseEnter: function (fun) {
            this.omoFun[this.omoFun.length] = fun;
        }
        , MouseLeave: function (fun) {
            this.omlFun[this.omlFun.length] = fun;
        }
        , OME: function (e) {
            if (this.omoFun.length > 0) {
                for (var ind in this.omoFun) {
                    this.omoFun[ind](this, e);
                }
            }
            this.telid.OMO();
        }
        , OML: function (e) {
            if (this.omlFun.length > 0) {
                for (var ind in this.omlFun) {
                    this.omlFun[ind](this, e);
                }
            }
        }
        , SettingClicked: function (e) {

            PageManager.Mouse.x = this.$gv.mloc.x;
            PageManager.Mouse.y = this.$gv.mloc.y;

            var ih = this.elid + "_EditingMe";
            $("#" + this.elid + "_ClientHeight").val($("#" + this.elid).height());
            $("#" + this.elid + "_ClientWidth").val($("#" + this.elid).width());

            Widgets.StartEditingContent(this.elid, ih);
            return false;
        }
    };

    // czidDom:'2_12_zone_content', widgetid:18, pid:12, zt:0, cpos:0, name:'head logo', ised:false
    // remove for live
    $AMS.WidgetMan.WidgetClass = $AMS.$RC("AMS.WidgetMan.Widget", Widget);

    if ($AMS.WidgetMan.WidgetClass === undefined) {
        $AMS.WidgetMan.WidgetClass = $AMS.$RC("AMS.WidgetMan.Widget", Widget);
    }

})();

( function() {

    var PhotoCommentManagerClass = function (obj) {
        $.extend(true, this, obj);
        this.Init();
    };

    PhotoCommentManagerClass.prototype = {
        /* variables */
        imgID: null
        , UpdatingObj: null
        , cmtTxtBoxEl: null
        , cmtEl: null
        , cmtBoxElm: null
        , cmtTmpBoxElm: null
        , btnSave : null
        , dyBuild: false // false if already on page.. true if this needs to build it dynamically
        /* function */
        , Init: function () {
            var t = this;
            if(t.cmtEl == null) {
                t.cmtEl = $('#img_comment_main_container');
            }

            t.UpdatingObj = $('#img_comment_uploading');

            t.cmtTxtBoxEl = $('#img_comment_txtbox');
            t.cmtBoxElm = $('#img_commentbox_msg_box');

            t.cmtTmpBoxElm = $('#btn_img_commentbox');
            t.cmtTmpBoxElm.click($.proxy(t.cmtBoxElm_clicked,t));

            t.btnSave = $("#btn_img_comment_save");
            t.btnSave.click($.proxy(t.btnSave_Clicked,t));
        }
        , Load: function () { }
        , cmtBoxElm_clicked: function(){
            var t = this;
            t.cmtBoxElm.show();
            t.btnSave.show();

            t.UpdatingObj.hide();
            t.cmtTmpBoxElm.hide();
            t.cmtTxtBoxEl.focus();
            $(document).bind("click." + t.imgID , $.proxy(t.ResetmsgBox, t));
        }
        , btnSave_Clicked: function(){
            var t= this;
            t.btnSave.hide();
            t.UpdatingObj.show();
            $(document).unbind("click." + t.imgID);

            AMS.Web.Services.Photos.PostComment(t.imgID,$AMS.$MM.Get_mid(),t.cmtTxtBoxEl.html());
            t.cmtTmpBoxElm.show();
            t.cmtBoxElm.hide();
            t.cmtTxtBoxEl.html('&nbsp;');
            var _cArea = $("#imgid_" + t.imgID + "_comments");

            var _newComment = $("<tr></tr>"); //  t.cmtBoxElm.append("<tr></td>");
            var _myimg = $('#img_comment_myimg').clone();
            var _imgph = $("<td class='imgC-35'></td>");
            _imgph.append(_myimg).appendTo(_newComment);
            _newComment.append("<td class='area'> <span class='member-name'> You</span> " + t.cmtTxtBoxEl.html() + "</td>");
            _cArea.append(_newComment);

        }
        , ResetmsgBox: function (s) {
            var _s = $(s.target);
            var _class = _s.attr("className");
            _class += " " + _s.parent().attr("className");
            if (_class.indexOf('pom') > 0) {
                return false;
            }
            this.cmtBoxElm.hide();
            this.cmtTmpBoxElm.show();
            $(document).unbind("click." + this.imgID); // , $.proxy(this.ResetmsgBox, this)
        }
    };

    $AMS.PhotoCommentManagerClass = $AMS.$RC("AMS.PhotoCommentManagerClass", PhotoCommentManagerClass);

})();

( function() {

    var BlogManagerClass = function(obj) {
        $.extend(true, this, obj);
        this.Init();
    };

    BlogManagerClass.prototype = {
        blogID: null
        , Init: function() {
        
        }
        , Load: function() {}

    };

    var ArticleCommentManagerClass = function (obj) {
        $.extend(true, this, obj);
        this.Init();
    };

    ArticleCommentManagerClass.prototype = {
        /* variables */
        articleID: null
        , UpdatingObj: null
        , cmtTxtBoxEl: null
        , cmtEl: null
        , cmtBoxElm: null
        , cmtTmpBoxElm: null
        , btnSave : null
        , dyBuild: false // false if already on page.. true if this needs to build it dynamically
        /* function */
        , Init: function () {
            var t = this;
            if(t.cmtEl == null) {
                t.cmtEl = $('#article_comment_main_container');
            }

            t.UpdatingObj = $('#article_comment_uploading');

            t.cmtTxtBoxEl = $('#article_comment_txtbox');
            t.cmtBoxElm = $('#article_commentbox_msg_box');

            t.cmtTmpBoxElm = $('#btn_article_commentbox');
            t.cmtTmpBoxElm.click($.proxy(t.cmtBoxElm_clicked,t));

            t.btnSave = $("#btn_article_comment_save");
            t.btnSave.click($.proxy(t.btnSave_Clicked,t));
        }
        , Load: function () { }
        , cmtBoxElm_clicked: function(){
            var t = this;
            t.cmtBoxElm.show();
            t.btnSave.show();

            t.UpdatingObj.hide();
            t.cmtTmpBoxElm.hide();
            t.cmtTxtBoxEl.focus();
            $(document).bind("click." + t.articleID , $.proxy(t.ResetmsgBox, t));
        }
        , btnSave_Clicked: function(){
            var t= this;
            t.btnSave.hide();
            t.UpdatingObj.show();
            $(document).unbind("click." + t.articleID);

            AMS.Web.Services.Pages.PostArticleComment(t.articleID,$AMS.$MM.Get_mid(),t.cmtTxtBoxEl.html());
            t.cmtTmpBoxElm.show();
            t.cmtBoxElm.hide();
            t.cmtTxtBoxEl.html('&nbsp;');

            var _cArea = $("#articleid_" + t.articleID + "_comments");

            var _newComment = $("<tr></tr>"); //  t.cmtBoxElm.append("<tr></td>");
            var _myimg = $('#img_comment_myimg').clone();
            var _imgph = $("<td class='imgC-35'></td>");
            _imgph.append(_myimg).appendTo(_newComment);
            _newComment.append("<td class='area'> <span class='member-name'> You</span> " + t.cmtTxtBoxEl.html() + "</td>");
            _cArea.append(_newComment);

        }
        , ResetmsgBox: function (s) {
            var _s = $(s.target);
            var _class = _s.attr("className");
            _class += " " + _s.parent().attr("className");
            if (_class.indexOf('pom') > 0) {
                return false;
            }
            this.cmtBoxElm.hide();
            this.cmtTmpBoxElm.show();
            $(document).unbind("click." + this.articleID); // , $.proxy(this.ResetmsgBox, this)
        }
    };

    $AMS.BlogManagerClass = $AMS.$RC("AMS.BlogManagerClass", BlogManagerClass);
    $AMS.ArticleCommentManagerClass = $AMS.$RC("AMS.ArticleCommentManagerClass", ArticleCommentManagerClass);

})();