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();
			}
		});
	});
}
window.addEvent('domready', fDelete);

function del( Obj ) {
	var label = ( Obj.title ) ? Obj.title : 'Etes vous sûr de vouloir supprimer cet élément ?';
	return confirm( label );	
}

function addressChangeConfirm( Obj ) {
	var label = ( Obj.title ) ? Obj.title : 'Confirmez vous le changement d\'adresse de cet abonnement ?';
	return confirm( label );	
}

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, 580 );
}

function fFlashMessage() {
	new mooFlashMessage($$('.flash'));
}
window.addEvent('domready', fFlashMessage);



window.addEvent('domready', function(){
	$$('.blink1').each(function(el, i){
		var effect = el.effect('opacity', {duration: 600});
		$$('.blink2').setOpacity(0);
		
		effect.start('0').chain(function() {
			effect.start('1').chain(function() {
				effect.start('0').chain(function() {
					effect.start('1').chain(function() {
						effect.start('0').chain(function() {
							effect.start('1');
							
							$$('.blink2').each(function(el, i){
								var effect = el.effect('opacity', {duration: 600});
								effect.start('1').chain(function() {
									effect.start('0').chain(function() {
										effect.start('1').chain(function() {
											effect.start('0').chain(function() {
												effect.start('1');
											});
										});
									});
								});
							});
							
						});
					});
				});
			});
		});
	});
	
}); 


function initHome(){
	// Mousemove
	/*
	var scrollLeft = new Scroller('moveleft', {area: 13, velocity: 1, onChange: function(x, y){ console.log(x, y); }});
	$('moveleft').addEvent('mouseenter', scrollLeft.start.bind(scrollLeft));
	$('moveleft').addEvent('mouseleave', scrollLeft.stop.bind(scrollLeft));	
	
	var scrollRight = new Scroller('moveright', {area: 13, velocity: 1, onChange: function(x, y){ console.log(x, y); }});
	$('moveright').addEvent('mouseenter', function(){ scroll.start.bind(scrollRight); console.log('moveright start'); } );
	$('moveright').addEvent('mouseleave', function(){ scroll.stop.bind(scrollRight); console.log('moveright stop'); });
	*/
	
	var scroll = new Scroller('mousemove', {area: 100, velocity: 1});
	$('mousemove').addEvent('mouseenter', scroll.start.bind(scroll));
	$('mousemove').addEvent('mouseleave', scroll.stop.bind(scroll));	

	var fxs = [];
	$$('.imgmac').each(function(div, i){
		fxs[i] = new Fx.Styles(div.getElements('img').shift(), {duration: 300, transition: Fx.Transitions.linear, wait: false});
		div.addEvents({
			mouseenter: function(){
				fxs[i].start({
					'margin-top': 0,
				    'height': 110,
				    'width': 160
				});
			},
			mouseleave: function(){
				fxs[i].start({
					'margin-top': 15,
				    'height': 80,
				    'width': 130
				});	
			}
		});
	});
}

function marqueeInit(){
	if($('marqueebox')){
		new mooMarquee($('marqueebox'), $$('#marqueebox .marquee'), {'waitDuration': 7000});
	}
	if($('marqueepromo')){
		new mooMarquee($('marqueepromo'), $$('#marqueepromo .marquee'), {'waitDuration': 7000});
	}
}
window.addEvent('domready', marqueeInit);

function initMenu(){
	new mooMenu($('menu'));
}
window.addEvent('domready', initMenu());
function clearInput(inputid,inputvalue) {
	if (document.getElementById(inputid).value==inputvalue)
		document.getElementById(inputid).value="";
}



function changeMenuOptions( menu, idp ) {
	var menuObj = document.getElementById( menu );
	$('p'+menu).setStyle('display','block');
	if( menuObj ) {
		clearAll( menu );
		menuObj.disabled = false;
		//menuObj.options[0] = new Option( "", "" );
		for( var i=0; i<productsoptions.length; i++ ) {
			if( productsoptions[i].productid == idp ) {
				menuObj.options[ menuObj.length ] = new Option( html_entity_decode(productsoptions[i].charcol), productsoptions[i].id );
			}
		}
		if( menuObj.length < 1 ) {
			$('p'+menu).setStyle('display','none');
			menuObj.disabled = true;
		}
	}
}
function changeMenuSsOptions( menu, ido ) {
	var menuObj = document.getElementById( menu );
	$('p'+menu).setStyle('display','block');
	if( menuObj ) {
		clearAll( menu );
		menuObj.disabled = false;
		//menuObj.options[0] = new Option( "", "" );
		for( var i=0; i<productsssoptions.length; i++ ) {
			if( productsssoptions[i].optionid == ido ) { 
				menuObj.options[ menuObj.length ] = new Option( html_entity_decode(productsssoptions[i].charoption), productsssoptions[i].id );
			}
		}
		if( menuObj.length < 1 ) {
			$('p'+menu).setStyle('display','none');
			menuObj.disabled = true;
		}
	}
}
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 clearAll( menu ) {			
	var menuObj = document.getElementById( menu );			
	for( var j=menuObj.length; j>=0; j-- ) {
		menuObj.options[j] = null;
	}
	menuObj = null;
}
