//////////////////////////////////////////////////////////////////
//DETECT IE VERSION IF AVAILABLE
//////////////////////////////////////////////////////////////////
temp=navigator.appVersion.split('MSIE');
ieVer=parseInt(temp[1]);

if(ieVer == 6)
{
  document.write('\r\n<'+'link rel="stylesheet" type="text/css" media="all" href="/css/flash_map_ie6.css" />');
}
else
{
	document.write('\r\n<'+'link rel="stylesheet" type="text/css" media="all" href="/css/flash_map.css" />');
}

//////////////////////////////////////////////////////////////////
//LOADS SITEPLAN AFTER DOCUMENT CONTENTS
//////////////////////////////////////////////////////////////////
function init()
{
  var siteplan_flash = new SWFObject("/swf/flash_map/flash_map.swf", "the_siteplan", "700", "450", "8", "#91a4be");
  siteplan_flash.addVariable("data_path", "/swf/flash_map/data.xml");
  siteplan_flash.write("siteplan_content");
}

// wait for the page to fully load before initializing
window.onload = init;

//////////////////////////////////////////////////////////////////
//OVERLAY SETUP
//////////////////////////////////////////////////////////////////
window.onresize = window.document.onscroll = function()
{
	if($('overlay').style.display != "none")
	{
    center('box');
				adjust_overlay();
	}
}

function adjust_overlay()
{
  //resizes overlay to fit the full window height
				if(ieVer == 6)
				{
				  document.getElementById("overlay").style.height = document.body.clientHeight + 10; //IE6
				}
				if(c_page == "home")
				{
					 document.getElementById("overlay").style.height = "100%"; //HOMEPAGE BUG IN FF2
				}
				else
				{
				  document.getElementById("overlay").style.height = (window.document.height + 10) + "px"; //ALL OTHER BROWSERS
				}
}

function showBox(){
    $('overlay').show();
    center('box');		
				
				adjust_overlay();
    //return false;
}

function hideBox(){
    $('box').hide();
    $('overlay').hide();
    //return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}