window.addEvent('domready', function() {
  
       // Email decoding for SPAM robots
       $$('.sposti').each(function(el) { 
  				el.set('href','mailto:' + el.get('href').replace('|','@')); 
  				el.set('text', el.get('text').replace('|','@'));
	   });
		
  
	   $$('ul#sub-menu li a.tree').each(function(item) {
	   		if(!item.hasClass('active')){
		   		item.addClass('closed');
		   		var tree = item.getNext();
		   		tree.hide();
		   		
		   		item.addEvent('click', function(e){
		   			e.stop();
		   			var tree = this.getNext();
		   			if(this.hasClass('closed')){
		   				this.removeClass('closed');
		   				tree.show();
		   			} else {
		   				this.addClass('closed');
		   				tree.hide();
		   			}
		   		});
	   		}
	   });
	   
	   
	   var products = new Element('div', {"id": "products", "class": "drop-menu"});
	   products.load(lang+"/menus/menu-product/");
	   products.inject("bt_products");
	   products.hide();	
	   
	   var benefits = new Element('div', {"id": "benefits", "class": "drop-menu"});
	   benefits.load(lang+"/menus/menu-benefits/");
	   benefits.inject("bt_benefits");
	   benefits.hide();	
	   
	   var company = new Element('div', {"id": "company", "class": "drop-menu"});
	   company.load(lang+"/menus/menu-company/");
	   company.inject("bt_company");
	   company.hide();	
	   
	   var search = new Element('div', {"id": "search-results", "class": "drop-menu"});
	   search.hide();
	   search.inject("search-area");
	   
	   
	   $('search_input').value = $('search_input').getAttribute('placeholder');
	   $('search_input').addClass('placeholder');
	  
	  
	  $('search_input').addEvent('focus', function(){
	  		if(this.value == this.getAttribute('placeholder')){
	  			this.value = "";
	  			this.removeClass('placeholder');
	  		}
	  });
	  
	  $('search_input').addEvent('blur', function(){
	  		if(this.value == ""){
	  			this.value = this.getAttribute('placeholder');
	  			this.addClass('placeholder');
	  			search.hide();
	  		}
	  });
	  
	  $('search_input').addEvent('keyup', function(){
	    	ajaxSearch(this.value);
	  });
	  
	  $('search_input').addEvent('change', function(){
	    	ajaxSearch(this.value);
	  });
	  
	  
	  function ajaxSearch(input){
	  		if(dmenus == 0){
		  		var inp = input;
		    	if(inp.length > 4){
		    		search.load(lang+"/ajax-search/?search="+inp);
		    		search.show();
		    	} else {
		    		search.hide();
		    	}
	    	}
	  }
	  // MENU SCRIPTS
	  
	  Element.implement({
	    show: function() {
	      this.setStyle('display','');
	    },
	    hide: function() {
	      this.setStyle('display','none');
	    }
	  });
	  
	  $('bt_products').addEvent('mouseover', function(){
	    	if(dmenus == 0)
	    		$('products').show();
	    	this.addClass('hover');
	  });
	  $('bt_products').addEvent('mouseout', function(){
	    	if(dmenus == 0)
	    	 	$('products').hide();
	    	this.removeClass('hover');
	  });
	  $('bt_benefits').addEvent('mouseover', function(){
	    	if(dmenus == 0)
	    		$('benefits').show();
	    	this.addClass('hover');
	  });
	  $('bt_benefits').addEvent('mouseout', function(){
	    	if(dmenus == 0)
	    		$('benefits').hide();
	    	this.removeClass('hover');
	  });
	  $('bt_company').addEvent('mouseover', function(){
	    	if(dmenus == 0)
	    		$('company').show();
	    	this.addClass('hover');
	  });
	  $('bt_company').addEvent('mouseout', function(){
	    	if(dmenus == 0)
	    		$('company').hide();
	    	this.removeClass('hover');
	  });
  
  });
  
 function closeSearch(){
	    	$('search_input').value = $('search_input').getAttribute('placeholder');
	  		$('search_input').addClass('placeholder');
	  		$('search-results').hide();
}
	  
