 /***********
Variant Controls COG menu
*************/
jQuery(function(){
  jQuery('.cog').click(function() {
  $this = jQuery(this);
 
  // if it's already open, just shut it
  if ($this.data('isOpen') == true) {
    close($this);
    return;
  }
 
  var closedZIndex = 1000;
  var openZIndex = 1001;
  $this.data('isOpen', false);
  // var isOpen = false;
  var $list = $this.siblings('ul.cog-options');
  // .mouseover(function() {
  //             jQuery(this).data('hovering', true);
  //           });
  // if there are no items, hide the actions button
  if ( !jQuery('li', $list).length ) {
    jQuery(this).hide();
    return;
  }

  var open = function($btn) {
    var $openlist = $btn.parents('.cog-menu').addClass('list-open').css('z-index', openZIndex);
    $this.data('isOpen',true);               
    $list.show();
    // bind a click event to the document to close the controls
    jQuery(document).bind('click', onDocumentClick);
  };
 
  var close = function($btn) {
    $btn.parents('.cog-menu').removeClass('list-open').css('z-index', closedZIndex);
    $this.data('isOpen',false);               
    $list.hide();
    jQuery(document).unbind('click', onDocumentClick);
  };
 
  var onDocumentClick = function(e) {
    close($this);
  };
 
  if ($this.data('isOpen') == true) {
    close($this);
  } else {
    open($this);
    }
  return false;

  });
});



