if (!Kwo) var Kwo = {};

Hammel = {
  Class: {},

  sizeDialog: function(elt) {
    elt = $(elt);
    var support = elt.up('.dialog-support');
		if (!support) return;
    var content = support.down('.modal-content');
    content.setStyle({height: (support.getHeight() - 100) + 'px'});
  }
};

// ----------
Hammel.Menu = {
  current: null,

  onDisplay: function(elt) {
    elt = $(elt).up('li.universe').down('a');
    if (elt.hasClassName('selected')) {
      return Hammel.Menu.onHide(elt);
    }
    $('menu').select('li.universe a.selected').each(function(el) {
      el.removeClassName('selected');
      el.next('.submenu').hide();
    });
    elt.addClassName('selected');
    elt.next('.submenu').show();

    Hammel.Menu.current = $(elt);
    $$('body')[0].observe('mouseover', function(event){
      clicked = Event.element(event);
      if (!clicked.ancestors().include($('menu'))) {
        Hammel.Menu.onHide(Hammel.Menu.current);
      }
    });
  },

  onHide: function(elt) {
    elt = $(elt);
    elt.removeClassName('selected');
    elt.next('.submenu').hide();
  }
};

// ----------
Hammel.Article = {
  onFilter: function(args) {
    args = $(args);
    if ($('allSegments').checked==true) {
      $$('.segment-filters').each(function(elt) {
        elt.checked=false;
      });
    }
    $("grid").update('<div class="loader"><img src="/app/hammel/pix/ico-loader.gif" alt="" /></div>');
    Kwo.exec('/produits.list', args, {container: "grid", progress: true});
  },

  onZoom: function(elt) {
    var img = $(elt).down('img');
    new Kwo.Dialog("/article.image",
                   {"article_id": elt.readAttribute("data-id")},
                   {width: (parseInt(img.readAttribute("data-width")) + 60),
                    height: (parseInt(img.readAttribute("data-height")) + 100),
                    name: "zoom"});
  },

  onTabChange: function(tab) {
    var elt = $(tab);
    elt.up('.tabs').select('li.tab').each(function(tab) {
      tab.down('a').removeClassName('selected');
    });
    elt.addClassName('selected');
    $("tab-content").update('<div class="tab-loader"><img src="/app/hammel/pix/ico-loader.gif" alt="" /></div>');
  },

  onRefsList: function(elt) {
    Hammel.Article.onTabChange(elt);
    Kwo.exec('/article.references.box',
             {id: elt.readAttribute('data-id')},
             {container: 'tab-content'});
  },

  onSparesList: function(elt) {
    Hammel.Article.onTabChange(elt);
    Kwo.exec('/article.spares.box',
             {id: elt.readAttribute('data-id')},
             {container: 'tab-content'});
  },

  onRelatedList: function(elt) {
    Hammel.Article.onTabChange(elt);
    Kwo.exec('/article.related.box',
             {id: elt.readAttribute('data-id')},
             {container: 'tab-content'});
  }
};

// ----------
Hammel.Newsletter = {
  onSubmit: function(args) {
    Kwo.exec("/push/newsletter.subscribe", args,
             {callback: Hammel.Newsletter.onCallback.bind(args), disable: true});
  },

  onCallback: function(res) {
    if (Kwo.hasError(res)) return Kwo.error(res);
    $$('#newsletter span.inputs')[0].addClassName("confirmation").update(res["result"]["callback_msg"].ucfirst());
  }
};

// ----------
Hammel.Contact = {
  onMessageSend: function(elt) {
    elt = $(elt);
    Kwo.exec("/contact.send", elt,
             {'callback': elt.up('.callback-container'), disable: true});
  },

  onWcbRequest: function(elt) {
    elt = $(elt);
    Kwo.exec("/contact.wcb.send", elt, {"callback": elt.up('.callback-container'), disable: true});
  }
};

// ----------
Hammel.Devis = {
  onMessageSend: function(elt) {
    elt = $(elt);
    Kwo.exec("/devis.send", elt, {callback: elt.up(".callback-container"), disable: true});
  }
};

