
YAHOO.namespace("mektec.util.accordion");
YAHOO.mektec.util.accordion = new function()
{
  this.hdClass       = "";
  this.hdClassActive = "";
  this.bdClass       = "";
  this.duration      = "";
    
  this.clickEventDependent = function(e)
  {
    var oSelf = YAHOO.mektec.util.accordion;
    var elOldHd = YAHOO.util.Dom.getElementsByClassName(oSelf.hdClassActive)[0];
    
    if(elOldHd)
    {
      var elOldBd = oSelf.findContent(elOldHd);
      oSelf.closeSection(elOldHd, elOldBd);
    }
    
    var elNewBd = oSelf.findContent(this);
    
    oSelf.openSection(this, elNewBd);
  };
    
  this.clickEventIndependent = function(e)
  {
    var oSelf = YAHOO.mektec.util.accordion;
    var elNewBd = oSelf.findContent(this);
    
    if ( YAHOO.util.Dom.hasClass(this, oSelf.hdClassActive) )
    {
      oSelf.closeSection(this, elNewBd);
    }
    else
    {
      oSelf.openSection(this, elNewBd);
    }
  };
    
  this.findContent = function(el)
  {
    if(!el)
    {
      return null;
    }
        
    var el = el.nextSibling;
    
    while(el.className != this.bdClass)
    {
      el = el.nextSibling;
    }
        
    return el;
  };
    
  this.closeSection = function(elHd, elBd, duration)
  {
    var attributes = {
      height: { to: 0}
    };

    if ( (duration == undefined) || (isNaN(duration)) )
    {
      duration = this.duration;
    }
    
    var closeAnim = new YAHOO.util.Anim(elBd, attributes, duration);
    closeAnim.animate();
    YAHOO.util.Dom.removeClass(elHd, this.hdClassActive);
  };
  
  this.closeAll = function(duration)
  {
    var hds = YAHOO.util.Dom.getElementsByClassName(this.hdClass);

    if ( (duration == undefined) || (isNaN(duration)) )
    {
      duration = this.duration;
    }
    
    var hdsLength = hds.length;
    
    for ( var i = 0; i < hdsLength; i++ )
    {
      if ( ! YAHOO.util.Dom.getElementsByClassName(this.bdClass)[i] )
        {
          return null;
        }

      var hd = YAHOO.util.Dom.getElementsByClassName(this.hdClass)[i];
      var bd = YAHOO.util.Dom.getElementsByClassName(this.bdClass)[i];
      this.closeSection(hd, bd, duration);
    }
  };
  
  this.closeAllFast = function()
  {
    this.closeAll(0.0);  
  };
    
  this.openSection = function(elHd, elBd, duration)
  {
    var attributes = {
      height: { to: elBd.scrollHeight }
    };
    
    if ( (duration == undefined) || (isNaN(duration)) )
    {
      duration = this.duration;
    }
    
    var openAnim = new YAHOO.util.Anim(elBd, attributes, duration);
    openAnim.onComplete.subscribe(function(){
      var el = this.getEl();
      el.style.height="auto";
    });

    openAnim.animate();
    YAHOO.util.Dom.addClass(elHd, this.hdClassActive);
  };
  
  this.openAll = function(duration)
  {
    var hds = YAHOO.util.Dom.getElementsByClassName(this.hdClass);
    
    if ( (duration == undefined) || (isNaN(duration)) )
    {
      duration = this.duration;
    }

    var hdsLength = hds.length;
    
    for ( var i = 0; i < hdsLength; i++ )
    {
      if ( ! YAHOO.util.Dom.getElementsByClassName(this.bdClass)[i] )
        {
          return null;
        }
      
      var hd = YAHOO.util.Dom.getElementsByClassName(this.hdClass)[i];
      var bd = YAHOO.util.Dom.getElementsByClassName(this.bdClass)[i];
      this.openSection(hd, bd, duration);
    }
  };
  
  this.openAllFast = function()
  {
    this.openAll(0.0);
  };

  this.openFirst = function(duration)
  {
    if ( (duration == undefined) || (isNaN(duration)) )
    {
      duration = this.duration;
    }
    
    var hd = YAHOO.util.Dom.getElementsByClassName(this.hdClass)[0];
    var bd = YAHOO.util.Dom.getElementsByClassName(this.bdClass)[0];
    this.openSection(hd, bd, duration);
  };
  
  this.openFirstFast = function()
  {
    this.openFirst(0.0);
  };
    
  this.openNumber = function(integer)
  {
    var hd = YAHOO.util.Dom.getElementsByClassName(this.hdClass)[integer];
    var bd = YAHOO.util.Dom.getElementsByClassName(this.bdClass)[integer];
    this.openSection(hd, bd);
  };
    
  this.init = function(behavior,
                       initial,
                       duration,
                       event,
                       hdClass, 
                       hdClassActive,
                       bdClass)
  {
    // behavior should be one of 'independent' (default) or 'dependent'. 
    // Here, dependent indicates that opening one accordion will close all 
    // others.
    behavior = ((behavior) ? behavior : 'independent');

    // initial should be one of 'all', 'none', or 'first'.
    initial = ((initial) ? initial : 'all');
    
    // animation duration setting in seconds.
    this.duration = (
      ((duration == undefined) || isNaN(duration)) ? 0.2 : duration
    );
    
    // event type;
    event = ((event) ? event : 'click');

    // these are the class identifiers for the elements to operate over.
    this.hdClass       = ((hdClass) ? hdClass : 'accordionToggle');
    this.bdClass       = ((bdClass) ? bdClass : 'accordionContent');
    this.hdClassActive = ((hdClassActive) ? hdClassActive : 'accordionToggleActive');
    
    (initial == 'all')  ? this.openAllFast() : this.closeAllFast();
    (initial == 'first') ? this.openFirstFast() : null;

    eHandler = ((behavior == 'independent') ? 
      this.clickEventIndependent : this.clickEventDependent);
  
    YAHOO.util.Event.addListener(
      YAHOO.util.Dom.getElementsByClassName(this.hdClass),
      event,
      eHandler
    );
  };
};

