window.addEvent('domready', function(){
	// Affichage du sous menu
	$$("#menu .submenu").each(function(item, index) {
		item.getParent().addEvents({
			'mouseover': function(e) { this.addClass("over"); },
			'mouseout': function(e) { this.removeClass("over"); }
		});
	});
	// Google Maps sur la page contact
	if($(document.body).hasClass("page-trouver"))
	{
		window.addEvent('load', function() {
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("GMap_canvas"));
				var etoIcon = new GIcon(G_DEFAULT_ICON);
				etoIcon.image = "images/pages/contact/map-eto.png";
				etoIcon.shadow = "images/pages/contact/map-shadow.png";
				etoIcon.iconSize = new GSize(32,32);
				var coordParis = new GLatLng(48.873816,2.337984);
				var coordRoubaix = new GLatLng(50.69296,3.16995);
				map.addOverlay(new GMarker(coordParis, { icon:etoIcon }));
				map.addOverlay(new GMarker(coordRoubaix, { icon:etoIcon }));
				map.setCenter(coordParis, 16);
				map.setUIToDefault();
				$("GMap_paris").addEvent("click", function() {
					map.panTo(coordParis);
				});
				$("GMap_roubaix").addEvent("click", function() {
					map.panTo(coordRoubaix);
				});
			}
		});
		window.addEvent('unload', function() { GUnload(); });
	}
});

var ScrollPanel = new Class({
	initialize: function(id){
		if($(id))
		{
			this.FxScroll = new Fx.Scroll(id, {
				wait: false,
				duration: 600,
				transition: Fx.Transitions.Quad.easeInOut
			});
			this.currentPanel = $(id).getFirst();
			this.FxScroll.toElement(this.currentPanel);
			this.position();
			this.setNavButtons();
			sp = this;
			$("previous").addEvent("click", function(event) {
				event = new Event(event).stop();
				if(sp.currentPanel.getPrevious())
				{
					sp.currentPanel = sp.currentPanel.getPrevious();
					sp.setNavButtons();
					sp.FxScroll.toElement(sp.currentPanel);
				}
			});
			$("next").addEvent("click", function(event) {
				event = new Event(event).stop();
				if(sp.currentPanel.getNext())
				{
					sp.currentPanel = sp.currentPanel.getNext();
					sp.setNavButtons();
					sp.FxScroll.toElement(sp.currentPanel);
				}
			});
		}
    },
    position: function() {
    	p = this.currentPanel;
    	x=0;
    	while(p)
    	{
    		p.setStyle("left", x+"px");
    		p.setStyle("visibility", "visible");
    		x += p.getSize().x;
    		p = p.getNext();
    	}
    },
    setPreviousButton: function() {
		if(!this.currentPanel.getPrevious())
			$("previous").fade("out");
		else 
			$("previous").fade("in");
    },
    setNextButton: function() {
		if(!this.currentPanel.getNext())
			$("next").fade("out");
		else 
			$("next").fade("in");
    },
    setNavButtons: function() {
		this.setPreviousButton();
		this.setNextButton();
    }
});