// ----------
Hammel.Catalog = {
  onOpen: function(elt) {
    elt = $(elt);
    new Kwo.Dialog("/catalogue",
                   {"code": elt.readAttribute("data-code")},
                   {width:980, height:800, name: "catalog"});
  }
};

// ----------
Hammel.FirstLog = {
  onOpen: function() {
    new Kwo.Dialog("/firstlog", null, {width:450, height:300, name: "firstlog"});
  }
};

// ----------
Hammel.Class.Snippet = Class.create(Kwo.Dialog, {
  initialize: function($super, code) {
    this.name = "snippet";
    this.className = "layout-hbox";
    this.args = {code: code};
    this.width = 600;
    this.height = 620;
    $super(this.onDisplay);
  },

  onDisplay: function() {
    Kwo.exec("/sys/snippet", this.args, {container: this.support});
  }
});

// ----------
Hammel.Service = {
  onOverview: function(elt) {
    elt = $(elt);
    new Kwo.Dialog("/account/hammel/service",
                   {"id": elt.readAttribute("data-id")},
                   {width:600, height:400, name:"service"});
  },
  onConfirm: function(args) {
    args = $(args).up('form');
    var check_count = 0;
    args.select('.checkbox-inp').each(function(el) {
      if (el.checked === true) check_count++;
    });

    if (check_count > 0) {
      new Kwo.Dialog("/account/hammel/service.confirm", args,
                     {width:450, height:250, name:"service"});
    }
    else {
      alert('Veuillez sélectionner au moins un service');
    }
  },

  onSend: function(args) {
    Kwo.exec("/account/hammel/service.send", args, {callback: true});
  }
};

// ----------
Hammel.Cadeau = {
  onOverview: function(elt) {
    elt = $(elt);
    new Kwo.Dialog("/account/hammel/cadeau",
                   {"id": elt.readAttribute("data-id")},
                   {width:600, height:400, name:"cadeau"});
  },
  onConfirm: function(args) {
    args = $(args).up('form');
    var check_count = 0;
    args.select('.checkbox-inp').each(function(el) {
      if (el.checked === true) check_count++;
    });

    if (check_count > 0) {
      new Kwo.Dialog("/account/hammel/cadeau.confirm", args,
                     {width:450, height:250, name:"cadeau"});
    }
    else {
      alert('Veuillez sélectionner au moins un cadeau');
    }
  },

  onSend: function(args) {
    Kwo.exec("/account/hammel/cadeau.send", args,
             {callback: Kwo.reload, disable: true});
  }
};

