﻿function FloorplanUCJS(hiddenJSONID, modehiddenvalueID, modelinkID, primeImgID, lblFPNameID,hlAnimationID) {
    this.RefreshJSON = true;
    this._cachedJSON = null;
    this.getJSONobj = function() {
        if (this.RefreshJSON || this._cachedJSON == null) {
            this.CachedJSON = document.getElementById(hiddenJSONID).value.evalJSON(); //Prototype
            this.RefreshJSON = false;  
        }
        return this.CachedJSON;
    }
    this.currentMode = function() { return document.getElementById(modehiddenvalueID).value; };
    this.setCurrentMode = function(value) { document.getElementById(modehiddenvalueID).value = value };
    this.multilinkNODE = function() { return document.getElementById(modelinkID); };
    this.currentImage = function() { return document.getElementById(primeImgID); }
    this.currentAnimationNODE = function() { return document.getElementById(hlAnimationID); }
    this.currentFPName = function() { return document.getElementById(lblFPNameID).innerHTML; };
}
FloorplanUCJS.prototype.currentPrintBrochureURL = function() { return this.getJSONobj().PrintBrochureURL; };
FloorplanUCJS.prototype.currentImage2DRegularURL = function() { return this.getJSONobj().Image2DRegularURL; };
FloorplanUCJS.prototype.currentImage2DLargeURL = function() { return this.getJSONobj().Image2DLargeURL; };
FloorplanUCJS.prototype.currentImage3DRegularURL = function() { return this.getJSONobj().Image3DRegularURL; };
FloorplanUCJS.prototype.currentImage3DLargeURL = function() { return this.getJSONobj().Image3DLargeURL; };
FloorplanUCJS.prototype.currentAnimiation3DURL = function() { return this.getJSONobj().Animiation3DURL; };
FloorplanUCJS.prototype.currentFurnitureArrangerURL = function() { return this.getJSONobj().FurnitureArrangerURL; };
FloorplanUCJS.prototype.currentFPID = function() { return this.getJSONobj().FPID; };

FloorplanUCJS.prototype.WindowWithURL = function(WINDOW_NAME, url) {
    //Default.aspx + Telerik
    window.radopen(url, WINDOW_NAME); return false;
}
FloorplanUCJS.prototype.WindowWithURLAndTitle = function(WINDOW_NAME, url, Title) {
    //Default.aspx + Telerik
    var wnd = window.radopen(url, WINDOW_NAME);
    wnd.SetTitle(Title);
    return false;
}
FloorplanUCJS.prototype.viewPrintBrochure = function() {
    this.EventTracker("View Floorplan Brochure " + this.currentFPName(), "");
    this.WindowWithURLAndTitle('wdwPrint', this.currentPrintBrochureURL(), this.currentFPName());
};
FloorplanUCJS.prototype.viewAnimation = function() {
    this.EventTracker("View Floorplan Animation " + this.currentFPName(), "");
    this.WindowWithURLAndTitle('wdwMovie', this.currentAnimiation3DURL(), this.currentFPName());
};
FloorplanUCJS.prototype.viewFurnitureArranger = function() {
    this.EventTracker("View Floorplan Arranger " + this.currentFPName(), "");
    this.WindowWithURLAndTitle('wdwFurniture', this.currentFurnitureArrangerURL(), this.currentFPName());
};
FloorplanUCJS.prototype.showZoom = function() {
    var currentmode = this.currentMode();
    var url = "";
    if (currentmode == "3D") {
        url = this.currentImage3DLargeURL();
    } else {
        url = this.currentImage2DLargeURL();
    }
    this.EventTracker("View Floorplan Zoom " + this.currentFPName(), this.currentMode());
    this.WindowWithURLAndTitle('wdwZoom', url, this.currentFPName());
};
FloorplanUCJS.prototype.lnk2D3D = function() {
    var x = Floorplan.multilinkNODE();
    var img = Floorplan.currentImage();
    var fpid = this.currentFPID();
    var currentmode = this.currentMode();
    //if we're in 3d mode, the 2D link shows (to go to the next one)
    //if we're in 2d mode, the 3D link shows.
    if (currentmode == "3D") {
        x.className = "d3";
        img.src = this.currentImage2DRegularURL();
        this.setCurrentMode("2D");
    } else if (currentmode == "2D") {
        x.className = "d2";
        img.src = this.currentImage3DRegularURL();
        this.setCurrentMode("3D");
    }
    this.EventTracker("Switch Mode: View Floorplan " + this.currentFPName(), this.currentMode());
}
FloorplanUCJS.prototype.setupCurrentAnimationLink = function() {
    try {
        if (this.currentAnimiation3DURL() == "") {
            this.currentAnimationNODE().style["display"] = "none";
        } else {
            this.currentAnimationNODE().style["display"] = "";
        }
    } catch (e) { };
}
FloorplanUCJS.prototype.responseEnd = function(sender, eventArgs) {

    var f = new RegExp("lnkbtnView$");
    var target = eventArgs.get_eventTarget();
    //if input fired was lnkbtnView in data grid
    if (f.test(target)) {
        this.EventTracker("View Floorplan " + this.currentFPName(), this.currentMode());
        this.RefreshJSON = true;
        this.setupCurrentAnimationLink();
    }

}
FloorplanUCJS.prototype.EventTracker = function(action, label) {
    try {
        //Google/Default.aspx
        pageTracker._trackEvent("Floorplans", action, label);
    } catch (e) {
        alert(e);
    }
}



// Add FloorplansUCresponseEnd to the event listeners for telerik response end (please see default.aspx)

