//<!--
/************
This file is part of Genwi JS Lib.
All Rights Reserved.

Desc: mystuff. Controls for mystuff page..

************/

function MyStuff()
{
    this.oAllItemLink = null;
    this.oSharedItemLink = null;
    this.sCurSidePanel = 'panelAll';
    this.aItemLinkNames = ['snapShotLink:snap:Summary','allItemsLink:new:Most Recent','popularItemsLink:popular:Most Popular','ratingsItemsLink:ratings:Highest Rated','mostSharedItemsLink:shared:Most Shared'];
    this.sSidePanels = {'panelAll':'snap','panelShared':'shared','panelFriends':'favs','panelPost':'quick','publicWire':'public'};
    this.oItemLinks = [];
    this.oBCLyr = null;
    this.sInitialBC = null;
    this.oInlineHelpLyr = null;
    this.oFilterTextLyr = this.oFilterLyr = null;
    this.oTimer = this.oShowSourceTimer = this.oFilterTimer = null;
    this.aLvlBCs = {lvl1:null,lvl2:null,lvl3:null};
    this.sBcSpanStr = '&nbsp;<span class="bcgrey">&nbsp;/&nbsp;</span>&nbsp;';
    this.sCurFilterView = this.sBCText = this.sCurFilterOrder = null;
    this.sSourcesUrl = null;
    this.aFilters = {};
    this.aFilterHTML = {'Category':[],'from':[],'folder':[]};
    this.aFilterParams = ['from','folder'];
    this.oCatLyr = this.oSourcesLyr = this.oCollectionLyr = this.oTray = this.oSumFilter = this.oSourceTextLyr =
    this.oFilterBtnLyr = this.oSourcesBtnLyr = this.oSourceSecLyr = this.oCollectionSecLyr = 
    this.oFilterAlert = this.oFilterChannel = this.oMSFilter = this.oHRFilter = this.oFBComments = null;
    this.aFilterLyrs = {};
    this.bSourcesHTMLInitialized = false;
    this.bAllSourcesInitiazed = false;
    this.bSourcePageCall = false;
    this.bNextPageLoading = false;
    this.bPublicView = false;
    this.sPublicOrder = this.sPublicFilter = null;
    this.bSourceShow = this.bFilterShow = this.bFilterAlertShow = false;
    this.oTimer = null;
    this.sItemIdInAjax = null;
    this.sQuickPostHTML = null;
    this.sAjaxBaseUrl = null;
    this.bQPReset = false;
    this.sBaseUrl = _GL.getBaseUrl();
    this.sDeleteItemUrl = this.sAjaxBaseUrl + 'AjaxServices/MyStuff.asmx/AjaxUserItemsRemoveItem?itemId=<#1#>&channelId=<#2#>&friendGenwiName=<#3#>&listtype=<#4#>';
    this.sImportFeedUrl = _GL.getBaseUrl() + 'importfeeds.aspx';
    this.sSourcesLoader = '<li><img src="images/wire/ajax-loader-white.gif"></li>';
    this.oInfoBubble = null;
    this.bFBCommShow = false;
    
    this.init = function()
    {
        with(this)
        {
           // if (document.domain.has('localhost'))
           //     sABUrl = 'http://' + document.domain + ':' + location.port + '/wire_follow/';
                
            this.sAjaxBaseUrl = typeof sABUrl != 'undefined' ? sABUrl : this.sBaseUrl;
            this.oFilterAlert = new HTMLLayer('filter-alert');
            this.oFilterChannel = new HTMLAnchor('filter-channel');
			this.oFilterLyr = new HTMLLayer('sFilters');
            this.oFilterTextLyr = new HTMLLayer('sFilterBtn');
            this.oFilterBtnLyr = new HTMLLayer('by-filter');
            this.oSourceSecLyr = new HTMLLayer('by-source-source');
            this.oCollectionSecLyr = new HTMLLayer('by-source-collection');
            this.oSumFilter = new HTMLLayer('sumLi');
            this.oMSFilter = new HTMLLayer('msLi');
            this.oHRFilter = new HTMLLayer('hrLi');
            this.oSourceTextLyr = new HTMLLayer('sourceBtn');
            var oFilterBtn = this.oFilterBtnLyr.elem;
            this.oInfoBubble = new infoBubble('infoBubble',200,120);
            this.oFBComments = new HTMLLayer('fbcomments');
            
            if (oFilterBtn)
            {
                oFilterBtn.parent = this;
                /*
                oFilterBtn.onmouseover = function()
                {return;
                    if (!oMyStuff.bSourceShow)
                    {
                        this.parent.oSourcesBtnLyr.setClass('filter-widget');
                        this.className='filter-widget active';  
                    } 
                }
                oFilterBtn.onmouseout = function()
                {
                    if (!oMyStuff.bFilterShow)
                        this.className='filter-widget';
                }
                */
                oFilterBtn.onclick = function(pEvent)
                {
                    if (oAutoSug)
                        oAutoSug.hide();
                   
                    oMyStuff.openFilter(true);
                    oMyStuff.closeSources();
                    var e = pEvent ? pEvent : event;e.cancelBubble = true;
                }
                
                for (var i=0; i<aItemLinkNames.length; i++)
                {
                    var a = aItemLinkNames[i].split(':');
                    var o = oItemLinks[a[0]] = new HTMLAnchor(a[0]), e = o.elem;
                    if (e)
                    {
                        e.order = a[1];
                        e.sBCText = a[2];
                        e.onclick = function()
                        {
                           oMyStuff.hideFilter();
                           oMyStuff.switchItemView(this.id, this.order, this.sBCText);
                           return false;
                        }
                    }
                }
            }
            if(this.oFilterLyr.elem)
                this.oFilterLyr.elem.onclick = function(pEvent){var e = pEvent ? pEvent : event;e.cancelBubble = true;}
            if (typeof(aSidePanels) != 'undefined')
                sSidePanels = aSidePanels;
            var ii = 0;
            for (var i in sSidePanels)
            {
                if (ii == 0)
                    this.sCurSidePanel = i;
                
                ii++;
                
                var oA = _GL.getUIElem(i);
                if (oA)
                {
                    oA.sOrder = sSidePanels[i];
                    oA.onclick = function()
                    {
                        var oMS = oMyStuff, sOrder = this.sOrder, 
                            cLi = _GL.getUIElem(oMyStuff.sCurSidePanel+'_li'), 
                            nLi = _GL.getUIElem(this.id+'_li');
                        if (sPageName.is('follow'))
                        {
                            oMS.setDropDownViews(sOrder);
                            oMS.switchItemView(this.id, sOrder, "Most recent");
                        }
                        else
                        {
                            oMS.sCurFilterOrder = sOrder;
                            oReader.bFilterView = !sOrder.is('new');
                            
                            oMS.setDropDownViews(sOrder);
                            oMS.hideFilter();
                            if (sOrder.is('public'))
                            {
                                oMS.bPublicView = true;
                                oMS.sPublicOrder = 'popular';
                                oReader.refreshPublicView(oMS.sPublicOrder,oMS.sPublicFilter,'1');
                            }
                            else
                            {
                                oMS.bPublicView = false;
                                oMS.sPublicFilter = null;
                                oMS.sPublicOrder = null;
                                var ordName = 'order';
                                if (sPageName.is('follow'))
                                {
                                    ordName = sOrder && sOrder.length>0 ? 'filter' : '';
                                    sOrder = sOrder && sOrder.length>0 ? 'type/all/category/' + sOrder : '';
                                    oReader.bFilterView = false;
                                }
                                oReader.refreshListView(sOrder != 'new' ? [{'name':ordName,'val':sOrder}] : []);
                            }
                        }
                        cLi.className = "";
                        nLi.className = 'active';
                        oMS.sCurSidePanel = this.id;
                        return false;
                    }
                }
            }
            
            // Populate sources and collections.
            /*
            if (sPageName.is('follow'))
            {
                this.aFilterHTML = {'Category':[],'follow':[]};
                this.aFilterParams = ['follow','folder'];
            }
            */
            this.oCatLyr = new HTMLLayer('catUL');
            this.oSourcesLyr = new HTMLLayer('sourceUL');
            this.oCollectionLyr = new HTMLLayer('collectionUL');
            this.oTray = new HTMLLayer('sourcesTray');
            this.oSourcesBtnLyr = new HTMLLayer('by-source');
            var oSourceTab = this.oSourcesBtnLyr.elem;
            
            if (oSourceTab)
            {
                /*
                oSourceTab.onmouseover = function()
                {
                    if (!oMyStuff.bFilterShow)
                    {
                        oMyStuff.oFilterBtnLyr.setClass('filter-widget');
                        this.className = 'filter-widget active';
                    }
                }
                oSourceTab.onmouseout = function()
                {
                    if (!oMyStuff.bSourceShow)
                        this.className = 'filter-widget';
                }
                */
                oSourceTab.onclick = function(pEvent)
                {
                    if (oAutoSug)
                        oAutoSug.hide();
                    oMyStuff.openSources();
                    oMyStuff.openFilter(false);
                    var e = pEvent ? pEvent : event;e.cancelBubble = true;
                }
            }
            if (this.oSourcesLyr.elem)
            {
                this.oSourcesLyr.elem.onscroll = function()
                {
                    with(oMyStuff)
                    {
                        if (!bNextPageLoading && bSourceShow &&
                            (this.scrollTop + this.clientHeight) >= (this.scrollHeight - 20))
                        {
                            bNextPageLoading = true;
                            getSourcesNextPage();
                        }
                    }
                }
            }
            
            if (this.oTray.elem)
                this.oTray.elem.onclick = function(pEvent){var e = pEvent ? pEvent : event;e.cancelBubble = true;}
            
            this.sSourcesUrl = this.sAjaxBaseUrl + 'json/jtabs.aspx?username=<#1#>&tab=<#2#>&page=<#3#>';
            this.aFilterLyrs = {'Category':this.oCatLyr, 'from':this.oSourcesLyr, 'folder':this.oCollectionLyr,'follow':this.oSourcesLyr};
            this.aFilters['Category'] = aFilterData['Category'];
            this.aFilterHTML['Category'][0] = this.getFilterHTML(this.aFilters['Category'],'filter','Category');
            
            var oQP = _GL.getUIElem('quickpost');
            if (oQP)
            {
                oQP.onclick = function()
                {
                    oReader.bNaviDisabled = true;
                    if (!oMyStuff.bQPReset)
                    {
                        this.value = "";
                        oMyStuff.bQPReset = true;
                    }
                }
                oQP.onblur = function()
                {
                    oReader.bNaviDisabled = false;
                }
                
            }
            
            var oKBLink = _GL.getUIElem('kbShortcut');
            if (oKBLink)
            {
                oKBLink.onclick = function(pEvent)
                {
                    oMyStuff.oInfoBubble.showInfo(sKBDetails,pEvent);
                    return false;
                }
            }
            
            var oIELink = _GL.getUIElem('inviteByEmail');
	        if (oIELink)
	        {
	            oIELink.onclick = function()
	            {
    	            
	                var u = oMyStuff.sBaseUrl+'people/cimporter.aspx';

                    if (!oOverlay)
                        oOverlay = new OverlayPopup('mb-overlay', '500', '500', true, u, 'mb');
                    else
                        oOverlay.sUrl = u;
                    
                    oOverlay.display();
                    return false;
    	            
	            }
	        }
            
            this.oTimer = setTimeout('oMyStuff.getSources()',2000);
        }
    }
    
    this.hideDD = function()
    {
        if (this.bSourceShow)
            this.closeSources();
        
        if (this.bFilterShow)
            this.openFilter(false);
    }
     
    this.switchItemView = function(pId, pOrder, pBCText)
    {
        var a = this.oItemLinks;
        oReader.bFilterView = !pOrder.is('new');
        this.sCurFilterView = pId;
        this.sCurFilterOrder = pOrder;
        this.openFilter(false);
        this.setFilterText(pBCText);
        if (this.bFBCommShow)
        {
            oReader.oItemsArea.show(true);
            this.oFBComments.show(false);
            this.bFBCommShow = false;
        }
        if (this.bPublicView)
        {
            this.sPublicOrder = pOrder;
            oReader.refreshPublicView(pOrder,this.sPublicFilter,'1');
        }
        else
        {
            if (pOrder.is('discuss'))
            {
                this.setDropDownViews(pOrder);
                this.hideFilter();
                this.showFaceBookComments();
            }
            else
                oReader.refreshListView(pOrder != 'new' ? [{'name':'order','val':pOrder}] : []);
        }
    }
    
    this.openSources = function()
    {
        var oMS = this, oSourceTab = oMS.oSourcesBtnLyr.elem;;
        if (!oMS.bAllSourcesInitiazed)
        {
            var bFollowPage = sPageName.is('follow')
                sSouHtml = !bFollowPage ? oMS.aFilterHTML['from'][0] : oMS.aFilterHTML['follow'][0],
                oColHtml = !bFollowPage ? oMS.aFilterHTML['folder'][0] : null;
            oSourceTab.className = 'filter-widget active';
            
            oMS.oTray.show(true);
            
            oMS.oSourcesLyr.elem.scrollTop = 0;
            
            oMS.oCatLyr.setValue(oMS.aFilterHTML['Category'][0]);
            
            oMS.oSourcesLyr.setValue(sSouHtml ? sSouHtml : oMyStuff.sSourcesLoader);
            oMS.oCollectionLyr.setValue(oColHtml ? oColHtml : oMyStuff.sSourcesLoader);
        }
        if (oMS.bAllSourcesInitiazed)
        {
            oSourceTab.className = 'filter-widget active';
            oMS.showSources();
        }
        else if (oReader.bPageLoaded)
        {
            clearTimeout(oMS.oTimer);
            oMS.getSources();
        }
        this.bSourceShow = true;
    }
    
    this.closeSources = function()
    {
        this.oSourcesBtnLyr.setClass('filter-widget');
        this.oTray.show(false);
        this.bSourceShow = false;
    }
    
    this.openFilter = function(pShow)
    {
        var b = pShow, oFB = this.oFilterBtnLyr;
        if (b)
            this.setFilterPosition();
        
        oFB.setClass(b ? 'filter-widget active' : 'filter-widget');
        this.oFilterLyr.show(b);
        this.bFilterShow = b;
    }
    
    this.setFilterPosition = function()
    {
        if(this.oFilterLyr.elem)
        {
            var aByFilterDims = _GL.getOffsetLT('by-filter'), 
                aContentDims = _GL.getOffsetLT('content');
            this.oFilterLyr.elem.style.left = (aByFilterDims[0] - aContentDims[0]) + 'px';
        }
    }
    
    this.setFilterText = function(pTxt)
    {
        this.oFilterTextLyr.setValue('<strong>Filter: </strong>'+pTxt);
    }
    
    this.setSourceBtnText = function(pTxt)
    {
        this.oSourceTextLyr.setValue(pTxt);
    } 
    
    this.updateFilterAlert = function(pCid, pTitle, pFilter, pPageId,pItemId)
    {
        var oFC = this.oFilterChannel, oFCE = oFC.elem;
        oFC.setText(pTitle);
        oFCE.href = "channel/"+pCid;
        this.oFilterAlert.show(true);
        this.bFilterAlertShow = true;
       
        var oUnsubSec = _GL.getUIElem('unsubSec');
        
        if (oUnsubSec)
        {
            var s = "";
            if (pFilter.toLowerCase().is('collection') && pItemId)
                s = '[<a id="delCollection" href="#" onclick="this.className=\'\';this.style.marginRight=\'30px\';oMyStuff.deleteCollection(\''+pCid+'\',\''+pPageId+'\',\''+pItemId+'\');return false;">Delete Collection</a><a href="#" onclick="oMyStuff.editCollection(\''+pPageId+'\');return false;">Edit Collection</a>]';
            else if (pFilter.toLowerCase().is('source') && !this.bPublicView && !sPageName.is('follow'))
                s = '[<a id="unsubChannel" href="#" onclick="oReader.unsubscribeChannel(\''+pCid+'\');return false;">Delete Source</a>]';
            oUnsubSec.innerHTML = s;   
        }
        
        oReader.setMainLayerDims();
    }
    
    this.removeFilterAlert = function()
    {
        this.hideFilter();
        if (sPageName.is('mywire'))
        {
            var oA = !this.bPublicView ? _GL.getUIElem('panelAll') : _GL.getUIElem('publicWire');
		    if (oA)
		        oA.onclick();
		}
		else if (sPageName.is('items') || sPageName.is('follow'))
		{
		    var e = sPageName.is('items') ? 'panelAll' : 'allItemsLink';
		    var oAll = _GL.getUIElem(e);
		    if (oAll)
		        oAll.onclick();
		}
    }
    
    this.hideFilter = function()
    {
        this.oFilterAlert.show(false);
        this.bFilterAlertShow = false;
        oReader.setMainLayerDims();
    }
    
    this.getFilterView = function(pId, pTitle, pName, pParam)
    {
        with(this)
        {
            var sBCTitle = pTitle;
            if (pName == 'From')
                sBCTitle += sUnsubscribeChannel.replaceTokens(pId);
                 
            if (pName != 'Category' && pName != 'SubCategory' )
                oReader.bFilterView = false;
            else
                oReader.sFilterItem = pTitle;
            
            aLvlBCs.lvl1 = oReader.bFilterView ? '<a href="#" onclick="oMyStuff.switchItemView(\'' + sCurFilterView + '\',\'' + sCurFilterOrder + '\');return false;">' + sBCText + '</a>' : sBCTitle;
            aLvlBCs.lvl2 = oReader.bFilterView ? sBCTitle : null;
            
            var bDateDD = pName.is('Date');
            
            if (!bDateDD)
                updateBrearCrumb();
            
            if (bDateDD)
                oReader.setDateText(pTitle);
                
            oReader.refreshListView([{'name':pParam,'val':pId}]);
        }
    }
    
    this.setDropDownViews = function(pOrder)
    {
        this.setSourceBtnText('<strong>Source:</strong>&nbsp;Everything');
        this.oMSFilter.show(false);
        this.oHRFilter.show(true);
        this.oSumFilter.show(true);
        switch (pOrder)
        {
            case "-1":
            case "snap":
                this.oFilterBtnLyr.show(true,true);
                this.oSourcesBtnLyr.show(true,true);
                this.setFilterText('Summary');
                break;
            case "public":
                this.oFilterBtnLyr.show(true,true);
                this.oSourcesBtnLyr.show(true,true);
                this.oSumFilter.show(false);
                this.oMSFilter.show(true);
                this.oHRFilter.show(false);
                this.setSourceBtnText('<strong>Category:</strong>&nbsp;All');
                this.setFilterText('Most Popular');
                break;
            case "shared":
                this.oFilterBtnLyr.show(false,true);
                this.oSourcesBtnLyr.show(true,true);
                this.setSourceBtnText('<strong>Category:</strong>&nbsp;All');
                break;
            case "quick":
            case "discuss":
            case "favs":
                this.oFilterBtnLyr.show(false, true);
                this.oSourcesBtnLyr.show(false, true);
                break;
        }
        
        this.setFilterPosition();       
    }
    
    this.showSources = function()
    {
        this.initSourcesHTML();
        this.oTray.show(true);
        this.oSourcesLyr.elem.scrollTop = 0;
        this.setTray();
    }
    
    this.setTray = function()
    {
        switch(this.sCurFilterOrder)
        {
            case "-1":
            case "snap":
                this.oSourceSecLyr.show(true);
                this.oCollectionSecLyr.show(true);
                break;
            case "public":
            case "shared":
            case "favs":
                this.oSourceSecLyr.show(false);
                this.oCollectionSecLyr.show(false);
                break;
        }
    }
    
    this.initSourcesHTML = function()
    {
        if (!this.bSourcesHTMLInitialized)
        {
            this.oCatLyr.setValue(this.aFilterHTML['Category'][0]);
            if (sPageName.is('mywire'))
            {
                this.oSourcesLyr.setValue(this.aFilterHTML['from'][0] );
                this.oCollectionLyr.setValue(this.aFilterHTML['folder'][0]);
            }
            this.bSourcesHTMLInitialized = true;
        }
    }
    
    this.getFilterHTML = function(pData, pParam,pFilter)
    {
        var oD = pData, len = oD.length, s = '';
        for (var i=0;i<len;i++)
        {
            var sTitle = oD[i].title.cleanLineBreaks(), t = sTitle;
            if (t.length >= 20)
                t = t.substr(0,20) + '...';
            s += '<li onmouseover="this.className=\'active\'" onmouseout="this.className=\'\'">';
            s += '<a href="#" onclick="oMyStuff.refreshListView(\''+pParam+'\',\''+oD[i].id+'\',\''+pFilter+'\',\''+t.escapeSingleQuote()+'\',\''+sTitle.escapeSingleQuote()+'\',\''+oD[i].pageid+'\',\''+oD[i].itemid+'\');return false;" title="'+oD[i].title+'">'+t+'</a>';
            s += '</li>';
        }
        return s;
    }
    
    this.refreshListView = function(pParam,pVal,pFilter,pTitle,pFullTitle,pPageId,pItemId)
    {
        this.closeSources();
        this.setSourceBtnText('<strong>'+pFilter+':</strong>&nbsp;'+pTitle);
        if (pFilter.toLowerCase().hasAny('collection','source'))
            this.updateFilterAlert(pVal,pFullTitle,pFilter,pPageId,pItemId);
        else
            this.hideFilter();
        
        if (this.bPublicView)
        {
            this.sPublicFilter = pVal;
            oReader.refreshPublicView(this.sPublicOrder,this.sPublicFilter,'1');
        }
        else
        {
            this.sPublicFilter = null;
            oReader.refreshListView([{'name':pParam,'val':pVal}]);
        }
    }
    
    this.getSources = function()
    {
        if (oReader.bPageLoaded)
        {
            if (sPageName.is('items'))
            {
                this.bAllSourcesInitiazed = true;
                return;
            }
                
            var bFound = false;
            for (var i=0; i<this.aFilterParams.length; i++)
            {
                var sFilter = this.aFilterParams[i];
                if (!this.aFilters[sFilter])
                {
                    this.sReqFilter = sFilter;
                    oMyStuff.requestSources(1);
                    bFound = true;
                    break;
                }
            }
            if (!bFound)
            {
                this.sReqFilter = null;
                this.bAllSourcesInitiazed = true;
            }
        }
        else
            this.oTimer = setTimeout('oMyStuff.getSources()',1000);
    }
    
    this.getSourcesNextPage = function()
    {
        var aF = this.aFilters['from'], tp = aF.sTotalPages, cp = aF.iCurPage;
       
        if (cp >= tp)
            return;
        
        aF.iCurPage = ++cp;
        this.sReqFilter = 'from';
        this.bSourcePageCall = true;
        this.requestSources(aF.iCurPage);
    }
    
    this.getFolderItems = function(pId, pPageId, pFav,pItemId,pFavName)
    {
        var cLi = _GL.getUIElem(this.sCurSidePanel+'_li');
        if (cLi)
            cLi.className = "";
        var nLiPrefix = pFav ? pFav : 'cl'+pId, nLi = _GL.getUIElem(nLiPrefix+'_li');
        this.sCurSidePanel = nLiPrefix;
        nLi.className = 'active';
        this.updateFilterAlert(pId,pFavName,'collection',pPageId,pItemId);
        oReader.refreshListView([{'name':'channelid','val':pId+''}]);
    }
    
    this.editCollection = function(pPageId)
    {
        var sUrl = _GL.getBaseUrl() + 'addpage.aspx?subpage=edit&pageid='+pPageId;
        
        if (!oOverlay)
            oOverlay = new OverlayPopup('mb-overlay', '500', '400', true,sUrl, 'mb');
        else
            oOverlay.sUrl = sUrl;
        
        oOverlay.display();
        return;
    
    }
    
    this.deleteCollection = function(pChannelId, pPageId, pItemId)
    {
        var sUrl = oMyStuff.sAjaxBaseUrl + 'AjaxServices/MyStuff.asmx/AjaxUserFeedRemoveFeed?ItemID='+pItemId+'&ChannelID='+pChannelId+'&PageID='+pPageId+'&subType=2';
        var oAjax = new Ajax('delCollection',sUrl, true, ['oMyStuff.processDelCollection']);
        oAjax.iResponseType = oAjax.RESPONSE_HTML;
        oAjax.sShowProgressId = 'delCollection';
        oAjax.bShowProgress = true;
        oAjax.send();
    }
    
    this.processDelCollection = function(pResp)
    {
        _GL.redirect(location.href);
    }
    
    this.requestSources = function(pPage, pListner)
    {
        clearTimeout(this.oTimer);
        var url = this.sSourcesUrl.replaceTokens(oReader.sUserName,this.sReqFilter, pPage),
            sListner = typeof(pListner) != 'undefined' ? 'oMyStuff.'+pListner : 'oMyStuff.processSources';
        var oAjax = new Ajax('fiterDataReq',(url + '&rd=' + _GL.getRandomNumber()), true, 
                             [sListner]);
        oAjax.iResponseType = oAjax.RESPONSE_JSON;
        oAjax.send();
    }
    
    this.processSources = function(pResp)
    {
        if (pResp.oJSON)
        {
            if (!pResp.oJSON)
                return;
            var oD = pResp.oJSON, oFeeds = oD.feeds, sRF = this.sReqFilter;
            this.aFilters[sRF] = oFeeds;
            
            if (oD.totalpages > 1)
            {
                this.aFilters[sRF].bPages = true;
                this.aFilters[sRF].sTotalPages = oD.totalpages;
                this.aFilters[sRF].iCurPage = oD.curpage;
            }
            
            var s = this.getFilterHTML(oFeeds,'channelid',sRF.is('from')?'Source':'Collection');
            var v = this.aFilterHTML[sRF][0];
            this.aFilterHTML[sRF][0] = v && v.length > 0 ? v + s : s;
             
            try
            {
                this.aFilterLyrs[sRF].setValue(this.aFilterHTML[sRF][0]);
            }
            catch(e)
            { /****/}
            
            this.bSourcePageCall = false;
            
            if (!this.bAllSourcesInitiazed)
                this.oTimer = setTimeout('oMyStuff.getSources()',1000);
            else
                this.oTimer = setTimeout('oMyStuff.setNextSourcePageLoading()',1000);
        }
    }
    
    this.setNextSourcePageLoading = function()
    {
        var sRF = 'from';
        this.aFilterLyrs[sRF].elem.scrollTop =  this.aFilterLyrs[sRF].elem.scrollTop - 50;
        this.bNextPageLoading=false;
    }
    
    this.deleteItem = function(pId,pFldId,pShId)
    {
        this.sItemIdInAjax = pId;
        oReader.bItemClickOff = true;
        var fldId = pFldId, shid = fldId ? null : pShId, listType = fldId ? null : shid ? 'share' : 'sent';
        
        var sUrl = this.sDeleteItemUrl.replaceTokens(pId,fldId,shid,listType);
        var oAjax = new Ajax('delItem', sUrl, true,  ['oMyStuff.processDelItem']);
        oAjax.iResponseType = oAjax.RESPONSE_HTML;
        oAjax.bShowProgress = true;
        oAjax.sShowProgressId = 'itemRem_'+pId;
        oAjax.send();
    }
    
    this.processDelItem = function(presp)
    {
        var itemId = this.sItemIdInAjax, oRow = _GL.getUIElem('rowouter_'+itemId);
        if (oRow)
        {
            var e = oRow, prt = e.parentNode ? e.parentNode : e.parentElement;
            prt.removeChild(e);
        }
        oReader.bItemClickOff = false;
    }
    
    this.importFeeds = function()
    {
        if (!oOverlay)
            oOverlay = new OverlayPopup('mb-overlay', '500', '200', true, this.sImportFeedUrl, 'mb');
        else
            oOverlay.sUrl = this.sImportFeedUrl;
        
        oOverlay.display();
        return;
    }
    
    this.createNewCollection = function()
    {
        var u = oReader.sBaseUrl+'addpage.aspx?addtopage=new&itemId=';
        
        if (!oOverlay)
            oOverlay = new OverlayPopup('mb-overlay', '500', '400', true, u, 'mb');
        else
            oOverlay.sUrl = u + this.sItemId;
        
        oOverlay.display();
        return;
    }
    
    this.quickPost = function()
    {
        var oQPSpan = _GL.getUIElem('btnSpan_qp'), oFrm, oQPTxt;
        this.sQuickPostHTML = oQPSpan.innerHTML;
        
        oFrm = document.forms['quick-post'];
        if (oFrm)
        {
            oQPTxt = oFrm.elements['quickpost'];
            if (oQPTxt)
            {
                var v = oQPTxt.value;
                if (v && v.length > 0)
                {
                    var u = oMyStuff.sAjaxBaseUrl + 'json/jupdate.aspx?action=add&content='+v;
                    var oAjax = new Ajax('quickPost', u, true,  ['oMyStuff.processQuickPost']);
                    oAjax.iResponseType = oAjax.RESPONSE_HTML;
                    oAjax.bShowProgress = true;
                    oAjax.sShowProgressId = 'btnSpan_qp';
                    oAjax.send();
                }
            }
        }
    }
    
    this.processQuickPost = function(pResp)
    {
        var oQPSpan = _GL.getUIElem('btnSpan_qp'), oFrm, oQPTxt;
        oQPSpan.innerHTML = this.sQuickPostHTML;
        document.forms['quick-post'].elements['quickpost'].value = "";
    }
    
    this.showFaceBookComments = function()
    {
        if (this.oFBComments && this.oFBComments.elem)
        {
            oReader.initReaderState();
            this.oFBComments.elem.style.height = oReader.oItemsArea.elem.offsetHeight + 'px';
            oReader.oItemsArea.show(false);
            this.oFBComments.show(true);
            this.bFBCommShow = true;
            return false;
        }
    }
}

var oMyStuff = new MyStuff();
var sPageNameName = 'myweb';
//_GL.addOnLoadListener(oMyStuff.init);

window.onload = function()
{
    if (typeof aFilterData == 'undefined')
        return;
        
    oMyStuff.init();
    if (oReader)
        oReader.init();

}