// ----------
Hammel.AdvancedSearch = {
  current: 0,
  onGetUniversChildren: function(value) {
    if (value==0) {
      $('famille-select').update("<option value='0'>toutes</option>");
      return false;
    }
    args = {'famille_id':value}
    Kwo.exec("/hammel/get.familles",args, {callback: Hammel.AdvancedSearch.onUniversCallBack});
  },
  onGetFamilleChildren: function(value) {
    if (value==0) {
      $('sous-famille-select').update("<option value='0'>toutes</option>");
      return false;
    }
    args = {'famille_id':value}
    Kwo.exec("/hammel/get.familles",args, {callback: Hammel.AdvancedSearch.onFamilleCallBack});
  },
  onGetSegmentChildren: function(value) {
    if (value==0) {
      $('gamme-select').update("<option value='0'>toutes</option>");
      return false;
    }
    args = {'famille_id':value}
    Kwo.exec("/hammel/get.segments",args, {callback: Hammel.AdvancedSearch.onSSFamilleCallBack});
  },
  onMakeFilter: function(args) {

  },
  onUniversCallBack: function(res) {
    if (Kwo.hasError(res)) {
      return Kwo.error(res);
    }
    elt= $('famille-select');
    elt.length = 0;
    elt.insert("<option value='0'>toutes</option>");
    $H(res["result"]["values"]).each(function (pair) {
       elt.insert("<option value='"+pair.key+"'>"+pair.value+"</option>");
    });
    elt.selectedIndex = 0;
  },
  onFamilleCallBack: function(res) {
    if (Kwo.hasError(res)) {
      return Kwo.error(res);
    }
    elt= $('sous-famille-select');
    elt.length = 0;
    elt.insert("<option value='0'>toutes</option>");
    $H(res["result"]["values"]).each(function (pair) {
       elt.insert("<option value='"+pair.key+"'>"+pair.value+"</option>");
    });
    elt.selectedIndex = 0;
  },
  onSSFamilleCallBack: function(res) {
    if (Kwo.hasError(res)) {
      return Kwo.error(res);
    }
    elt= $('gamme-select');
    elt.length = 0;
    elt.insert("<option value='0'>toutes</option>");
    $H(res["result"]["values"]).each(function (pair) {
       elt.insert("<option value='"+pair.key+"'>"+pair.value+"</option>");
    });
    elt.selectedIndex = 0;
  },
  onAddFilter: function () {
    if ($F('univers-select')=='0') {
      alert('Veuillez sélectionner au moins un critère');
      return false;
    }
    if (Hammel.AdvancedSearch.current==0) {
      $('filters-wrapper').update('');
    }
    var textContent = '';
    if ($F('gamme-select')=='0') {
      textContent = '> Toutes les gammes';
    } else {
      textContent += '> '+$('gamme-select').options[$('gamme-select').selectedIndex].innerHTML;
    }
    if ($F('sous-famille-select')=='0') {
      textContent = '> Toutes les sous-familles ';
    } else {
      textContent = '> '+$('sous-famille-select').options[$('sous-famille-select').selectedIndex].innerHTML+' '+textContent;
    }
    if ($F('famille-select')=='0') {
      textContent = '> Toutes les familles ';
    } else {
      textContent = '> '+$('famille-select').options[$('famille-select').selectedIndex].innerHTML+' '+textContent;
    }
    if ($F('univers-select')=='0') {
      textContent = ' Tous les univers';
    } else {
      textContent = $('univers-select').options[$('univers-select').selectedIndex].innerHTML+' '+textContent;
    }
    var value = $('form-make-filter').serialize(true);
    var inputFilter = new Element('input',
                                  {'type':'hidden',
                                   'name':'filtres[]',
                                   'value':Object.toJSON(value) });
    var div = new Element('div',{'class':'hammel-search-filter'}).update(textContent);
    var divWhere = new Element('div',
                                {'class':'hammel-search-filter-where'}).update((Hammel.AdvancedSearch.current>0)?'ou':'Au sein de :');
    var divBlock = new Element('div',{'class':'hammel-search-filter-block' }).insert(divWhere);
    var imgSuppr = new Element('img',{'src':'/app/hammel/pix/btn-empty-cart.png'});
    var deleteBtn = new Element('a',
                                {'class':'hammel-search-filter-delete',
                                 'href':'javascript:void(0)',
                                 'onclick':'Hammel.AdvancedSearch.onDeleteFilter(this)',
                                 'title':'supprimer le filtre'}).update(imgSuppr);
    div.insert(inputFilter);
    div.insert({'top':deleteBtn});
    divBlock.insert(div)
    $('filters-wrapper').insert(divBlock);
    Hammel.AdvancedSearch.current++;
    $('form-make-filter').reset();
    $('famille-select').update('<option value="0">toutes</value>');
    $('sous-famille-select').update('<option value="0">toutes</value>');
    $('gamme-select').update('<option value="0">toutes</value>');
  },
  onDeleteFilter: function(elt) {
    var elt = $(elt);
    var filter = elt.up('.hammel-search-filter-block');
    Hammel.AdvancedSearch.current--;
    filter.remove();
    if (Hammel.AdvancedSearch.current==0) {
      $('filters-wrapper').update('<p>Ajouter un filtre pour effectuer une recherche.</p><input type="hidden" name="nofilter" value="1" />');
    } else {
      $$('div.hammel-search-filter-block')[0].down('div.hammel-search-filter-where').update('Au sein de');
    }
  }
};


