/**
 * Resource      Elsevier.CacheSet.CP.2010
 * Source        Local
 **/


    
    /**
    * Elsevier Commercial Sales Magazines
    * Public
    * cp
    *
    * @requires YAHOO
    * @namespace cp
    * @version 1
    */

    if (typeof cp == 'undefined') {
        var cp = {};
    }

    cp.namespace = function() {
        var a = arguments, e = null, c, b, d;
        for (c = 0; c < a.length; c++) {
            d = a[c].split('.'); e = cp;
            for (b = (d[0] == 'cp') ? 1 : 0; b < d.length; b++) {
                e[d[b]] = e[d[b]] || {}; e = e[d[b]]
            }
        }
        return e;
    };
    
    /**
    * Elsevier Commercial Sales Magazines
    * Public
    * Ajax
    *
    * @requires /cp/cp.js
    * @namespace cp.ajax
    * @version 1
    */

    cp.namespace('ajax');

    cp.ajax = {
        _createTransport: function() {
            if (typeof XMLHttpRequest != "undefined") {
                return new XMLHttpRequest();
            }
            else if (typeof ActiveXObject != "undefined") {
                var http = null;
                try {
                    http = new ActiveXObject("MSXML2.XmlHttp.6.0");
                    return http;
                }
                catch (ex) {
                    try {
                        http = new ActiveXObject("MSXML2.XmlHttp.3.0");
                        return http;
                    }
                    catch (ex2) {
                        throw Error("Cannot create XHR object");
                    }
                }
            }
        },

        post: function(object) {
            var _ajport = this._createTransport();
            _ajport.open('GET', object.url, true);
            _ajport.onreadystatechange = function() {
                if (_ajport.readyState == 4) {
                    if (_ajport.status == 200) {
                        object.success(_ajport);
                    }
                    else {
                        //alert(_ajport.status);
                    }
                }
            }
            _ajport.send(null);
        }
    };

    /**
    * Elsevier Commercial Sales Magazines
    * Public
    * Ad rotator
    *
    * @requires /cp/cp.js;/cp/cp.ajax.js
    * @namespace cp.articles
    * @version 1
    */

    cp.namespace('cp.advertising');

    cp.advertising = {
        useFullPath: false,
        rotateAdvert: function(iframe, areaId, categoryId) {
            var optionalParamaters = arguments[3];
            var iframesrc = '/content/advert/advert.aspx?AreaId=' + areaId;

            if (categoryId != '0')
                iframesrc = iframesrc + '&CategoryId=' + categoryId;
            if (optionalParamaters != null)
                iframesrc = iframesrc + '&' + optionalParamaters;

            if (parent.window['ref_finance'] == 'true') {
                this.useFullPath = true;
            }

            if (this.useFullPath) {
                iframesrc = 'http://www.renewableenergyfocus.com' + iframesrc;
            }

            $(iframe).src = iframesrc;

            var timeout = setTimeout("cp.advertising.rotateAdvert('" + iframe + "', " + areaId + ", " + categoryId + ", " + optionalParamaters + ");", 20000);
        }
    };

