var WCDLibrary = Class.create();

WCDLibrary.prototype = {

    initialize: function() {


    },

    /**    * getAssetPath - gets the path to an asset dynamically, based on the content group number and brand    * This is a method of class WCDLib    * @param {string} contentID = 1234567    * @param {string} asset OPTIONAL i.e. someImage.jpg    * @return (string) assetPath i.e. /Asset_Archive/ONWeb/content/0001/234/567/assets/someImage.jpg    * @author Jermaine Jackson    * @date 08/27/2009    */
    getAssetPath: function(contentID, asset) {

        asset = asset && asset != '' ? asset : '';

        var contentPath = "000" + contentID.substr(0, 1) + "/" + contentID.substr(1, 3) + "/" + contentID.substr(4, 3);
        var assetPath = "/Asset_Archive/" + brandConst.BRAND_ID + "Web/content/" + contentPath + "/assets/" + asset;

        return assetPath;
    },


    /**    * getMlink - changes browser url to a new url with Omniture tracking appended. *Omniture tracking should be sorted by mlink    * This is a method of class WCDLib    * @param {string} baseURL = /browse/category.do?cid=12345    * @param {string} cid = (content Group # used for tracking and clink) i.e. 1234567    * @param {string} label OPTIONAL = additional label used in mlink for tracking    * @return (string) mlink    * @author Jermaine Jackson    * @date 08/27/2009    */
    getMlink: function() {
        var mlink;
        if (reportingService) {
            mlink = reportingService.controller.viewManagers.commonViewManager.model.commonCurrentBusinessId;
        }
        else {
            mlink = false;
        }
        return mlink;
    },


    /**    * goToTrackingURL - changes browser url to a new url with Omniture tracking appended    * This is a method of class WCDLib    * @param {string} baseURL = /browse/category.do?cid=12345    * @param {string} contentID = (content Group # used for tracking and clink) i.e. 1234567    * @param {string} label OPTIONAL = additional label used in mlink for tracking    * @return - returns nothing (changes browser location)    * @author Jermaine Jackson    * @date 09/22/2009    */
    /** NOT TESTED YET **/
    goToTrackingURL: function(baseURL, contentID, label) {

        thisMlink = this.getMlink();
        label = label && label != '' ? ',' + label : '';
        //var trackingURL = location.protocol + '//' + location.host + baseURL + '&mlink=' + thisMlink + ',' + contentID + label + '&clink=' + contentID;
        //location.href = 'http://oldnavy.gap.com/browse/category.do?cid=00000&mlink=5421,1234567&clink=1234567';
    },


    /**
    * isProuctSalable() - makes ajax request to check if product is salable
    * @param {string} baseURL = /browse/category.do?cid=12345
    * returns true or false;
    * ??? Returns "failed" onFailure (if request was not successful for some reason)
    * @author Jermaine Jackson    * @date 09/22/2009
    */
    isProductSalable: function(thisPID) {
        new Ajax.Request('/browse/isProductSalable.do?pid=' + thisPID, {
            method: 'get',
            onSuccess: function(transport) {
                var response = transport.responseText.strip();
                if (response.indexOf('true') >= 0) {
                    retVal = true;
                }
                else {
                    retVal = false;
                }
            },
            onFailure: function() {
                //request failed
                retVal = "failed";

            }
        });

        return retVal;
    },

    /**
    * addProductToBag() - adds product to shopping bag    * This is a method of class WCDLib    * @param {string} thisSKU = sku number to add    * @param {string} thisCID = cid of sku's product page    * @return - returns nothing (changes browser location)    * @author Jermaine Jackson    * @date 09/22/2009    */
    addProductToBag: function(thisSKU, thisCID) {

        var thisHost = location.protocol + '//' + location.host;
        var requestURL = thisHost + '/buy/inlineShoppingBagAdd.do?skuid='
                         + thisSKU
                         + '&quantity'
                         + thisSKU
                         + '=1&sfl'
                         + thisSKU
                         + '=false&cid'
                         + thisSKU
                         + '='
                         + thisCID;

        new Ajax.Request(
            requestURL,
             {
                 method: 'get',
                 onComplete: quickLook.parseInlineBagAjaxResonse
             }
        )


    }

};

var wcdLib = new WCDLibrary();