/**
*   Swap color and background color
**/
function swapColors(oEle){
    var sFg     = oEle.style.color;
    var sBg     = oEle.style.backgroundColor;
    
    if ( sColor.length == 0 ) {
        sFg = "white";
    }
    if ( sBg.length == 0 ) {
        sBg = "#"+sColor;
    }
        
    oEle.style.color = sBg;
    oEle.style.backgroundColor  = sFg;
}




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

      var size = checkSize();      
      myWidth  = size[0];
      myHeight = size[1];
      
      if ( ( myWidth < 500 || myHeight < 500 ) && oSettings._bMenu !== false ) { 
        window.resizeTo(1024, 768);        
        
        var size = checkSize();
        myWidth = size[0];
        myHeight= size[1];        
      }
      
      
      if ( myWidth < 914 ) {
        document.getElementById('tabMap').style.width = ( 20 ) + 'px';
      } else {
        document.getElementById('tabMap').style.width = ( myWidth  - 904 ) + 'px';
      }
            
      document.getElementById('container').style.marginTop = (iHeaderHeight)+'px';
      document.getElementById('GeoMenu').style.top = (iHeaderHeight+22)+'px';
      
      
      //document.getElementById('GeoMap').style.height =  ( myHeight  - 25 - iHeaderHeight ) + 'px';
      
      if ( oSettings._bMenu !== false ) {
          document.getElementById('tabMenu').style.top = (iHeaderHeight)+'px';
          document.getElementById('GeoMenu').style.height = ( myHeight  - 25 - iHeaderHeight ) + 'px';
          document.getElementById('GeoMenu_items').style.height = ( myHeight  - 164 - iHeaderHeight ) + 'px';
          document.getElementById('GeoDirections').style.height = ( myHeight  - 93 - iHeaderHeight ) + 'px';
          document.getElementById('GeoMap').style.width =   ( myWidth   - 307 ) + 'px';
          
          document.getElementById('GeoMap').style.height =  ( myHeight  - 25 - iHeaderHeight ) + 'px';
      } else {
            document.getElementById('container').style.right = 0;
            document.getElementById('tabMenu').style.display = 'none';
            document.getElementById('GeoMenu').style.display = 'none';
            document.getElementById('GeoMap').style.width =   ( myWidth - 3 ) + 'px';      
            
            document.getElementById('GeoMap').style.height =  ( myHeight  - 25 - iHeaderHeight ) + 'px';
            
            document.getElementById('tabMap').style.width = ( document.getElementById('tabMap').offsetWidth + 304 ) + "px";
            
      }
      //document.getElementById('GeoMap').style.height =  ( myHeight  - 25 - iHeaderHeight ) + 'px';
      document.getElementById('tab').style.height =     ( myHeight  - 25 - iHeaderHeight ) + 'px';
      
      
      


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



/**
*   Show / Hide the overlay tab for extra info/search etc.
**/
function swap(div, bDisplay){
    return false;

    $(div).style.display = bDisplay ? 'block' : 'none';
    
    oGeoStart._bEnableHover = !bDisplay;    
    
    /**
    *   Add listener to map to close the tab when clicked
    **/
    if ( bDisplay ) {
        if ( oGeoStart.oListener == null ) {
            window.setTimeout(closeTabClick, 1);
        }
        oGeoStart.oMap.getContainer().className = '';
        $('help').style.display = 'none';
        $('tab').scrollTop = 0;
    } else {
        /** remove the click listener if possible **/
        try { oGeoStart.oListener.remove(); } catch(e){}
        try { GEvent.removeListener(oGeoStart.oListener);  } catch(e){}
        oGeoStart.oListener = null;
        activate('tabMap');
        oGeoStart.oMap.getContainer().className = 'active';
    }
}

function closeTabClick(){
    oGeoStart.oListener = GEvent.addListener(oGeoStart.oMap, 'click', function(){
        activate('tabMap');
        swap('tab',false); 
        try { oGeoStart.oListener.remove(); } catch(e){}
        try { GEvent.removeListener(oGeoStart.oListener);  } catch(e){}
        oGeoStart.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='';
        $('route').className='active';
        $('GeoMenu_items').style.display = 'none';
        $('GeoDirections').style.display = 'block';
    } else {
        $('button').className='active';
        $('route').className='';
        $('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['route'] = document.getElementById('tab_contents_route');
    
    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];
      //console.log(retVal);
      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);
}