// ----------
SlideShow = Class.create({
  "timeout": null,
  "mask": null,
  "nav": null,
  "count": 0,
  "pos": 0,
  "z": 1,
  "slides": [],
  "initialize": function (id, opts) {
    this.pos = 0;
    this.mask = $(id);
    this.width = this.mask.getWidth();
    this.slides = this.mask.childElements();
    this.slides.invoke('setStyle',{left:'0px',zIndex:this.z++});
    this.slides[this.pos].setStyle({zIndex:this.z});
    if (this.slides.length > 1) {
      if (opts.prev && $(opts.prev)) {
        $(opts.prev).observe('click', this.prev.curry(null).bind(this));
      }
      if (opts.next && $(opts.next)) {
        $(opts.next).observe('click', this.next.curry(null).bind(this));
      }
      if (opts.nav && $(opts.nav)) {
        this.nav = opts.nav;
        $(this.nav).childElements().each(function(s, index) {
          $(s).observe('click', this.view.curry(index).bind(this));
        }, this);
      }
      this.pagination();
    }
    this.slides[0].down('img').observe('load', this.resize.curry(opts).bind(this));
    this.resize(opts);
  },
  "resize": function (opts) {
    var height = this.slides[0].childElements()[0].getHeight();
    this.mask.setStyle({height:height+"px"});
    this.slides.each(function(s, index) { $(s).setStyle({height:(height)+"px"}); }, this);
    if (opts.prev && $(opts.prev)) $(opts.prev).setStyle({marginTop:(height)+"px"});
    if (opts.next && $(opts.next)) $(opts.next).setStyle({marginTop:(height)+"px"});
    if (opts.nav && $(opts.nav)) $(opts.nav).setStyle({marginTop:(height)+"px"});
  },
  "view": function (pos) {
    if (pos > this.pos) {
      this.next(pos);
    } else if (pos < this.pos) {
      this.prev(pos);
    }
  },
  "next": function (pos) {
    if (this.slides[this.pos] && (this.slides[this.pos].style.left == '0px' || this.slides[this.pos].style.left == this.width+'px' || this.slides[this.pos].style.left == '-'+this.width+'px')) {
      emile(this.slides[this.pos].setStyle({left:'0px',zIndex:this.z++}), 'left:-'+this.width+'px', {duration: 400});
      if (Object.isNumber(pos) && pos >= 0) this.pos = pos;
      else this.pos++;
      if (this.pos > this.slides.length - 1) this.pos = 0;
      if (this.pos < 0) this.pos = this.slides.length - 1;
      if (this.slides[this.pos] && (this.slides[this.pos].style.left == '0px' || this.slides[this.pos].style.left == this.width+'px' || this.slides[this.pos].style.left == '-'+this.width+'px')) {
        emile(this.slides[this.pos].setStyle({left:this.width+'px',zIndex:this.z++}), 'left:0px', {duration: 400});
      }
      this.pagination();
    }
  },
  "prev": function (pos) {
    if (this.slides[this.pos] && (this.slides[this.pos].style.left == '0px' || this.slides[this.pos].style.left == this.width+'px' || this.slides[this.pos].style.left == '-'+this.width+'px')) {
      emile(this.slides[this.pos].setStyle({left:'0px',zIndex:this.z++}), 'left:'+this.width+'px', {duration: 400});
      if (typeof pos == 'number' && pos >= 0) this.pos = pos;
      else this.pos--;
      if (this.pos > this.slides.length - 1) this.pos = 0;
      if (this.pos < 0) this.pos = this.slides.length - 1;
      if (this.slides[this.pos] && (this.slides[this.pos].style.left == '0px' || this.slides[this.pos].style.left == this.width+'px' || this.slides[this.pos].style.left == '-'+this.width+'px')) {
        emile(this.slides[this.pos].setStyle({left:(this.width*(-1))+'px',zIndex:this.z++}), 'left:0px', {duration: 400});
      }
      this.pagination();
    }
  },
  "pagination": function () {
    var list = $(this.nav).select('*');
    list.each(function(s) { s.addClassName("selected"); });
    list[this.pos].removeClassName("selected");
  }
});

