var activeCat = "";
var activeBtn;

Element.Events.keyenter = {
  base: 'keyup',
  condition: function(e){
    return e.key=='enter';
  }
};

function initializeSearchBar(){
  $$('#GlobalSearch').addEvents({
    click: function(){
      if($$('#GlobalSearch').getProperty('value') == "Enter Your Search"){
        $$('#GlobalSearch').setProperty('value', '');
      }
    },
    mouseleave: function(){
      if($$('#GlobalSearch').getProperty('value') == ""){
        $$('#GlobalSearch').setProperty('value', 'Enter Your Search');
      }
    },
    'keyenter': function(e){
      e.stop();
      GlobalSearch();
    }
  });
}
initializeSearchBar();

function initializeCategories(cat){
  // Initialize Menu Effects
  $$(cat).set('morph', {duration: 180});
  $$(cat).addEvents({
    click: function(){
      if(activeCat != this.get('href') && activeCat != ""){
        $(this).morph('.categoryEnter');
      }
      $(this).morph('.categoryActive');
      activeCat = this.get('href');
      activeBtn = $(this);
    },
    mouseenter: function(){
      //var elMorph = new Fx.Morph(this, {duration: 'short'});
      if(activeCat != this.get('href')){
        $(this).morph('.categoryEnter');
      }
    },
    mouseleave: function(){
      //var elMorph = new Fx.Morph(this, {duration: 'short'});
      if(activeCat != this.get('href')){
        $(this).morph('.categoryLeave');
      }
    }
  });
}

var activeBrowse = "";
var activeBrowseBtn = "";
function browseBtns(){
  $$('#searchBtns a').set('morph', {duration: 'short'});
  $$('#searchBtns a').addEvents({
    click: function(){
      if(activeBrowse != this.get('href') && activeBrowse != ""){
        if(activeBrowseBtn.hasClass('browseBtnActive')){
          activeBrowseBtn.removeClass('browseBtnActive');     
        }
        activeBrowseBtn.addClass('browseBtnLeave');
        activeBrowseBtn.setProperty('style', '');
      }
      if(this.hasClass('browseBtnLeave')){
        this.removeClass('browseBtnLeave');     
      }
      this.addClass('browseBtnActive');

      activeBrowse = this.get('href');
      activeBrowseBtn = $(this);
    
    },
    mouseenter: function(){
      //var elMorph = new Fx.Morph(this, {duration: 'short'});
      if(activeBrowse != this.get('href')){
        $(this).morph('.browseBtnEnter');
      }
    },
    mouseleave: function(){
      //var elMorph = new Fx.Morph(this, {duration: 'short'});
      if(activeBrowse != this.get('href')){
        $(this).morph('.browseBtnLeave');
      }
    }       
  });
}
browseBtns();
