/*
 * relInfoControllerI[mages]
*/

function RelInfoControllerI() {
    this._relInfoBase;
    this._infoBase;
    this._titlePattern = document.title;
    document.title = this._titlePattern.replace("{OperationValue}", "").replace("{OperationTitle}", "");
    this._op;
}

RelInfoControllerI.prototype = {

    initializeController: function(relInfoBase, infoBase) {
        this._relInfoBase = $(relInfoBase);
        this._infoBase = $(infoBase);

        this._op = window.location.hash;

        if (!this._op) this._op = "#";

        if (this._op.charAt(0) == "#") this._op = this._op.substring(1);

        if (this._op == "overview") this._op = "";
    },

    clear: function() {
        this._infoBase.find("div.relinfo").hide();

        this._relInfoBase.find("li a").removeClass("rel_active");
        this._relInfoBase.find("li").removeClass("active");         

        this._relInfoBase.find("li a img").map(function() {
            $(this).attr("imageOff", $(this).attr("imageWayOff")).attr("src", $(this).attr("imageWayOff"));
        });
    },

    getOperation: function() { return this._op; },

    turnOn: function(controller, op, title, rootOp) {
        this.clear();

        document.title = this._titlePattern.replace("{OperationValue}", title).replace("{OperationTitle}", title);

        if (rootOp) {
            this._relInfoBase.find("li.operation_" + rootOp + " div.navitem a").find("img").map(function() {
                $(this).attr("imageOff", $(this).attr("imageOn")).attr("src", $(this).attr("imageOn"));
            });
            this._relInfoBase.find("li.operation_" + op + " a").addClass("rel_active");
        } else {
            this._relInfoBase.find("li.operation_" + op + " a").find("img").map(function() {
                $(this).attr("imageOff", $(this).attr("imageOn")).attr("src", $(this).attr("imageOn"));
            });
        }

        this._relInfoBase.find("li.operation_" + op).addClass("active");    
        this._relInfoBase.find("li.operation_" + rootOp).addClass("active");  
        
        this._infoBase.find("div.relinfo.op_" + op).show();

        // fixing internal links
        this._infoBase.find("div.relinfo.op_" + op).find("div.paginator a").map(function() {
            if (this.href.indexOf("#") < 0) this.href = this.href + '#' + op;
        });

        this._infoBase.find("div.relinfo.op_" + op).find("a.hashaware").map(function() {
            if (this.href.indexOf("#") < 0) this.href = this.href + '#' + op;
        });
    },

    initialize: function(controller, op, title, rootOp) {
        this._relInfoBase.find("li.operation_" + op + " a").click(function() {
            controller.turnOn(controller, op, title, rootOp);
        });
    }
}

