var myMap = {
	init:function(map)
	{
		var that = this
		this.map = map;
		this.infoWindowContainer = map.getPane(G_MAP_FLOAT_PANE);
		$('hideLeft').addEvent('click', function(e)
		{
			var e = new Event(e);
			e.stop();
			that.hideLeft();
		});
		$('zoomin').addEvent('click', function(e){ var e = new Event(e); e.stop(); that.map.zoomIn(); });
		$('zoomout').addEvent('click', function(e) { var e = new Event(e); e.stop(); that.map.zoomOut(); });
		$('normalMap').addEvent('click', function(e) { var e = new Event(e); e.stop(); that.map.setMapType(G_NORMAL_MAP); });
		$('satMap').addEvent('click', function(e) { var e = new Event(e); e.stop(); that.map.setMapType(G_SATELLITE_MAP); });
		$('hybMap').addEvent('click', function(e) { var e = new Event(e); e.stop(); that.map.setMapType(G_HYBRID_MAP); });
		// this.createWindow(this.infoWindowContainer);
		// EFFETS D'OUVERTURE / FERMETURE
		if(!this.fx)
		{
			this.fx = {};
			this.fx.left = new Fx.Styles($('left'), { duration:500, wait:false, onComplete:function() { that.map.checkResize(); }});
			this.fx.center = new Fx.Styles($('center'), {duration:500, wait:false});
			this.fx.content = new Fx.Styles($('content'), {duration:500, wait:false});
		}
		this.widths = {};
		this.widths.openedW = [230,620];
		this.widths.closedW = [0,852];

	},
	createWindow : function(target)
	{
		var that = this;
		if(!this.windowContainer)
		{
			this.windowContainer = new Element('div', {'id':'windowContainer'}).injectInside(target);
			//TOP
			var top = new Element('div', {'id':'windowTop'}).injectInside(this.windowContainer);
			var topLeft = new Element('div', {'id':'windowTopLeft'}).injectInside(top);
			var topRight = new Element('div', {'id':'windowTopRight'}).injectInside(top);
			var topCenter = new Element('div', {'id':'windowTopCenter'}).injectInside(top);
			//CENTER
			var center = new Element('div', {'id':'windowCenter'}).injectInside(this.windowContainer);
			this.htmlZone = new Element('div', {'id':'windowCenterHtmlZone'}).injectInside(center);
			//this.htmlZone.setStyle('z-index',10);
			/*
			this.closeButton = new Element('a', {href:'#',id:'closeW'}).injectInside(center);
			this.closeButton.addEvent('click', function(e)
			{
				var e = new Event(e);
				e.stop();
				that.hideInfoWindow();
			});
			*/
			// BOTTOM
			var bottom = new Element('div', {'id':'windowBottom'}).injectInside(this.windowContainer);
			var bottomLeft = new Element('div', {'id':'windowBottomLeft'}).injectInside(bottom);
			var bottomRight = new Element('div', {'id':'windowBottomRight'}).injectInside(bottom);
			var bottomCenter = new Element('div', {'id':'windowBottomCenter'}).injectInside(bottom);
			var bottomArrow = new Element('div', {'id':'windowBottomArrow'}).injectInside(bottom);
			this.w = this.windowContainer;
			this.w.draggable = false;
			this.w.setStyles({'display':'none', 'opacity':0 });
			//this.w.fx = new Fx.Styles(this.w, {duration:500, wait:false});
			this.img = new Element('img', {src:"images/bluePixel.png", useMap:'#myMapsMap'});
			//this.map.addOverlay(this.img);
			//this.img.injectBefore(this.w);
			//this.theShape = new Element('area', { href:"javascript:alert('testset')", shape:"rect",coords:'0,0,1,1'}).injectInside(new Element('map',{name:'myMapsMap', id:'myMapsMap'}).injectAfter(this.img));
		}
		return this;
	},
	fillWith: function(content)
	{
		this.htmlZone.innerHTML = content;
	},
	placeTheWindow:function(position)
	{
		GEvent.addListener(this.map,'zoomend',function()
		{
			myMap.placeTheWindow(position);
		});
		GEvent.addListener(this.map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE), 'click',function()
		{
			myMap.hideInfoWindow();
		});
		this.currentWindowPosition = position;
		this.w.setStyles({'display':'block', 'opacity':0 });
		var c = this.map.fromLatLngToDivPixel(position);
		this.w.setStyles({'left':c.x-20,'top':c.y - this.w.getCoordinates().height-20});
		//this.img = new Element('img', {src:"http://maps.google.com/intl/fr_ALL/mapfiles/transparent.gif"});
		//this.img.setStyles({'position':'absolute','left':c.x-20,'top':c.y - this.w.getCoordinates().height-20, 'width':this.w.getCoordinates().width, 'height':this.w.getCoordinates().height});
		//this.theShape.setProperty('coords','0,0,' + this.w.getCoordinates().width +','+this.w.getCoordinates().height);
 	},
	showInfoWindow:function(position, text)
	{
		this.fillWith(text);
		this.placeTheWindow(position);
		//this.w.fx.start({opacity:1});
		this.w.setStyles({'display':'block' });
	},
	hideInfoWindow:function()
	{
		this.w.setStyles({'display':'none' });
	},
	hideLeft: function()
	{
		var that = this;
		if(this.hidden)
		{
			this.hidden = false;
			this.fx.left.start({'width':this.widths.openedW[0], opacity:1});
			this.fx.content.start({'width':this.widths.openedW[1]});
			//$('left').setStyle('overflow','auto');
		}else{
			this.hidden = true;
			this.fx.left.start({'width':this.widths.closedW[0], opacity:0});
			this.fx.content.start({'width':this.widths.closedW[1]});
			//$('left').setStyle('overflow','hidden');
		}
	},
	hideCenter: function()
	{
		this.hiddeCenter = false;
		this.fx.left.start({'width':this.widths.openedW[0], opacity:1});
		this.fx.content.start({'width':this.widths.openedW[1]});
	},
	showInfoPanel:function(center, text)
	{
		var t = text.split('|');
		if(t[0].length > 5){
			Lightbox.show(t[0],t[1]);
		}
		this.centerTheMap.delay(720,this,center);
		//$('minf').innerHTML = text;
	},
	centerTheMap:function(center)
	{
		this.map.setCenter(center, 15);
	}	
}

	//var mainPath = '';
