/**
*   GMultiPolygon extension
**/
function GMultiPolygon(){
    this._aPolys = Array();
    this._aPolyBounds = Array();
    
    /* Init */
    this._gInitMulti = function(oArg){    
        var aPolyLines = oArg.polylines;
        var i = aPolyLines.length;
        while ( i-- ) {
            this._gAddPoly(GPolygon.fromEncoded({polylines:Array(aPolyLines[i]), fill:false, color:'#000000', opacity:100, outline:false}));
        }    
    }

    /**
    *   Add polygon and polybounds to list.
    **/ 
    this._gAddPoly = function(oPoly){
        this._aPolyBounds.push( oPoly.getBounds() );
        this._aPolys.push( oPoly );
    }

    /**
    *   Check if multipoly contains point.
    **/
    this.Contains = function(point){
        var i = this._aPolyBounds.length;
        while ( i-- ) {
            if ( this._aPolyBounds[i].contains(point) ) {
                if ( this._gCheckPoly(i, point) ) {
                    return true;
                }
            }
        }
        return false;
    }

    this._gCheckPoly = function(index, point){
        return this._aPolys[index].Contains(point);
    }    
    
    this.getBounds = function() {
        if ( !this.oBounds ) {
            this.oBounds = new GLatLngBounds();
            var i = this._aPolyBounds.length;
            while ( i-- ) {
                this.oBounds.extend(this._aPolyBounds[i].getSouthWest());
                this.oBounds.extend(this._aPolyBounds[i].getNorthEast());
            }
        }
        return this.oBounds;
    }
}
