var $tb = tbelt;

var flashMap = {
    containerID:"flashMap",
    container:null,
    swfID:"mapswf",
    swf: null,
    height: 311,
    width: 416,
    src: "Weingarten-3.swf",
    version:7,
    flashVars: {
        isCoordMode: false,
        isEditMode: false,
        display: "home", //Defines the context of the map instance. home,map,state,city
        displayData: null, //Valid values are CityID or StateAbbr from XML data.
        dataPath: "data/", //Defines the path to the XML data folder.
        market: "retail" //Defines the market mode of the map. Valid values are "retail" and "industry".
    },
    flashParams: {
        base:".",
        allowScriptAccess: "sameDomain",
        quality: "high",
        menu: "false",
        bgcolor:"#FFFFFF",
        wmode:"opaque"
    },
    create: function() {

        var flashVars = [];
        for (var v in this.flashVars)
            if(this.flashVars[v]!=null) flashVars.push(v + "=" + this.flashVars[v]);

        var fo = new FlashObject(this.src, this.swfID, this.width, this.height, this.version);
        
        for (var p in this.flashParams)
            fo.addParam(p, this.flashParams[p]);
        fo.addParam("FlashVars", flashVars.join("&"));
        //fo.addParam("scale", "noscale");
        fo.write(this.containerID);
        this.swf = document.getElementById(this.swfID);
        this.container = document.getElementById(this.containerID);
    },
    
    getMarket:function(){
        return (flashMap.swf != null && typeof (flashMap.swf.getMarket) == "function") ? flashMap.swf.getMarket() : flashMap.flashVars.market;
    }
}



//Called when a state in the flash map is clicked.
function stateClicked(st_abbr, proptype) {
    console.log("stateClicked(" + st_abbr + "," + proptype + ")");

    // delete the map zoom cookies so we don't re-zoom
    SetCookie('RETAIL_MAPZOOM1', '');
    SetCookie('RETAIL_MAPZOOM2', '');
    SetCookie('INDUSTRIAL_MAPZOOM1', '');
    SetCookie('INDUSTRIAL_MAPZOOM2', '');

    // go to the state
    //location.href = proptype + "/?st_abbr=" + st_abbr;	

    if (flashMap.flashVars.display == "home") {
        with (flashMap) {
            flashVars.display = "state";
            flashVars.market = (proptype == "industrial") ? "industry" : "retail";
            flashVars.displayData = st_abbr;
            create("flashMap");
        }
    }
}


//Called when a city/metro area in the flash map is clicked.
function cityClicked(name) {
    console.log("cityClicked(" + name + ")");

    var market = flashMap.getMarket();
    if (market == "industry") market = "industrial";
    window.location = "/"+market+"/results.aspx?ma=" + name;
    /*
    gmaps.queryLocations("ma=" + name + "&type=" + market);
    gmaps.toggleFlashMap(false);
    */
}

// called when a map item is clicked
function recordState(display, displaydata) {

    var market = flashMap.getMarket();

    if (market == "industry") {
        SetCookie('INDUSTRIAL_MAPZOOM1', display);
        SetCookie('INDUSTRIAL_MAPZOOM2', displaydata);
    } else {
        SetCookie('RETAIL_MAPZOOM1', display);
        SetCookie('RETAIL_MAPZOOM2', displaydata);
    }
    
}	
