function TuristRegion(map, noRecenter){
    this.map = map;
    if(noRecenter){
        this.noRecenter = noRecenter;
    }else{
        this.noRecenter = false;
    }
}



// *** static
TuristRegion.clearRegions = function () {

    if (!TuristRegion.regions) {
        return;
    }
    var regions = TuristRegion.regions;
    for (var i = 0; i < regions.length; i++) {
        regions[i].remove();
    }
    regions = new Array();
}

// *** static
TuristRegion.loadFromJSON = function (json, map, savePos, noRecenter) {


    var jsonObject = (json.responseJSON || json);
    var childRegions =  jsonObject.children;

    if (!TuristRegion.regions) {
        TuristRegion.regions = new Array();
    }

    var tr;
    if (!childRegions) {
            tr = new TuristRegion(map, noRecenter);
            Object.extend(tr, jsonObject);
            tr.showRegion(savePos);
            TuristRegion.regions.push(tr);
    } else {
        for ( var i = 0; i < childRegions.length; i++ ) {
            tr = new TuristRegion(map, true);
            Object.extend( tr, childRegions[i] );
            tr.showRegion(savePos);
            TuristRegion.regions.push(tr);
        }
        
        if (noRecenter != true) {
            var bounds = new GLatLngBounds;
            bounds.extend(new GLatLng(jsonObject.yMinimum, jsonObject.xMinimum));
            bounds.extend(new GLatLng(jsonObject.yMaximum,jsonObject.xMaximum));
            map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
        }
    }
}


TuristRegion.prototype.loadKmlFile = function(savePos){
    var that = this;
    this.kml = new GGeoXml(this.kmlFile+"?p", function() {
        if(!that.noRecenter){
            that.kml.gotoDefaultViewport(that.map);
            if(savePos){
                that.map.savePosition();
            }
    
        }

        that.showLabel();
        if($("loadingPanel")){
            bqc.hideLoading();
        }
    });
    this.map.addOverlay(that.kml);
}

TuristRegion.prototype.showLabel = function() {
    this.elabel = new ELabel(new GLatLng(this.yCentroid, this.xCentroid),  this.regionName , "regionNameLabel");
    this.map.addOverlay(this.elabel);
    this.elabel.pixelOffset =new GSize(-1 * (this.elabel.div_.offsetWidth / 2),8);
    this.elabel.redraw(null);
}

TuristRegion.prototype.showRegion = function(savePos, callback){
    this.loadKmlFile(savePos, callback);
}

TuristRegion.prototype.remove = function() {
    this.map.removeOverlay(this.kml);
    this.map.removeOverlay(this.elabel);
}
