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

(function(){

    SONGHAY.ui.Client =
    {
        ajax:SONGHAY.ui.Ajax,
        application:null,
        applicationName:'Index',
        applicationTitle:'SonghaySystem()',
        appSettings:null,
        baseUri:'./',
        color:'',

        getUri:function()
        {
            var vResourceName = (arguments.length > 0) ? arguments[0] : '';
            var vUriPart = (arguments.length > 1) ? arguments[1] : '';

            switch(vResourceName)
            {
                case 'amazon_xml_http':
                    vUriPart = 'rest/amazon/asin/' + vUriPart + '/salt/' + new Date().getTime();
                break;

                case 'xml_http':
                    vUriPart = 'rest/' + vUriPart + '/salt/' + new Date().getTime();
                break;

            }

            var vUri = self.baseUri + vUriPart;

            return vUri;
        },

        initialize:function()
        {
            //Get a reference to the Client Application (on window.load):
            self.application = self.ui[self.applicationName];

            //Plug this Client into Ajax:
            self.ajax.client = self;

            if(self.root.canEnhance())
            {
                var o = null;

                //Load Application settings from Client:
                if(self.dataForm.loadAppSettings())
                {
                    o = self.appSettings.RootUri;
                    if(o) { self.baseUri = o.value; }
                }

                self.application.buildDisplay();

                //Format Amazon Stuff:
                self.application.ajaxAmazon();
            }
        },

        mouseOutLink:function(e)
        {
            var oSrcElement = YAHOO.util.Event.getTarget(e);
            var o = oSrcElement.style;

            if(oSrcElement.tagName.toLowerCase() == 'a')
            {
                if(o)
                {
                    o.color = self.color;
                    o.backgroundColor = 'transparent';
                }
            }
        },

        mouseOverLink:function(e)
        {
            var oSrcElement = YAHOO.util.Event.getTarget(e);
            var o = oSrcElement.style;

            if(oSrcElement.tagName.toLowerCase() == 'a')
            {
                if(o)
                {
                    self.color = o.color;
                    o.color = '#ffffff';
                    o.backgroundColor = '#c7c7c7';
                }
            }
        },

        /**
         * The root container of this Client.
         * @property root
         * @type object
         */
        root:SONGHAY,

        /**
         * The user interface branch of the root container.
         * @property ui
         * @type object
         */
        ui:SONGHAY.ui
    };

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

    YAHOO.util.Event.addListener(window, 'load', self.initialize);

})();
