if (typeof Ferengi == "undefined") {
    var Ferengi = {
        Version: "1.0"
    };
    Ferengi.namespace = function() {
        var a = arguments,
			o = null,
			i, j, d;
        for (i = 0; i < a.length; ++i) {
            d = a[i].split(".");
            o = Ferengi;
            for (j = (d[0] == "Ferengi") ? 1 : 0; j < d.length; ++j) {
                o[d[j]] = o[d[j]] || {};
                o = o[d[j]];
            }
        }
        return o;
    };
};
Ferengi.namespace("Pxp");
// Creating a class
Ferengi.Pxp.GetProperty = new Class({
    Implements: Options,
    options: {
        Id: ""
    },
    initialize: function(options) {
        this.setOptions(options);
        // initialize commands goes here
    }

});
Ferengi.Pxp.GetProperty.implement({

    load: function(o) {
    if (o.getAttribute('SlbfLoad')) {
            var SlbfObject = o.getAttribute('SlbfLoad')
            var arrSlbfObject = SlbfObject.split('|')
            var ObjectType = "";
            var ObjectId = "";
            var Property = "";
            if (arrSlbfObject.length == 2) {
                //Context
                ObjectType = arrSlbfObject[0];
                Property = arrSlbfObject[1];
            } else if (arrSlbfObject.length == 3) {
                //Object
                ObjectType = arrSlbfObject[0];
                ObjectId = arrSlbfObject[1];
                Property = arrSlbfObject[2];
            } else {
                //error
                return;
            }

            this._currentElement = o;
            this.getProperty(ObjectType, ObjectId, Property, function(html) {
                var el = $(this.CurrentElement);
                el.set('html', html);
            })
        }

    }
    , getProperty: function(ObjectType, ObjectId, Property, successFunction) {

        var Params = "";
        var rx = /(?:[?&]id=|Seccion-)(\d+)/i;
        var url = location.href;
        var SectionId = 0;
        var match = rx.exec(url);
        if (match != null) {
            SectionId = match[1];
        }
        if (ObjectId == null || typeof (ObjectId) == 'undefined' || ObjectId == "") {
            //Context
            Params = "ObjectType=" + ObjectType + "&Property=" + Property + "&SectionId=" + SectionId;
        } else if (arrSlbfObject.length == 3) {
            //Object
            Params = "ObjectType=" + ObjectType + "&ObjectId=" + ObjectId + "&Property=" + Property + "&SectionId=" + SectionId;
        } else {
            //error
            return;
        }
        
        var Hash = Math.ceil(Math.random() * 100000000000);

        var url = '/GetProperty.ashx?' + Params + "&h=" + Hash;
        var myAjaxFeed = new Request({
            url: url,
            method: 'get',
            onSuccess: successFunction,
            evalScripts: false
        });
        myAjaxFeed.CurrentElement = this._currentElement;
        myAjaxFeed.send();
    }
});


window.addEvent("domready", function() {
    var oo = $$('.SlbfLoad');
    for (var i = 0; i < oo.length; i++) {
        var o = oo[i];

        var gp = new Ferengi.Pxp.GetProperty();
        gp.load(o);
    }
});