YAHOO.namespace("mektec.util.tabs");
YAHOO.mektec.util.tabs = new function()
{  
  function tabCloseTimeout()
  {
    this.delay = 300;
    this.timeoutCall = null;
    this.el = null;
    
    this.setCloseTimeout = function(el)
    {
      var oSelf = this;
      oSelf.el = el;
      
      oSelf.timeoutCall = setTimeout(function()
      {        
        var el = oSelf.el;
       
        while ( el && el.className != 'subList' )
        {
          if ( el.className == 'tabLink tabLinkSpecial' )
          {
            YAHOO.util.Dom.removeClass(el, 'tabLinkSpecial');
          }
      
          el = el.nextSibling;
        }
    
        if ( ! el )
        {
          return null;
        }
  
        var attributes = {
          height: { to: 0 }
        };
    
        var closeAnim = new YAHOO.util.Anim(el, attributes, 0.4);
     
        closeAnim.animate();
      }, oSelf.delay);
    };
  
    this.clearCloseTimeout = function()
    {      
      var oSelf = this;
      
      if ( oSelf.timeoutCall != null )
      {
        clearTimeout(oSelf.timeoutCall);
        oSelf.timeoutCall = null;
      }
    };
  };
  
  var homeTabTimeout         = new tabCloseTimeout();
  var productsTabTimeout     = new tabCloseTimeout();
  var capabilitiesTabTimeout = new tabCloseTimeout();
  var supportTabTimeout      = new tabCloseTimeout();
  
  this.overEvent = function(e)
  {
    switch ( this.id )
    {
   	  case 'tabLinks_home':         homeTabTimeout.clearCloseTimeout();         break;
   	  case 'tabLinks_products':     productsTabTimeout.clearCloseTimeout();     break;
   	  case 'tabLinks_capabilities': capabilitiesTabTimeout.clearCloseTimeout(); break;
   	  case 'tabLinks_support':      supportTabTimeout.clearCloseTimeout();      break;
    }
    
    var el = this.firstChild;
    
    while ( el && el.className != 'subList' )
    {  
      if ( el.className == 'tabLink' )
      {
        YAHOO.util.Dom.addClass(el, 'tabLinkSpecial');
      }
          
      el = el.nextSibling;
    }
    
    if ( ! el )
    {
      return null;
    }

    var attributes = {
      height: { to: el.scrollHeight }
    };

    var openAnim = new YAHOO.util.Anim(el, attributes, 0.4);
    openAnim.animate();
  };
  
  this.outEvent = function(e)
  {
    var el = this.firstChild;

    switch ( this.id )
    {
   	  case 'tabLinks_home':         homeTabTimeout.setCloseTimeout(el);         break;
   	  case 'tabLinks_products':     productsTabTimeout.setCloseTimeout(el);     break;
   	  case 'tabLinks_capabilities': capabilitiesTabTimeout.setCloseTimeout(el); break;
   	  case 'tabLinks_support':      supportTabTimeout.setCloseTimeout(el);      break;
    }
  }
  
  this.init = function()
  {
    YAHOO.util.Event.addListener(
      YAHOO.util.Dom.getElementsByClassName('tabItem', 'li'),
      'mouseover',
      this.overEvent
    );
    
    YAHOO.util.Event.addListener(
      YAHOO.util.Dom.getElementsByClassName('tabItem', 'li'),
      'mouseout',
      this.outEvent
    );
  };
};

googleMapInit = function()
{
  //var infoHtml = '<img src="/images/logo.png" style="border: none;" />';

  var latlng = new google.maps.LatLng(37.3665, -121.9185);
  var mapOptions = {
	      zoom: 17,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
  var map =
    new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  var image = "/images/logo.png";
  var marker = new google.maps.Marker({
	position: latlng,
	map:      map
  });
  var infowindow = new google.maps.InfoWindow();
  infowindow.set_content('<img src="/images/logo.png" style="border: none;" />');
  infowindow.open(map, marker);
};

