// MapBox connector for Google Maps API v3.

function mbLogo(map) {
    var logoDiv = document.createElement('DIV');
    logoDiv.className = 'mbLogo';
    logoDiv.innerHTML = '<a href="http://mapbox.com">'
        + '<img src="http://mapbox-js.s3.amazonaws.com/img/mapbox.png"></a>';
    map.controls[google.maps.ControlPosition.BOTTOM_LEFT]
        .push(logoDiv);
};

function mbLayer(options) {
    return new google.maps.ImageMapType({
        getTileUrl: function(coord, z) {
        // Y coordinate is flipped in Mapbox, compared to Google
        // Simplistic predictable hashing
        return 'http://'
            + ['a', 'b', 'c', 'd'][(coord.x + coord.y) % 4]
            + '.tile.mapbox.com/1.0.0/' + options.tileset
            + '/' + z
            + '/' + coord.x
            + '/' + Math.abs(coord.y - (Math.pow(2, z) - 1)) + '.' + options.filetype;
        },
        name: 			options.name,
        alt: 			options.name,
        interactive: 	options.interactive || false,
        tileSize: 		new google.maps.Size(256, 256),
        isPng: 			options.filetype == 'png' ? true : false,
        minZoom: 		options.minZoom || 0,
        maxZoom: 		options.maxZoom || 17,
        opacity:		1
    });
};

