/*
 * $Id$
 * $URL$
 */

// shortcuts
var Y = YAHOO.util,
    $E = Y.Event,
    $D = Y.Dom;
    
lmi_map_loaded = false;

// controls the display of the tabs
// loops through each of the tabs and changes their display depending on the mode
function togglePlaceTabs( mode ) {
    var tabsChildren, linkChild, textChild,
        tabs = $('tabs'),
        tab1 = $('place_about'),
        tab2 = $('place_nearby'),
        tabsArray = $D.getChildren( $D.getFirstChild(tabs) );

    for( i=0; i<tabsArray.length; i++ ) {
      // get children here
      tabsChildren = $D.getChildren(tabsArray[i]);
      for (j = 0; j < tabsChildren.length; j++) {
        if ( $D.hasClass(tabsChildren[j], 'link') ) {
          linkChild = tabsChildren[j];
        }
        else {
          textChild = tabsChildren[j];
        }
      }

      if ( $D.hasClass(tabsArray[i], mode) ) {
        // this is the tab being clicked on
        $D.addClass( tabsArray[i], 'active' );
        $D.addClass( linkChild, 'hidden' );
        $D.removeClass ( textChild, 'hidden');
      }
      else {
        $D.removeClass( tabsArray[i], 'active' );
        $D.removeClass( linkChild, 'hidden' );
        $D.addClass ( textChild, 'hidden' );
      }

      // show/hide the actual content for each tab
      if ( mode == 'about' ) {
        $D.removeClass( tab1, 'hidden');
        $D.addClass( tab2, 'hidden');

      } else {
        $D.addClass( tab1, 'hidden');
        $D.removeClass( tab2, 'hidden');
      }
    }
    if ( mode == 'about' && !lmi_map_loaded) {
      // force a re-initialization of the map one time only
      init();
    }
    
    // map was either loaded on the first init() call or the call above
    lmi_map_loaded = true;
    
    //$E.stopEvent( e );
}
