var menuNavigationFacileScroll;


function mxc_menuNavigationFacile(tabCouleur, idMenuFacile, idBlocParent, listeBloc) {
    if(mxc_existScroll(idBlocParent, listeBloc)) { // test si exitence de la scrollbarre pour afficher le menu facile
        if ($(idMenuFacile) != null) return;

    	var divMenuFacile = new Element('div',  {'id' : idMenuFacile}).addClass(tabCouleur);
            divMenuFacile.injectInside(document.body);
            divMenuFacile.initialTop = window.getHeight() / 2;

        if(!window.ie6) {
            divMenuFacile.setStyles({top: divMenuFacile.initialTop, 'position': 'fixed'});
            menuNavigationFacileScroll = new mxc_scroller({milliseconds : 50});
        } else {
            divMenuFacile.setStyles({top: window.getScrollTop() + divMenuFacile.initialTop});
            menuNavigationFacileScroll = new mxc_scroller({compensate : divMenuFacile, milliseconds : 50});
        }

        var imgTop = new Element('img',  {'src' : '/z.gif', 'title' : 'Haut de page'}).addClass('h-facile').injectInside(divMenuFacile);
        var imgScrollTop = new Element('img',  {'src' : '/z.gif', 'title' : 'Monter'}).addClass('hscroll-facile').injectInside(divMenuFacile);
        var imgScrollBottom = new Element('img',  {'src' : '/z.gif', 'title' : 'Descendre'}).addClass('bscroll-facile').injectInside(divMenuFacile);
        var imgBottom = new Element('img',  {'src' : '/z.gif', 'title' : 'Bas de page'}).addClass('b-facile').injectInside(divMenuFacile);

        imgTop.addEvent('click', function(){
			window.scrollTo(0,0);
		});
        imgScrollTop.addEvent('mousedown', function(){
			menuNavigationFacileScroll.startScrollUp();
		});
        imgScrollBottom.addEvent('mousedown', function(){
			menuNavigationFacileScroll.startScrollDown();
		});
        imgBottom.addEvent('click', function(){
			window.scrollTo(0,document.body.offsetHeight);
		});

		// effet de fadding sur les boutons
        var list_btNavigationFacile = $$('#' + idMenuFacile +' img');
    	list_btNavigationFacile.each(function(element) {
    		var fx = new Fx.Styles(element, {duration:200, wait:false});
    		fx.start({'opacity': .5});
    		element.addEvent('mouseenter', function(){
    			fx.start({
    				'opacity': 1
    			});
    		});
    		element.addEvent('mouseleave', function(){
    			fx.start({
    				'opacity': .5
    			});
    		});
    	});
    } else if($(idMenuFacile) != null) {
        $(idMenuFacile).remove();
    }
}

// test si contenant est superieur a la taille de la fenetre alors existence d'une scrollbar
// listeBloc peut etre vide ou est un tableau d'ID de bloc et calcul la hauteur des blocs a cumuler
function mxc_existScroll(idBlocParent, listeBloc) {
	var isScroll = false;
	var wiHeight = window.getHeight();

	var heightListeBloc = 0;
	if(listeBloc != undefined) {
	    for(i = 0 ; i < listeBloc.length ; i++) {
	        heightListeBloc += $(listeBloc[i]).getCoordinates().height;
	    }
	}

	// test si existence du bloc contenant et test sur la taille Totale cumulée:
	// afin de tester exixtence de la scrollbarre (ex : pour le menu-navigation-facile)
	if($(idBlocParent) != null) {
    	var structureHeight = heightListeBloc + $(idBlocParent).getCoordinates().height;
    	if(structureHeight > wiHeight) {
    		isScroll =  true;
    	}
	}
	return isScroll;
}


///////////////////////////////////////////////////////////
// TODO QCM POUR BRC
/*
function mxc_menuNavigationFacileQCM(mxcSession) {
	var divMenuFacileQCM = new Element('div',  {'id' : 'menuNavigationFacileQCM'}).addClass('menuNavigationFacileQCM');
        divMenuFacileQCM.injectInside(document.body);
	var divMenuFacileBoutonsQCM = new Element('div',  {'id' : 'menuNavigationFacileBoutonsQCM'}).addClass('bouton-proposition');
        divMenuFacileBoutonsQCM.injectInside(divMenuFacileQCM);

    var imgBouton1 = new Element('img',  {'src' : '/i/site/navigation/qcm/1.gif', 'title' : 'Réponse 1'}).injectInside(divMenuFacileBoutonsQCM);
    var imgBouton2 = new Element('img',  {'src' : '/i/site/navigation/qcm/2.gif', 'title' : 'Réponse 2'}).injectInside(divMenuFacileBoutonsQCM);
    var imgBouton3 = new Element('img',  {'src' : '/i/site/navigation/qcm/3.gif', 'title' : 'Réponse 3'}).injectInside(divMenuFacileBoutonsQCM);
    var imgBouton4 = new Element('img',  {'src' : '/i/site/navigation/qcm/interrogation.gif', 'title' : 'Je ne sais pas'}).injectInside(divMenuFacileBoutonsQCM);

    imgBouton1.addEvent('click', function(){document.location = '?' + mxcSession + '&act=reponse&proposition=0';});
    imgBouton2.addEvent('click', function(){document.location = '?' + mxcSession + '&act=reponse&proposition=1';});
    imgBouton3.addEvent('click', function(){document.location = '?' + mxcSession + '&act=reponse&proposition=2';});
    imgBouton4.addEvent('click', function(){document.location = '?' + mxcSession + '&act=reponse&proposition=-1';});

    imgBouton1.addEvent('mouseenter', function(){showSelectionQCM('0');});
    imgBouton2.addEvent('mouseenter', function(){showSelectionQCM('1');});
    imgBouton3.addEvent('mouseenter', function(){showSelectionQCM('2');});
	imgBouton4.addEvent('mouseenter', function(){showSelectionQCM('autre');});

    imgBouton1.addEvent('mouseleave', function(){hideSelectionQCM();});
    imgBouton2.addEvent('mouseleave', function(){hideSelectionQCM();});
    imgBouton3.addEvent('mouseleave', function(){hideSelectionQCM();});
    imgBouton4.addEvent('mouseleave', function(){hideSelectionQCM();});

    var elemDatePos = $('date').getCoordinates();
    divMenuFacileQCM.initialTop = elemDatePos.top+3 ;

    if(!window.ie6) {
        divMenuFacileQCM.setStyles({top: divMenuFacileQCM.initialTop, left: elemDatePos.left+55, 'position': 'fixed'});
        //menuNavigationFacileQCMScroll = new mxc_scroller();
    } else {
        divMenuFacileQCM.setStyles({top: window.getScrollTop() + divMenuFacileQCM.initialTop, left: elemDatePos.left+55});
        //menuNavigationFacileQCMScroll = new mxc_scroller({compensate : divMenuFacileQCM});
    }
}

function showSelectionQCM(p) {
    $('iprop' + p).setProperty('src', '/i/exercices/qcm/prop_sel.gif');
    $('tdprop' + p).addClass('border-green');
}
function hideSelectionQCM() {
    $ES('.img-prop').each(function (el) {el.setProperty('src', '/i/exercices/qcm/prop_unsel.gif');});
    $ES('.td-prop').each(function (el) {el.removeClass('border-green');});
}
*/