/**
*   Function for fluid design. 
**/               
function resizer() {
      var iHeaderHeight = parseInt(oSettings._HeaderHeight);


      var size = checkSize();      
      myWidth  = size[0];
      myHeight = size[1];
      
      if ( myWidth < 500 || myHeight < 500 ) { 
        window.resizeTo(1024, 768);        
        
        var size = checkSize();      
        myWidth = size[0];
        myHeight= size[1];        
      }
      
      document.getElementById('GeoMap').style.width =   ( myWidth   - 307 ) + 'px';
      document.getElementById('GeoMap').style.height =  ( myHeight  - 25 - iHeaderHeight ) + 'px';
      document.getElementById('GeoMenu').style.height = ( myHeight  - 25 - iHeaderHeight ) + 'px';
      document.getElementById('GeoMenu_items').style.height = ( myHeight  - 94 - iHeaderHeight ) + 'px';
      document.getElementById('GeoDirections').style.height = ( myHeight  - 93 - iHeaderHeight ) + 'px';
      
      
      
      // Links      
      document.getElementById('GeoLinks').style.height = ( myHeight  - 93 - iHeaderHeight ) + 'px';
// document.getElementById('routeResult').style.height = ( myHeight  - 433 ) + 'px';
      document.getElementById('tab').style.height =     ( myHeight  - 25 - iHeaderHeight ) + 'px';
      
      
      if ( myWidth < 914 ) {
        document.getElementById('tabMap').style.width = ( 20 ) + 'px';
      } else {
        document.getElementById('tabMap').style.width = ( myWidth  - 904 ) + 'px';
      }

      /** Try/catch because this function is called before the creation of the map object **/
      try {
        oMapObjects.oMap.checkResize();
      } catch(e) { }      
      
      //positionHelp();
}                     
/** Call the function on resize **/
onresize = resizer

var counter = 0;

function positionHelp(){
    counter++;
    iHeaderHeight = parseInt(oSettings._HeaderHeight);
    iHeight = checkSize()[1];
    if ( document.getElementById('help_draggable') ) {
        var iTop = ( 0 - iHeaderHeight + ( ( iHeight - 579 ) / 2 ) );
        if ( ( iTop ) > 0 && counter < 100 ) {
            document.getElementById('help_draggable').style.top = iTop + "px"; 
            setTimeout('positionHelp(' + myHeight + ')', 100);
        } else {
            counter = 0;
            document.getElementById('help_draggable').style.top = iTop + "px";        
        }
    } else {
        setTimeout('positionHelp(' + myHeight + ')', 100);
    }
}



/**
*   Show / Hide the overlay tab for extra info/search etc.
**/
function swap(div, bDisplay){
    
    $(div).style.display = bDisplay ? 'block' : 'none';
    
    oMapObjects._bEnableHover = !bDisplay;    
    
    /**
    *   Add listener to map to close the tab when clicked
    **/
    if ( bDisplay ) {
        if ( oMapObjects.oListener == null ) {
            window.setTimeout(closeTabClick, 1);
        }
        oMapObjects.oMap.getContainer().className = '';
        oHelp.hide();
        $('tab').scrollTop = 0;
    } else {
        /** remove the click listener if possible **/
        try { oMapObjects.oListener.remove(); } catch(e){}
        try { GEvent.removeListener(oMapObjects.oListener);  } catch(e){}
        oMapObjects.oListener = null;
        activate('tabMap');
        oMapObjects.oMap.getContainer().className = 'active';
    }
}

function closeTabClick(){
    oMapObjects.oListener = GEvent.addListener(oMapObjects.oMap, 'click', function(){
        activate('tabMap');
        swap('tab',false); 
        try { oMapObjects.oListener.remove(); } catch(e){}
        try { GEvent.removeListener(oMapObjects.oListener);  } catch(e){}
        oMapObjects.oListener = null;
    });
}

/**
*   Change classname for sTab.
*   Used to color the tab.
**/
function activate(sTab){
    var aTabs = $('tabs').getElementsByTagName('div');
    for ( var sCurTab in aTabs ) {
        if ( sTab == aTabs[sCurTab].id ) {
            aTabs[sCurTab].className = 'active';
        } else if ( aTabs[sCurTab].className == 'active' ) {
            aTabs[sCurTab].className = '';
        }
    }
}

/**
*   Handle the menu tabs.
**/
function m_activate(sTab){
    if(sTab == 'route'){
        $('button').className='';
        $('links').className='';
        $('route').className='active';
        $('GeoMenu_items').style.display = 'none';
        $('GeoDirections').style.display = 'block';
        $('GeoLinks').style.display = 'none';
    } else if ( sTab == 'links' ) {
        $('button').className='';
        $('links').className='active';
        $('route').className='';
        $('GeoMenu_items').style.display = 'none';
        $('GeoLinks').style.display = 'block';
        $('GeoDirections').style.display = 'none';
    } else {
        $('button').className='active';
        $('links').className='';
        $('route').className='';
        $('GeoLinks').style.display = 'none';
        $('GeoMenu_items').style.display = 'block';
        $('GeoDirections').style.display = 'none';
    }
}

/**
*   In the main info tab, there are 3 divs. Use this to activate the correct div.
**/
function setTabContent(sBlock){
    var aBlocks = new Object();
    aBlocks['search'] =     document.getElementById('tab_contents_search');
    aBlocks['info'] =       document.getElementById('tab_contents_info');
    aBlocks['list'] =       document.getElementById('tab_contents_list');
    aBlocks['contact'] =    document.getElementById('tab_contents_contact');
    aBlocks['colofon'] =    document.getElementById('tab_contents_colofon');
    
    if ( sBlock != 'search' ) {
        var eCurTab = $('sCurTab');
        eCurTab.value = sBlock;
    }
    for ( var sId in aBlocks ) {
        aBlocks[sId].style.display = 'none';
    }    
    aBlocks[sBlock].style.display = 'block';
    
}

/**
*   Toggle help display on the map. 
*   eHC: Help Control element.
function toggleHelp(){
    var eH = $('help');
    var eHC = $('Control_grey_help');
    if ( eH.style.display != 'block' ){
        eH.style.display = 'block';  
        eHC.style.fontWeight = 'bold';      
        pageHit('Google_Maps_Help');
    } else {
        eH.style.display = 'none';
        eHC.style.fontWeight = 'normal';
    }    
}
**/





function checkSize() {
      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }      
      var retVal = [myWidth, myHeight];
      return retVal;
}


/** 
*   The tab title is dynamic and can contain 'Detail pagina' and 'Locatie overzicht' 
*   This function reads input#sCurTab.value to check what was loaded last.
**/
function tabTitleClick(){
    var sCurTab = $('sCurTab').value;
    
    setTabContent(sCurTab);
    activate('tabTitle');
    swap('tab', true);
}

