/*
 * Accordion.js v0.3 - Creates a Accordion UI element from a definition list
 *
 * AUTHOR: 	C. James Callaway <TehTreag@CyberGod.net>
 * WEBSITE:	http://www.CyberGod.net
 * DATE:   	Wed Sep 12 00:23:16 CDT 2007
 *
 * LICENSE:	This work is licensed under a Creative Commons
 *		Attribution 3.0 License
 *		http://creativecommons.org/licenses/by/3.0/
 *
 *------------------------------------------------------------------------
 *
 */
Accordion = Class.create();
Accordion.prototype = {
    initialize: function(elem) {
	this.options = Object.extend({
	      activeElement: null,
	      activeIndex: 1,
	      effect: 'blind',
	      duration: 0.2,
	      activeClassName: 'active',
	      onActivate: null
	    }, arguments[1] || {});
	var children = $$('#' + elem + ' > dt');
	children.invoke('observe','click',
			this._activateByEvent.bindAsEventListener(this))
		.invoke('next')
		.invoke('hide');
	this.activePanel = (this.options.activeElement)
		? $(this.options.activeElement)
		: children[this.options.activeIndex - 1];

	this.activePanel.addClassName(this.options.activeClassName)
		.next().show().addClassName(this.options.activeClassName);
    },
    _activateByEvent: function(event) {
	this.activate(Event.element(event));
    },
    activate: function(panel) {
	var panel = $(panel);
	if(panel != this.activePanel) {
	    if (this.options.onActivate && !this.options.onActivate(panel)) {
		return;
	    }
	    if (this.options.effect == 'blind') {
		new Effect.Parallel (
		    [
			new Effect.BlindUp(this.activePanel.next()),
			new Effect.BlindDown(panel.next())
			], {duration: this.options.duration});
	    } else if (this.options.effect == 'slide') {
		new Effect.Parallel (
		    [
			new Effect.SlideUp(this.activePanel.next()),
			new Effect.SlideDown(panel.next())
			], {duration: this.options.duration});
	    } else {
		this.activePanel.next().hide();
		panel.next().show();
	    }
	    panel.addClassName(this.options.activeClassName);
	    this.activePanel.removeClassName(this.options.activeClassName)
	    	.next().removeClassName(this.options.activeClassName);
	    this.activePanel = panel;
	}
    }
}

function initEvent(e) {
	Event.stop(e);
	var navBar = new Accordion( 'acc1' ,
		{
			activeElement: 'home',
			activeElement: $('home'),
	    activeIndex: 2,
	    animate:true,
	    activeClassName: "activePanel",
	    effect:"blind",
	    onActivate:function(element){ return true; },
	    duration:0.3
		});

	// Accordeon des nouveautes
	if ( $('acc2') )
		var navBar1 = new Accordion( 'acc2' ,
		{
			activeElement: 'home',
			activeElement: $('home'),
	    activeIndex: 2,
	    animate:true,
	    activeClassName: "activePanel",
	    effect:"blind",
	    onActivate:function(element){ return true; },
	    duration:0.3
		});

	//Boite de configuration de l'accordeon
	Event.observe('conf', 'click', function(){
		win =	new Window( {
			url: "http://www.zicanotes.com/popup/window_conf_acc.php",
			className: "spread",
			minWidth:400,
			minHeight:300,
			maxHeight:300,
			width:400,
			height:300,
			title: "Personnalisation des évènements",
			effectOptions: {duration:0.5},
			destroyOnClose:"true"
		} ) ;
		win.showCenter();
	} );
}
/** Accordeon */
Event.observe(window,'load',initEvent);
//Permettra de fermer la fenêtre de configuration
function closeWin(){
	win.close();
	window.location.href = window.location.pathname;
}