var mainPath = 'fileadmin/templates/';
window.addEvent('domready', function()
{
	var ctnr = $("container");
	if(!ctnr.hasClass('accueil'))
	{
		var fl = new Element('div', {id:'flC'}).injectInside($('header'));
		var flashvars = {
			mainurl:mainPath+"flash/"
		};
		var params = {
			menu:"false",
			wmode:"transparent",
			scaleMode:"noScale"
		};
		var attributes = {
			id: "anim",
			name: "anim"
		};
		swfobject.embedSWF(mainPath+"flash/header.swf","flC", "100%", "213", "8", mainPath+"flash/expressInstall.swf", flashvars, params, attributes);
	}else{
		var fl = new Element('div', {id:'flC'}).injectInside($('header'));
		var flashvars = {
			mainurl:mainPath+"flash/"
		};
		var params = {
			menu:"false",
			wmode:"transparent",
			scaleMode:"noScale"
		};
		var attributes = {
			id: "anim",
			name: "anim"
		};
		swfobject.embedSWF(mainPath+"flash/header_accueil.swf","flC", "100%", "310", "8", mainPath+"flash/expressInstall.swf", flashvars, params, attributes);
	}
	if(window.ie6)
	{
		//Suckerfish Alternative for IE, using MOOTOOLS.
		$$('#menu li','#mapControls li').each(function(el, index)
		{
			el.addEvents(
			{
				'mouseenter':function(e)
				{
					this.addClass('over');
				},
				'mouseleave':function(e)
				{
					this.removeClass('over');
				}
			});
		});
	}

	/*
	GOOGLE MAP
	*/
	if($('mapContainer'))
	{
		/*
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("mapContainer"));
			geocoder = new GClientGeocoder();
			new GKeyboardHandler(map);
			var origine = new GLatLng(43.60625069174641, 3.88092041015625)
			map.setCenter(origine, 10);
			//map.addControl(new GSmallMapControl());
			map.setMapType(G_NORMAL_MAP);
			//map.addControl(new GMapTypeControl());
			map.enableDoubleClickZoom();
			map.enableContinuousZoom();
			var marker = new GMarker(origine, {draggable: false});
			//alert(marker.getIcon().image);
			map.addOverlay(marker);
			//var iw = myMap.createWindow(infoWindowContainer);
			myMap.init(map);
			GEvent.addListener(marker, "click", function()
			{
				myMap.showInfoPanel(origine);
			});
			GEvent.addListener(marker, "mouseover", function()
			{
				myMap.showInfoWindow( origine, 'qsd mlkqs dmlkqs dmkldsq mlkqsd qsd mlkqs dmlkqs dmkldsq mlkqsd <p>qsd mlkqs dmlkqs dmkldsq mlkqsd qsd mlkqs dmlkqs dmkldsq mlkqsd</p>' );
			});
			GEvent.addListener(marker, "mouseout", function()
			{
				myMap.hideInfoWindow();
			});
/*			GEvent.addListener(map,'zoomend',function()
			{
				//iwplaceTheWindow
				//c = map.fromLatLngToDivPixel(origine);
				myMap.placeTheWindow( origine ); //w.setStyles({'left':c.x-20,'top':c.y-iw.w.getCoordinates().height-20});
			});
*/
	//	}
		
	}
	Lightbox.init({descriptions: true, showControls: false});
});