/*
  All functionality in this file is used by the flash-map, do not change method or variable names 
 
  Rewritten and restructured by Rens 13/10/2006
  
  Added JavaScriptFlashGateway (Bart 23.11.2006)

*/
FlashMap = function(src, width, height) {
    this.uid = new Date().getTime();
    this.flashProxy = new FlashProxy(this.uid, '/js/JavaScriptFlashGateway.swf');
    this.tag = new FlashTag(src, width, height); // last two arguments are height and width
    this.activeCountryId = -1;
    this.regionIds = [];
    Spif.DOMEvents.attach(window, "load", this.doLoad, this);
}

FlashMap.prototype = {

    uid: null,
    flashProxy: null,
    tag: null,
    flashMapLoaded: false,
    javaScriptLoaded: false,
    countryId: null,
    regionIds: null,
    searchFullPanel: null,
    searchFullOption1Panel: null,


    doLoad: function() {
        this.searchFullPanel = document.getElementById('search-full-panel');
        this.searchFullOption1Panel = document.getElementById('search-full-1');
        this.javaScriptLoaded = true;
        if (this.flashMapLoaded) {
            this.setMap();
        }
    },
    
    
    write: function(params) {
        this.tag.setFlashvars('lcId=' + this.uid + '&amp;' + params);
        this.tag.write(document);
    },
    
    
    isVisible: function() {
        return (this.searchFullPanel.className == 'search-panel-expanded' && this.searchFullOption1Panel.className == 'option-expanded');
    },
    
    
    setMap: function() {
        if (this.isVisible()) {
            if (this.regionIds.length != 0) {
                flashMap.flashProxy.call('changeSettings', this.countryId + ':' + this.regionIds.join(','));
            } else {
                flashMap.flashProxy.call('changeSettings', this.countryId);
            }
        }
    },
    
    updateRegionStoreByToggling: function(id) {
	    var obj = document.getElementById(id);
	    if (!obj) return;
	    if (obj.checked) {
		    this.regionIds.push(id);
	    } else {
		    for (var i = 0; i < this.regionIds.length; i++) {
			    if (this.regionIds[i] == id) 
			        this.regionIds.splice(i, 1);
		    }
	    }
    }
}

flashMap = new FlashMap('/Search/map_vs_new.swf', 298, 300);

// var activeCountryId = '-1';
// var regionIds = [];	


// Called from Flash:

selectCountry = function (countryId) 
{
	if (countryId != countryAndArea.currentSelectedCountry)
	{
    // Select the country from the country dropdown in the arealist
    countryAndArea.selectCountryFromlist(countryId);
    // Do the rest of the stuff....
    countryAndArea.changeToCountryNew(countryId, true);
  }
} 

selectRegion = function(regionId, isSelected) {
    if (isSelected == true) {
	    // Select the region check4box in the arealist
	    countryAndArea.selectAreaFromList(regionId);
    } else {
	    // DEselect the region check4box in the arealist
	    countryAndArea.deselectAreaFromList(regionId);
    }
    // Do the rest of the stuff....
    countryAndArea.toggleRegion(regionId);
}

finishedLoading = function() {
    
    flashMap.flashMapLoaded = true;
    if (flashMap.javaScriptLoaded) 
        flashMap.setMap();

}
