window.addEvent('domready', function(){
	// JS BODY CLASS
	$$('body').removeClass('no-js').addClass('js');
	
	// NAVIGATION :HOVER FIX
	$$('#header ul li').each(function(item){
		if(ul = item.getElement('ul')) ul.fade('hide');
		item.addEvents({
			'mouseenter': function(event){
				//this.addClass('hover');
				if(ul = item.getElement('ul')) ul.fade('in');
			},
			'mouseleave': function(event){
				//this.removeClass('hover');
				if(ul = item.getElement('ul')) ul.fade('out');
			}
		});
	});
	
	// SLIDESHOWS
	$$('div.slideshow').each(function(element){
		var simpleSlideShow = new SimpleSlideShow({
			slides: element.getChildren()
		});
		var next = function(){
			this.forward();
		}
		var periodical = next.periodical(5000, simpleSlideShow);
		element.addEvents({
			mouseenter: function(){
				$clear(periodical);
			},
			mouseleave: function(){
				periodical = next.periodical(5000, simpleSlideShow);
			}
		});
	});
	
	// ACCORDIONS
	if($('accordion')) new rAccordion('accordion', 'toggler', 'content', {
		alwaysHide: true,
		display: 0,
		onActive: function(toggle){
			toggle.addClass('open');
		},
		onBackground: function(toggle){
			toggle.removeClass('open');
		}
	});
	
	// REMOOZ
	$$('a.remooz', 'a[target=_top]').each(function(element) {
		var reMooz = new ReMooz(element, {
			centered: false,
			origin: element.getFirst(), 
			cutOut: false,
			opacityResize: 0,
			margin: 35,
			parse: 'rel'
		});
	});
	
	// TARGET-BLANK
	$$('a.target-blank', 'a[target=_blank]').addEvent('click', function(event){
		event.stop();
		window.open(this.get('href'));
	});
	
	// ALIGNS & BORDER
	$$('*[align=left]').removeProperty('align').addClass('align-left');
	$$('*[align=right]').removeProperty('align').addClass('align-right');
	$$('*[align=center]').removeProperty('align').addClass('align-center');
	$$('*[border=0]').removeProperty('border').addClass('no-border');
	$$('*[hspace=0]').removeProperty('hspace').addClass('no-margin');
	$$('*[vspace=0]').removeProperty('vspace').addClass('no-margin');
	
	$$('p.cart>a').addEvent('click', function(event){
		event.stop();
		new Request.JSON({url: this.href, onComplete: function(json, text){
			if(this.hasClass('delete')) this.getParent().getParent().dispose();
			else{
				var p = this.getParent();
				p.set('html', json.message);
				if(json.status == 'error') p.highlight('#e42e87', null, 'color');
				else p.highlight('#96bf0d', null, 'color');
			}
			//$('quicklinks-cart').getElement('a').set('text', 'Mon guide'+(json.cart != 0 ? ' ('+json.cart+')' : '')).highlight('#ffffff', null, 'color');
		}.bind(this)}).get();
	});
});

var rAccordion = new Class({
 
	initialize: function(container, toggleClass, elementClass, options){
		this.container = container;
		this.tClass = toggleClass;
		this.eClass = elementClass;
		this.options = options;
		this.selector = '#' + this.container + ' > .';
		this.makeAccordion();
	},
	
 
	makeAccordion: function(){
		new Accordion(
			$$(this.selector+this.tClass),
			$$(this.selector+this.eClass),
			this.options
		).addEvents({
			'onActive': function(toggle){
				if(toggle.getParent().getStyle('height') != 0) toggle.getParent().setStyle('height', '');
			},
			'onComplete': function(a){
				if ($defined(a)) {
					var height = 0;
					a.getParent().getChildren().each(function(e){
						height = height + e.offsetHeight;
					});
					if(height != a.getParent().offsetHeight && a.getParent().offsetHeight != 0)
						a.getParent().setStyle('height','');
				}
			}
		});
		this.selector += this.eClass + ' > .';
		if($defined($$(this.selector)[0])) this.makeAccordion();
	}
 
});
