/** Google-map extension **/

function CdfNavMap()
{
    this.elScreen = null;
    this.elMap = null;
    this.elClose = null;
    this.mapFrame = null;
    this.width = 702;//540;
    this.height = 494;//380;
    this.contract = 0;
}

CdfNavMap.prototype.setContract = function(c)
{
    this.contract = c;
}

CdfNavMap.prototype.getDocMetrics = function()
{
    var metrics = {
	offX : 0,
	offY : 0,
	width : 0,
	height: 0
    };

    if( window.pageXOffset !== undefined ) {
	metrics.offX = window.pageXOffset;
    } else if( document.documentElement.scrollLeft !== undefined ) {
	metrics.offX = document.documentElement.scrollLeft;
    } else if( document.body.scrollLeft !== undefined ) {
	metrics.offX = document.body.scrollLeft;
    }

    if( window.pageYOffset !== undefined ) {
	metrics.offY = window.pageYOffset;
    } else if( document.documentElement.scrollTop !== undefined ) {
	metrics.offY = document.documentElement.scrollTop;
    } else if( document.body.scrollTop !== undefined ) {
	metrics.offY = document.body.scrollTop;
    }

    if( window.innerWidth ) {
	metrics.width = window.innerWidth ;
	metrics.height = window.innerHeight;
    } else if( document.documentElement.clientWidth ) {
	metrics.width = document.documentElement.clientWidth;
	metrics.height = document.documentElement.clientHeight;
    } else if( document.body.clientWidth ) {
	metrics.width = document.body.clientWidth;
	metrics.height = document.body.clientHeight;
    }

    return metrics;
}


CdfNavMap.prototype.open = function()
{
    this.elScreen = document.createElement( "div" );
    this.elScreen.style.position = "absolute";
    this.elScreen.style.display = "block";
    this.elScreen.style.background = "#ffffff";
    this.elScreen.style.opacity = 0.7;
    this.elScreen.style.filter = "alpha(opacity=70)";
    if( this.elScreen.style.setAttribute )
	this.elScreen.style.setAttribute( "-moz-opacity", "0.7" );
    this.elScreen.style.width = "1px";
    this.elScreen.style.height = "1px";
    this.elScreen.style.zIndex = 100;
    document.body.appendChild( this.elScreen );

    this.elMap = document.createElement( "div" );
    this.elMap.style.display = "block";
    this.elMap.style.position = "absolute";
    this.elMap.style.width = this.width + "px";
    this.elMap.style.height = this.height + "px";
    this.elMap.style.background = "#ffffff url(/layout/navtopback.jpg) no-repeat top center";
    this.elMap.style.zIndex = 101;
    document.body.appendChild( this.elMap );

    this.elClose = document.createElement( "div" );
    this.elClose.style.display = "block";
    this.elClose.style.clear = "both";
    this.elClose.style.width = "12px";
    this.elClose.style.height = "12px";
    this.elClose.style.cssFloat = "right";
    this.elClose.style.margin = "7px 11px 15px 672px";
    this.elClose.style.zIndex = 101;
    this.elClose.style.textAlign = "center";
    this.elClose.innerHTML = "<A href=\"javascript:nmap.close();\"><img src=\"/layout/navclose.jpg\" width=\"12\" height=\"12\" border=\"0\" /></A>";
    this.elMap.appendChild( this.elClose );

    this.mapFrame = document.createElement( "iframe" );
    this.mapFrame.border = "0";
    this.mapFrame.frameBorder = "0";
    this.mapFrame.frameBorder = "0";
    this.mapFrame.style.display = "block";
    this.mapFrame.style.clear = "both";
    this.mapFrame.style.width = this.width + "px";
    this.mapFrame.style.height = (this.height - 34) + "px";
    this.mapFrame.style.border = "none";
    this.mapFrame.style.outline = "none";
    this.mapFrame.style.overflow = "hidden";
    this.mapFrame.setAttribute( "scrolling", "no" );

    if( this.contract == 0 )
	this.mapFrame.src = "/php/navmap.php";
    else
	this.mapFrame.src = "/php/navmap.php?c=" + this.contract;

    this.elMap.appendChild( this.mapFrame );

    this.positionElements();

    // no scroll
    document.body.style.overflow = "hidden";
}

CdfNavMap.prototype.close = function()
{
    this.elMap.removeChild( this.elClose );
    this.elMap.removeChild( this.mapFrame );
    document.body.removeChild( this.elMap );
    document.body.removeChild( this.elScreen );
    document.body.style.overflow = "";
}

CdfNavMap.prototype.positionElements = function()
{
    var mtx = this.getDocMetrics();

    // full
    this.elScreen.style.left = mtx.offX + "px";
    this.elScreen.style.top = mtx.offY + "px";
    this.elScreen.style.width = mtx.width + "px";
    this.elScreen.style.height = mtx.height + "px";

    // center
    this.elMap.style.left = (mtx.offX + ((mtx.width - this.width)/2)) + "px";
    this.elMap.style.top = (mtx.offY + ((mtx.height - this.height)/2)) + "px";

    // below
    this.elClose.style.left = (mtx.offX + ((mtx.width - this.width)/2)) + "px";
    this.elClose.style.top = ((mtx.offY + ((mtx.height - this.height)/2)) + this.height) + "px";
}