// ----------
Animation = Class.create({
  "pos": 1,
  "count": 0,
  "prev": 0,
  "timeout": null,
  "initialize": function(menu, opts) {
    this.pos = 1;
    this.count = $(menu).select('img.preview').length;
    //$(menu).select('img.preview').invoke('setStyle', {top:'0px', right:'0px', opacity:0});
    $(menu).select('img.preview').invoke('setStyle', {top:'0px', right:'0px', display:'none'});
    //$('anim-preview-'+this.pos).setStyle({opacity:1});
    $('anim-preview-'+this.pos).setStyle({display:'block'});

    if (this.count > 1) {
      $(menu).select('a.home-menu-tab').invoke('observe', 'mouseover', this.show.bind(this));
      $(menu).select('a.home-menu-tab').invoke('observe', 'mouseout', this.play.bind(this));
    }
    current_link = $('home-menu').down('li.home-menu-'+this.pos).down('a.home-menu-tab');
    current_link.toggleClassName('selected');
    this.play();
  },
  "play": function (evt) {
    this.timeout = window.setTimeout(this.show.curry(null).bind(this), 5000);
  },
  "pause": function () {
    if (this.timeout) window.clearTimeout(this.timeout);
  },
  "show": function(event) {
    if (event) {

      var elt = Event.element(event);
      if (elt.childElements().length>0) {
        elt = elt.childElements()[0];
      }
      this.prev = this.pos;
      this.pos = elt.readAttribute('class').replace('pos-','');//elt.readAttribute("data-pos");
    }
    else {
      this.prev = this.pos++;
      if (this.pos > this.count) this.pos = 1;
      else if (this.pos < 0) this.pos = this.count;
      var auto = true;
    }

    if (this.prev != this.pos) {
      current = $('anim-preview-'+this.prev);
      next = $('anim-preview-'+this.pos);

      current_link = $('home-menu').down('li.home-menu-'+this.prev).down('a.home-menu-tab');
      next_link = $('home-menu').down('li.home-menu-'+this.pos).down('a.home-menu-tab');

      current_link.toggleClassName('selected');
      new Effect.Fade(current, {from: 1, to: 0, duration: 0});
      next_link.toggleClassName('selected');
      new Effect.Appear(next, {from: 0, to: 1, duration: 0});
    }

    if (auto === true) {
      this.timeout = window.setTimeout(this.show.curry(null).bind(this), 5000);
    }
    else {
      if (this.timeout) window.clearTimeout(this.timeout);
    }
  }
});

/* Added by IRCF on 2011-04-12 : Accordion and Hammel.HomeBis */

/** Accordion v2.1
 *
 * Copyright (c) 2007 stickmanlabs
 * Additions (c) 2009 Thomas von Deyen
 * Author: Kevin P Miller | http://www.stickmanlabs.com
 * Additional Author: Thomas von Deyen | http://thomas.vondeyen.com
 * Prototype 1.6 fixes by the_coder via http://snipplr.com/view/5502/stickman-labs-accordion-updated-for-prototypejs-16-/
 *
 * Accordion is freely distributable under the terms of an MIT-style license.
 **/

if (typeof Effect == 'undefined') 
	throw("Accordion requires included script.aculo.us' effects.js library!");

/** 
 *  class Accordion(container[, options = {}]) -> Object
 *  - container (String | Element | CSSSelector): Containerelement of the accordion.
 *  - options (Object): options for Accordion.
 *  -- resizeSpeed (Integer): 8
 *  -- classNames (Object):
 *  --- toggle (String): The classname of the accordion toggle. Default = 'accordion_toggle'
 *  --- toggleActive (String): The classname of the active toggle. Default = 'accordion_toggle_active'
 *  --- content (String): The classname of the accordion content. Default = 'accordion_content'
 *  -- defaultSize (Object): Object with height and width values for fixed layout instead of auto height.
 *  -- direction: The direction of the accordion. Default = 'vertical'
 *  -- onEvent (String): The Eventname the toggle listens to. Default = 'click'
 *  -- afterComplete (Function): The Function to call after the Accordion animates.
 *  -- activeClosable (Boolean): Should the active Accordion be closable or not? Default = true.
 **/

