/*
    CruiseHolidays.Web.UI

    Navigator class is used to dynamically render breadcrumbs in the Navigator box.
*/

function Navigator(container) {
    this.container = container; //where to output breabcrumbs
    this.contextType = 0;
    this.contextId = 0;
    this.customContextItems = null;
    this.customContextItemLabels = null;
    
    this._contextTypes = new Array("", "", "Region", "Port", "Cruise", "Ship");
    this._contextIds = new Array(null, null, 0, 0, 0, 0);
    this._contextPages = new Array("/", null, "/?ContextId={0}", "/Port.aspx?ContextId={0}", "/Cruise.aspx?ContextId={0}", "/Ship.aspx?ContextId={0}");
    this._contextTypeLabels = new Array("Home", "Where", "Region", "City / Port", "Cruise", "Ship");
    
    this.setContext = function(contextType, contextId) {
        this.contextType = contextType;
        this.contextId = contextId;
        if (contextType!="") {
            for (var i=1; i<this._contextTypes.length; i++) {
                if (this._contextTypes[i]==contextType) {
                    this._contextIds[i] = contextId;
                    break;
                }
            }
        }
        this.render();
    }
    
    this.setCustomContextItems = function(items, labels) {
        this.customContextItems = items;
        if (labels)
            this.customContextItemLabels = labels;
        else
            this.customContextItemLabels = items;
        this.render();
    }
    
    this.render = function(container) {
        return; //DEBUG
        
        if (!container)
            container = this.container;
        
        if (!container)
            return;
        
        var output = "<ul><li><a href=\"/\">"+this._contextTypeLabels[0]+"</a>";
        if (this.contextType!="") {
            for (var i=1; i<this._contextTypes.length; i++) {
                output += "<ul><li>";
                if (this._contextPages[i]) {
                    output += "<a href=\""+this._contextPages[i].replace("{0}",this._contextIds[i])+"\">"+this._contextTypeLabels[i]+"</a>";
                } else
                    output += this._contextTypeLabels[i];
                if (this._contextTypes[i]==this.contextType) {
                    if (this.customContextItems) {
                        output += "<ul>";
                        for (var k=0; k<this.customContextItems.length; k++) {
                            //output += "<li><a href=\"javascript:iconbarButtonClicked('"+this.customContextItems[k]+"')\">"+this.customContextItemLabels[k]+"</a></li>";
                            output += "<li><a href=\"javascript:showInfoPanel("+k+")\">"+this.customContextItemLabels[k]+"</a></li>";
                        }
                        output += "</ul>";
                    }
                    break;
                }
            }
            for (var j=i; j>0; j--) {
                output += "</li></ul>";
            }
        }
        output += "</li></ul>";
        container.innerHTML = output;
    }
}

