function courrielFree(a,b,c)
{
	 document.write("<a href=\"mai");
	 document.write("lto:");
	 document.write(a+"@"+b+"."+c);
	 document.write("\">");
	 document.write(a+"(at)"+b+"(point)"+c);
	 document.write("</a>");
}
function submitTheForm()
{
	$('checkitout').value = "true";
	$('contactForm').submit();
}

var rouilleCoulonUrl = 'http://'+document.location.host;
var box = {};
var map = null;
var manageTheMap = {
	activeItem:null,
	options:null,
	center:null,
	init:function(container, points) 
	{
		var obj = this;
		this.options = points;
		map = new GMap2(document.getElementById(container));
		var center = new GLatLng(47.010226,2.416992);
		this.center = center;
		//map.setMapType(G_SATELLITE_MAP);
		map.setCenter(center, 5);
		map.enableScrollWheelZoom();
		//ZOOM BTNS
		var mapControl = new GSmallMapControl();
		map.addControl(mapControl);
		this.setPoints(points);
		// RESET
		$('resetMap').addEvent('click',function(e)
		{
			var e = new Event(e);
			e.stop();
			obj.resetMap();
		});
		$$('.img ul', this.options.infos).each(function(ul){
			ul.setStyle('display','none');
		});

	},
	setPoints: function(points)
	{
		var obj = this;
		var icon = new GIcon();
		icon.image = rouilleCoulonUrl+"/images/mapIcon.png";
		icon.shadow = rouilleCoulonUrl+"/images/mapIconShadow.png";
		icon.iconSize = new GSize(32, 30);
		icon.shadowSize = new GSize(47, 30);
		icon.iconAnchor = new GPoint(16, 30);
		icon.infoWindowAnchor = new GPoint(9, 2);
		points.pointsBtns.each(function(el, nb){
			
			var marker = new GMarker(points.points[nb], {draggable: false, icon:icon});
			//alert(marker.getIcon().image);
			map.addOverlay(marker);
			marker.redraw();
			GEvent.addListener(marker, "click", function()
			{
				//alert(this.getIcon());
				//this.getIcon().image = "images/mapIconShadow.png";
				//marker.openInfoWindowHtml(points.infos[nb]);
				obj.showItem(nb);
			});
			el.m = marker;
			el.itemId = nb;
			el.addEvent('click', function(e)
			{
				var e = new Event(e);
				e.stop();
				obj.showItem(nb);
			});
			// DEBUG POINTS
			/*
			var marker = new GMarker(points.points[nb], {draggable: true});
			GEvent.addListener(marker, "dragstart", function() {
				map.closeInfoWindow();
			});
			GEvent.addListener(marker, "dragend", function() {
				marker.openInfoWindowHtml("Just bouncing along...<br/>" + marker.getLatLng());
			});
			map.addOverlay(marker);
			*/
		});
	},
	showItem:function(id)
	{
		var options = this.options;
		if(this.activeItem)
		{
			this.activeItem.removeClass('act');
		}
		this.activeItem = options.pointsBtns[id].getParent();
		this.activeItem.addClass('act');
		options.infos.each(function(infoDiv)
		{
			infoDiv.setStyle('display','none');
		});
		options.infos[id].setStyle('display','block');
		//this.m.openInfoWindowHtml(points.titre[this.itemId]);
//		el.setStyle('display','block');
		map.setCenter(options.points[id], 10);
	},
	resetMap:function()
	{
		if(this.activeItem)
		{
			this.activeItem.removeClass('act');
		}
		this.options.infos.each(function(infoDiv)
		{
			infoDiv.setStyle('display','none');
		});
		map.setCenter(this.center, 5);
	}
};
window.addEvent('domready', function(){
	// HEADER
	var flashvars = {};
	var params = {};
	var attributes = {
	};
	params.menu = "false";
	params.wmode = "transparent";
	swfobject.embedSWF(rouilleCoulonUrl+"/flash/rouille_coulon_header2.swf", "anim", "1024", "235", "9.0.0",rouilleCoulonUrl+"/flash/expressInstall.swf", flashvars, params);
	// Initialisation de la lightbox (peut lire plein de formats, videos et autres.
	//box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: true});
	
	//Anim carte accueil
	if($('mapAccueilAnim'))
	{
		var flashvars = {};
		var params = {};
		var attributes = {
		};
		params.menu = "false";
		params.wmode = "transparent";
		swfobject.embedSWF(rouilleCoulonUrl+"/flash/map_accueil.swf", "mapAccueilAnim", "480", "400", "9.0.0",rouilleCoulonUrl+"/flash/expressInstall.swf", flashvars, params);
	}

	// MENU
	if(window.ie6)
	{
		//Suckerfish Alternative for IE, using MOOTOOLS.
		$$('#menu li').each(function(el, index)
		{
			el.addEvents(
			{
				'mouseenter':function(e)
				{
					this.addClass('over');
				},
				'mouseleave':function(e)
				{
					this.removeClass('over');
				}
			});
		});
	}
	
	// GOOGLE MAP
	if($('goug'))
	{
		if (GBrowserIsCompatible()) {
			// MARKER
			var listeDePoints = [new GLatLng(43.661861,4.02701), new GLatLng(48.621945508282415, 2.356116771697998), new GLatLng(44.89145151353192, -0.6059753894805908), new GLatLng(46.605538166888124, 4.669790267944336)];
			var pointsShower = $$('#pointsList a');
			var infos = $$('.mapInfosAdress');
			var nom = $$('.mapInfosAdress h3');
			var p = { pointsBtns:pointsShower, points:listeDePoints, infos:infos, titre:nom };
			manageTheMap.init('goug', p);
		}
	}
	if($('galerieC'))
	{
		var flashvars = {
			xmlFile:rouilleCoulonUrl+'/flash/materiel.xml'
		};
		//alert(flashvars.xmlFile);
		var params = {};
		var attributes = {
		};
		params.menu = "false";
		params.allowsciptaccess = "allways";
		params.wmode = "transparent";
		swfobject.embedSWF(rouilleCoulonUrl+"/flash/materiel2.swf", "galerieC", "900", "720", "9.0.0",rouilleCoulonUrl+"/flash/expressInstall.swf", flashvars, params);
	}
	if(Lightbox)
	{
		Lightbox.init({descriptions: true, showControls: true});
	}
	// POPUP PUB
	if($('popup'))
	{
		var popuped = Cookie.get("popupwasshown");
		if(!popuped)
		{
			var wait5sec = function()
			{
				Cookie.set("popupwasshown",true);
				if($('popup').getText().clean() != '')
				{
					//alert('Il y a qq chose  : \n '+ $('popup').getText().clean());
					var src = $('popup');//.clone();
					//$('popup').
					var layout = new Element('div',{'class':'popupLayout','styles':{'opacity':.8, 'height':$('container').getSize().size.y}}).injectAfter($('container'));
					var popup = new Element('div',{'class':'popup'}).injectAfter(layout);
					//var imgHolder = new Element('div',{'class':'popupImg','styles':{'opacity':0}}).injectInside(popup);
					popup.adopt(src);
					var closer = new Element('a', 
					{
						'href':'#',
						'class':'closePopup',
						'events':{
							'click':function(e)
							{
								var e=new Event(e);
								e.stop();
								popup.remove();
								layout.remove();
							}
						}
					}).setText('fermer').injectInside($('popup'));
/*					var myEffects = popup.effects({duration: 1000, transition: Fx.Transitions.Sine.easeInOut});
					var imgEffect = imgHolder.effects({duration: 1000, transition: Fx.Transitions.Sine.easeInOut, delay:1000});
					var img = new Image();
					img.onload = function()
					{
						//alert(this.width);
						//alert(this.height);
						imgHolder.setStyle('background','url('+src+') no-repeat 50%');
						myEffects.set({'height': this.height+20, 'width': this.width +20,'margin-top': -(this.height/2), 'margin-left': -(this.width/2) });	
						imgEffect.start({'height': this.height, 'width': this.width,'opacity':1});
						closer.injectInside(popup);
	
					}
					img.src = src;
					*/
				}
			}
			//var timer5sec = wait5sec.delay(10000);
			wait5sec();
		}else {
				$('popup').setStyle('display','none');
		}
	}	
});

