function fDelete(){
	$$('.fDelete').each(function(el){
		el.addEvent('click', function(e){
			e = new Event(e);
			if( !confirm(el.title ? el.title : 'Etes vous sûr de vouloir supprimer cet élément ?')){
				e.stop();
			}
		});
	});
}

function fFlashMessage() {
	new mooFlashMessage($$('.flash'));
}

function accordeon(){
	if(!$('accordion')) {
		return;
	}
	var elementActif = -1;
	if (window.location.hash.length > 1) {
		elementActif = parseInt(window.location.hash.substr(1,window.location.hash.length-1), 10);
	}
	var accordion = new Accordion('.toggler', '.element', {
		opacity: false,
		show: elementActif,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#264f89');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#264f89');
		}
	}, $('accordion'));
}

function fMenu() {
	new mooMenu($('menu'));
}

function html_entity_decode( string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    var ret, tarea = document.createElement('textarea');
    tarea.innerHTML = string;
    ret = tarea.value;
    return ret;
}

function fSchoolOptions() {
	var optionCheckbox = $('product-options');
	var optionsCheckboxes = $$('.product-option');
	if (optionCheckbox && optionsCheckboxes) {
		optionCheckbox.addEvent('click', function(e){
			var isCheck = optionCheckbox.getProperty('checked');
			optionsCheckboxes.each(function(el){
				el.setProperty('checked', isCheck);
			});
		});
	}
}
 
 /*  height equalize  */
var Equalizer = new Class({
	initialize: function(elements) {
		this.elements = $$(elements);
	},
	equalize: function(hw) {
		if(!hw) { hw = 'height'; }
		var max = 0,
			prop = (typeof document.body.style.maxHeight != 'undefined' ? 'min-' : '') + hw; //ie6 ftl
			offset = 'offset' + hw.capitalize();
		this.elements.each(function(element,i) {
			var calc = element[offset];
			if(calc > max) { max = calc; }
		},this);
		this.elements.each(function(element,i) {
			element.setStyle(prop,max - (element[offset] - element.getStyle(hw).toInt()));
		});
		return max;
	}
});

/* egalisation des hauteurs */
function equalize() {
var columnizer = new Equalizer('.wrap-product').equalize('height'); //call .equalize() as often as you want!
var columnizer = new Equalizer('.wrap-product .illus').equalize('height'); //call .equalize() as often as you want!
var columnizer = new Equalizer('.optionBlock').equalize('height'); //call .equalize() as often as you want!
var columnizer = new Equalizer('.optionBlock h3').equalize('height'); //call .equalize() as often as you want!
var columnizer = new Equalizer('.optionBlock img').equalize('height'); //call .equalize() as often as you want!
}
window.addEvent('domready', equalize);
 
function fInit(){
	fDelete();
	fFlashMessage();
	accordeon();
	fMenu();
	fSchoolOptions();
	formHiddenLabelInit();
}
window.addEvent('domready', fInit);


function popup( href, name, h, l ) {
	var hauteur = Math.round( ( screen.availHeight - h ) / 2 );
	var largeur = Math.round( ( screen.availWidth - l ) / 2 );
	var popup = window.open( href, name, 'toolbar=0,location=0,directories=0,status=0, scrollbars=1,resizable=1,menubar=0,top='+hauteur+',left='+largeur+',width='+l+',height='+h);
	popup.focus();
	return false;	
}

function popupOrder( Obj ) {
	return popup(Obj.href, 'order', 600, 980);
}

function popupExplain( Obj ) {
	return popup(Obj.href, 'explain', 600, 580);
}

function popupOption( Obj ) {
	return popup(Obj.href, 'explain', 500, 750);
}