var Accordion = Class.create();
Accordion.prototype = {
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	initialize: function(container, options) {
	  if (!$(container)) {
	    if (typeof(console) != 'undefined') {
	      console.error(container + " doesn't exist!");
	    }
	    return false;
	  }	  
		this.options = Object.extend({
			resizeSpeed: 8,
			classNames: {
				toggle: 'accordion_toggle',
				toggleActive: 'accordion_toggle_active',
				content: 'accordion_content'
			},
			defaultSize: {
				height: null,
				width: null
			},
			direction: 'vertical',
			onEvent: 'click',
			afterComplete: function(){},
			activeClosable: true
		}, options || {});
		this.duration = ((11 - this.options.resizeSpeed) * 0.15);
		var accordions = $$('#' + container + ' .' + this.options.classNames.toggle);
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {
			  accordion.onclick = function() {return false;};
			}
			if (this.options.direction == 'horizontal') {
				var options = {width: '0px', display: 'none'};
			} else {
				var options = {height: '0px', display: 'none'};
			}
			this.currentAccordion = $(accordion.next(0)).setStyle(options);
		}.bind(this));
	},
	
	/**
	 * Accordion.activate(toggle) -> null
	 * Activates an accordion
	 **/
	activate : function(accordion) {

		if (this.animating) {
			return false;
		}
		this.effects = [];
		this.currentAccordion = $(accordion.next(0));

		this.currentAccordion.setStyle({
			display: 'block'
		});
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);
		if (this.options.direction == 'horizontal') {
			this.scaling = $H({
				scaleX: true,
				scaleY: false
			});
		} else {
			this.scaling = $H({
				scaleX: false,
				scaleY: true
			});			
		}
		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate();
		} else {
		  this._handleAccordion();
		}
	},

	/** 
	 * Accordion.deactivate() -> null
	 * Deactivates an active accordion
	 **/
	deactivate : function() {
		var options = $H({
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
          height: 'auto',
					display: 'none'
				});				
				this.showAccordion = null;
				this.animating = false;
				this.options.afterComplete();
			}.bind(this)
		});
		if (this.options.activeClosable) {
  		this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
		  new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject());
		} else {
		  this.options.afterComplete();
		}
	},

	/**
	 * Accordion._handleAccordion() -> null
	 * Handles the open/close actions of the accordion
	 **/
	_handleAccordion : function() {
		var options = $H({
			sync: true,
			scaleFrom: 0,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			}
		});
		options.merge(this.scaling);
		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options.update(this.scaling).toObject())
		);
		if (this.showAccordion) {
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
			options = $H({
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal
			});
			options.merge(this.scaling);
			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject())
			);				
		}
    new Effect.Parallel(this.effects, {
			duration: this.duration, 
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			beforeStart: function() {
				this.animating = true;
			}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) {
					this.showAccordion.setStyle({
						display: 'none'
					});				
				}
				$(this.currentAccordion).setStyle({
				  height: 'auto'
				});
				this.showAccordion = this.currentAccordion;
				this.animating = false;
				this.options.afterComplete();
			}.bind(this)
		});
	}

};


Hammel.HomeBis = {
	init : function(menu,level){
		new Accordion(menu,{
			classNames:{
			  toggle: "accordion-toggle-"+level,
			  toggleActive: "accordion-toggle-active-"+level,
			  content: "accordion-content-"+level
		  }
		});
		var items = $(menu).childElements();
		items.each(function(item){
			var submenu = item.down('ul');
			if (submenu) Hammel.HomeBis.init(submenu.identify(),level+1);
		});
	}
}

Hammel.SearchAutocomplete = {
	init : function(){
		var options = { 
			serviceUrl:'/search.results.autocomplete',
			minChars:3, 
			maxHeight:400,
			width:450,
			deferRequestBy:100,
			onSelect: function(value, data){
				location.href = data;
			}
		};
		if ($('q')){
			$('q').autocomplete = false;
			new Autocomplete('q', options);
		}
		if ($('q2')){
			$('q2').autocomplete = false;
			new Autocomplete('q2', options);
		}
	}
}
Event.observe(window, 'load', Hammel.SearchAutocomplete.init, false);

