/************************************************************************
 *  Fx matrix-editeur.com (animation titres, menus, images, scroll...)
 *  Avril 2007
 ************************************************************************/

var mSite = {
	testalert: function (){
		alert('Hello world !!');
	},

	start : function(){
		try {
			// message
			setTimeout("document.getElementById('message').innerHTML = '&nbsp;'",20000); // hide the user's msg after 20'
            mSite.createMenu();  // animation links
			mSite.makeAccordion();  // animation accordions
			// mSite.createBox();  // animation box
			//if(createImage){  // animation on images
				// mSite.createImage();
			//}
			// mSite.makeContent();  // animation balise 'content'
			mSite.pop(); // popup, non Mootools.
		}
		catch(e){
			alert(e);
		}
	},

	/**
	 * Interprétation du code et restart des effets graphiques du site
	 * (Cette fonction est appellée par les fonctions ajax)
	 */
	restart : function(javascript){
		try {
			eval(javascript);
			/*if(accordionMode == 1){
				window.accordionMode = 1;
			}else{
				window.accordionMode = 0;
			}*/

			mSite.start();  // lancement des animations
		}
		catch(e){
			alert(e);
		}
	},


	/** *******************
	*  Animation des blocs accordéons
	******************* */
	makeAccordion: function(){
		// affichage des articles en accordéons
		if(accordionMode){    // design accordionMode de la BD
			$$('#centre').each(function(el){
				new Accordion(el.getElements('.strech'), el.getElements('.strechable'),{'display': -1,'duration': 200,'alwaysHide':true});
				/* NOTE : la variable accordionMode est défini dans le controler php */
			});

		}
		/*
		// affichage des articles en mode tabMode
		if(tabMode){   // mode avec onglets
			var stretchers = document.getElementsByClassName('box2');
			var toggles = document.getElementsByClassName('tab');
			var myAccordion = new Fx.Accordion(
			toggles, stretchers, {opacity: false, height: true, duration: 600,  fixedHeight: 2000}
			);

			toggles.each(function(el){
				var overfxs = new Fx.Styles(el, {'duration': 200, 'wait': false});
				el.addEvent('mouseover', function(){
					overfxs.start({
					'margin-left': 8
					,'margin-right': 8
					});
				});
				el.addEvent('mouseout', function(){
					overfxs.start({
					'margin-left': 0
					,'margin-right': 1
					});
				});
			});
		} */

	} ,

        /** *******************
         *  Animation des liens des menus
         ******************* */
	createMenu: function(){
           var as = $$('.effects a');
           as.each(function(el){
          	var overfxs = new Fx.Styles(el, {'duration': 300, 'wait': false});
		el.addEvent('mouseover', function(){
                        overfxs.start({
				'padding-left': '15px',
				'padding-right': '15px'
			});
		});
		el.addEvent('mouseout', function(){
			overfxs.start({
				'padding-left': '2px',
				'padding-right': '10px'
			});
		});
            });

        },
        
        /** *******************
         *  Animation des box
         ******************* */
	createBox: function(){
           var as = $$('.squarebox');
           as.each(function(el){
           	var overfxs = new Fx.Styles(el, {'duration': 300, 'wait': false});
           	el.addEvent('mouseover', function(){
                	overfxs.start({
						'margin-top': '-10px'
					});
			});
		el.addEvent('mouseout', function(){
			overfxs.start({
				'margin-top': '0px'
			});
		});
       });

        },

	makeContent: function(){
		var timer = 0;
		var sideblocks = $$('#centre');

		var slidefxs = [];
		var colorfxs = [];

		sideblocks.each(function(el, i){
			el.setStyle('margin-top', '+400px');
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-top', {
				duration: 500,
				transition: Fx.Transitions.linear,
				wait: false
				/*,onComplete: mSite.createOverTitle.pass([el, i])*/
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);
		}, this);
	},

	/** *******************
	*  Animation des images
	******************* */
	createImage: function(){
		$$('#centre img').each(function(el){
			var overfxs = new Fx.Styles(el, {'duration': 200, 'wait': false});

			el.addEvent('mouseover', function(){
				overfxs.start({
				'width': '205px'
				});
			});
			el.addEvent('mouseout', function(){
				overfxs.start({
				'width': '200px'
				});
			});
		});
	},
	

	/** *******************
	* Gestion des popups
	******************* */
	pop: function()
	{
		var myAs = document.getElementsByTagName('a');
	    for (var a = 0; a < myAs.length; ++a) {
			// Si le lien a une classe de type pop
	        if (myAs[a].className == 'pop') {
	        	// on extrait l'id de la popup à partir du href
	            var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
				// si la popup existe on l'affiche (display block)
	            if (pop) {       
	                pop.style.display = 'none';
	                myAs[a].onclick = function() {
	                    thisPopup = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1))
	                    thisPopup.style.display = (thisPopup.style.display == 'none') ? 'block' : 'none';
	                    
	                    // si le lien à un nom 'dontgoup', on ne remonte pas à #
	                    if(thisPopup.getAttribute("name") != "dontgoup"){
	                    	return true;
	                    }
	                    return false;
	                };
					// on efface la popup en cliquant dessus
	                pop.onclick = function()
	                {
	                    this.style.display = 'none';
	                };
	            }
	        }
	    }
	},
	/** *******************
	* Gestion des menus
	******************* */
	menu: function(menu)
	{
		alert(menu);
	}
};

window.addEvent('domready', mSite.start);
//window.onload = function(e) {	mSite.start(); }
