/**
 * Drop down menu interactions
 * Copyright (c)	E-nova Technologies pvt. ltd.
 *
 * Licensed under The General Public Licence v2 onwards.
 * Redistributions of files must retain the above copyright notice.
 *
 * @package			stripthis
 * @copyright		E-nova Technologies pvt. ltd.
 * @link				http://www.enova-tech.net
 * @license			GPL2 onwards - http://www.opensource.org/licenses/gpl-license.php
 * @author      remy@enova-tech.net
 * @date        07/07/07
 *
 * Tabulated menu effects 
 * Hide and show submenu when pressing arrow down button
 * Acts like a dropdown list regarding user interactions
 */

$(document).ready(function(){
  var _current = null;
  var _hover = false;
  var _visible = false;
  var _img = null;
  
  /***
   * Hide / show
   */
  function hide(){
  	_current.css("visibility","hidden");
  	_visible=false;
  	_current= null;
    _hover =false;
  }
  
  function show(){
    _visible = true;
    _current.css("visibility","visible");
    _current.mouseover(function(){
    	_hover = true;
    });
  }
  
  /**
   * Events handler
   */
  $(".menu#top li a.sub").click(function(){
    if(!_visible){
      _current = $(this).parent().next();
      _img = $(this).children("img");
      _img.css("border-style","inset");
      show();
    }else{
      _img.css("border-style","solid");
      hide();
    }
  });
  
  $(".menu#top li a.sub").blur(function(){
    if(_current!=null && _visible && !_hover){
      _img.css("border-style","solid");
      hide();
    } 
  });
  
  $(".menu#top ul.submenu").click(function(){
    _img.css("border-style","solid");
    hide();
  });
   
  $(".menu#top ul.submenu").mouseout(function(){
    _hover = false;
  });
});