// The following derived from http://www.fillthathole.org.uk/js/maximise_map.js

var maximised = false;
var container = document.createElement("div");
var maximiseDiv = document.createElement("div");
var map_width;
var map_h_borders;
var map_v_borders;
var map_height;
var mapDiv;


function makeMaximiseButton()
{
	mapDiv = document.getElementById("map");
    map_width = mapDiv.offsetWidth;
    map_height = mapDiv.offsetHeight;
    map_h_borders = mapDiv.offsetWidth - mapDiv.clientWidth;
    map_v_borders = mapDiv.offsetHeight - mapDiv.clientHeight;
    var controlpos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 36));
    container.appendChild(maximiseDiv);
    var imgLupa = document.createElement("img");
    imgLupa.src = '/fotos/imagens/icon_lupa.gif';
    maximiseDiv.appendChild(imgLupa);
    GEvent.addDomListener(maximiseDiv, "click", function() { fullScreen() });
    controlpos.apply(container);
    mapconf.oMap.getContainer().appendChild(container);
    maximiseDiv.style.cursor = "pointer";
}

function fullScreen()
{
    var center = mapconf.oMap.getCenter();
    if (!maximised)
    {
        mapDiv.style.width = (f_clientWidth()-map_h_borders)+'px';
        mapDiv.style.height = (f_clientHeight()-map_v_borders)+'px';
        mapDiv.style.position = 'fixed';
        if (navigator.appVersion.toLowerCase().indexOf('msie 6')!=-1)
        {
            // IE6 doesn't handle position: fixed...
            // still needs to move mapdiv to top left, somehow :(
            // perhaps move div to HTML root in DOM?
            document.body.style.height = '100%';
            document.body.style.overflow = 'auto';
            mapDiv.style.position = 'absolute';
        }
        mapDiv.style.zIndex = 9999;
        mapDiv.style.top = 0;
        mapDiv.style.left = 0;
        maximised = true;
        mapconf.oMap.checkResize();
        mapconf.oMap.setCenter(center);
    }
    else
    {
        mapDiv.style.position = 'relative';
        mapDiv.style.width = (map_width-2)+'px';
        mapDiv.style.height = (map_height-2)+'px';
        mapDiv.style.zIndex = '0';
        maximised = false;
        mapconf.oMap.checkResize();
        mapconf.oMap.setCenter(center);
    }
}

// The following derived from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html

function f_clientWidth() {
    var n_win = window.innerWidth ? window.innerWidth : 0;
    var n_docel = document.documentElement ? document.documentElement.clientWidth : 0;
    var n_body = document.body ? document.body.clientWidth : 0;
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
    n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientHeight() {

    // From http://www.quirksmode.org/viewport/compatibility.html
    
    if (self.innerHeight) // all except Explorer
    {
        return self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
    {
        return document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers (needs scroll-bar width added?)
    {
        return document.body.clientHeight;
    }
}

