/*jslint browser: true, cap: false, passfail: false, undef: false, white: false */
/*global SONGHAY YAHOO */

(function(){

    //Module-level members:
    var index = SONGHAY.ui.Index;

    SONGHAY.ui.MegaFunk =
    {
        buildDisplay:function()
        {
            //TODO: Build any server exceptions:
            //if(*.displayBuilder.forServerMessage()) { return; }

            //The functional/querying/composeable builders sorted by name:
            self.displayBuilder.forMegaBabble();
            self.displayBuilder.forMegaBrowserCarousel();
            self.displayBuilder.forMegaBrowserDisplayArea();
            self.displayBuilder.forMegaGalleryList();
            self.displayBuilder.forMegaHeader();
        },

        handleCarouselCommandLink:function(e)
        {
            if(e) { 
                YAHOO.util.Event.preventDefault(e);
            }
            var o = (e) ? YAHOO.util.Event.getTarget(e) : null;
            var imageFrame = YAHOO.util.Dom.get('MegaImage');
            if(o && o.src && imageFrame && imageFrame.src)
            {
                imageFrame.src = o.src.replace(index.settings.MegaBrowserThumbsPath.value.replace('./',''),
                    index.settings.MegaBrowserImagesPath.value.replace('./',''))
            }
        },

        handleMegaGalleryLink:function(e)
        {
            if(e) { 
                YAHOO.util.Event.preventDefault(e);
            }
            var o = (e) ? YAHOO.util.Event.getTarget(e) : null;
            if(o)
            {
                index.ajax.display(null,
                {
                    serverCommand:'browse',
                    targetId:'MegaBrowserDisplayArea',
                    uriCase:'gallery,' + o.id
                });
            }
        },

        splashAndRedirect:function()
        {
            window.setTimeout(function()
            {
                if((window.location.href == index.settings.MegaBrowserRoot.value) &&
                (document.referrer.indexOf(index.settings.MegaBrowserRoot.value) == -1))
                { window.location.href = './browse'; }
            }, 2000);
        }
    };

    //Module-level "self":
    var self = SONGHAY.ui.MegaFunk;

})();
