
	// Central JavaScript Document

	Object.extend(Element, {
		setDisplay:function(element,s)
		{
			element = $(element);
			element.style.display = s; 
		},
		setSrc:function(element,src)
		{
			element = $(element);
			element.src = src; 
		},
		setBgImg:function(element,src)
		{
			element = $(element);
			element.style.backgroundImage = "url("+ src +")"; 
		}
		
	});	

	function Preload()
	{
		var args = Preload.arguments;
		document.PreloadArray = new Array(args.length);
		
		for(var i=0;i<args.length;i++)
		{
			document.PreloadArray[i] = new Image;
			document.PreloadArray[i].src = args[i];
		}
	}
	
	function getSelectTag()
	{
		return document.getElementsByTagName("select");
	}
	

	
	function _getParams(w)
	{
		// Current Url
		path = document.location.href;
		// Dot interoogation position
		itg = path.search(/\?/);
		// 
		s = path.substr(itg+1);
		s = s.split("&");
		
		// Extract param value
		vl = new Array();
		var w_param;
		
		for(i=0;i<s.length;i++)
		{
			ns = s[i].split("=");
			vl[i] = [ns[0], ns[1]];
			if(w)
			{
				if(w == ns[0]) w_param = [ns[0], ns[1]];
			}
		}
		
		return (w)?w_param:vl;
	}

	function EnterStats(data)
	{
		var request = new Ajax.Request("/request_handler.php",
			{
				// Use POST
				method:"post",
				// Send data
				postBody:"idPub=" + escape(data),
				// Handle successful response
				onSuccess:function(t)
				{
					//alert(t.responseText);
				}
			}	

		);	
	}

	Event.observe(window, "load", gInit);
	
	function gInit()
	{
	//   	if($("logo"))
	//	{
	//		$T($.A({id:"Back-Home"}), document.body);
	//		$("Back-Home").href = "/";
	//	}
		
		// Régie pub
		if($("publicite"))
		{
			$("publicite").onfocus = function()
			{
				this.blur();
			};
			$("publicite").onclick = function()
			{
				EnterStats(50)
			};
		}

		
		// List Urls - S
		
/*		$T($.DIV({id:"list-urls"}), document.body);
		$("list-urls").innerHTML = 	'<ul>' + 
											'<li><a href="index_p.php">&#8250; G&eacute;olocalisation / Pr&eacute;-Home</a></li>' + 
											'<li><a href="index.php">&#8250; Home</a></li>' + 
											'<li>&nbsp;</li>' + 
											'<li><a href="default.php">&#8250; Default template</a></li>' + 
											'<li><a href="default_rtl.php">&#8250; Default template right to left</a></li>' + 
											'<li><a href="recherche_magasins.php">&#8250; Recherche magasins</a></li>' + 
									'</ul>';
*/		// List Urls - E
		
		
		// Display left frames
		if(navigator.userAgent.toLowerCase().indexOf("mac") != -1)
		{
			if($("conteneur-gauche-mac")) Element.setDisplay("conteneur-gauche-mac" , "block");
		}
		else
		{
			if($("conteneur-gauche-opacite")) Element.setDisplay("conteneur-gauche-opacite" , "block");
		}
		
		if($("conteneur-gauche")) Element.setDisplay("conteneur-gauche", "block");
		
		
		// Initialize left menu
		Menu.Init();
		if(window.Locator != null) Menu.Set(Locator);
		// Order of Events in IE
		// IE Problem : http://cute-solutions.blogspot.com/ --> Prototype approach don't work, but IE problem handler management
		// Event.observe(window, "load", function(){Menu.Set(1);});	

		
		// Scroller container
		if($("defilement-conteneur"))
		{
			Slider = new Control.Scroller('contenu-defilant', 'poignee', 'couloir-defilement',
			{
				up:"bt-haut",
				down:"bt-bas",
				visibleHeight:350,
				totalPadding:50,
				onScroll:function(value, scroller)
				{
					// document.title = value;
				}
			});
			
			HC = '';
			for(i=0;i<12;i++) HC += '<div class="t"><span><\/span><\/div>';
			Slider.handle.update(HC);
		}
		
		// Bottom menu
		Mn_e = new Bottom_Menu("pimkie-entreprise", "menu-entreprise-b");
		Mn_r = new Bottom_Menu("pimkie-recrutement", "menu-recrutement-b");
		
		StoresPics.Init();
		Newsletter_Field.Init();
		CountryMenu.Init();
		RandomPicViewer.Init();
		LanguagesMenu.Init();

	}
	
	Newsletter_Field = 
	{
		Button:null,
		Layer:null,
		Init:function()
		{
			if($("newsletter") && $("menu-newsletter"))
			{
				_r = this;

				this.Button = $("newsletter")
				this.Layer = $("menu-newsletter");
				
				Event.observe(this.Button, "click", 
					function()
					{
						//new Effect.Appear(_r.Layer.id);
					}
				);

			}
			
		}
		
	}


	Menu =
	{
		Nav_Root:null,
		ListRootLi:[],
		ListRootA:[],
		ListSubLevel:[],
		Init:function()
		{
			this.Nav_Root = $("nav");
			var _r = this;
			
			if(this.Nav_Root)
			{
				// Collect and init behavior
				var ind = 0;
				
				NodeList = this.Nav_Root.childNodes
				$A(NodeList).each(
					function(e, i)
					{
						if(e.tagName == "li".toUpperCase())
						{
							_r.ListRootLi[ind] = e;
							
							_r.ListSubLevel[ind] = e.getElementsByTagName("ul".toUpperCase())[0];
							
							if(_r.ListSubLevel[ind])
							{
								_r.ListSubLevel[ind].id = "sub-"+ind;
								
								_r.ListRootA[ind] = e.childNodes[0];
								_r.ListRootA[ind].id = "nav-"+ind;
								
								// Behavior
								_r.ListRootA[ind].href = "javascript:void(0)";
								_r.ListRootA[ind].onfocus = function(){this.blur();};
								_r.ListRootA[ind].onclick = new Function('Menu.Set('+ind+');');
							}
							ind = ind + 1;
						}
					}
				);
				
				
				
			}
		},
		Set:function(w)
		{
			var _r = this;
			// Restore
			$A(this.ListRootA).each(
				function(e, i)
				{
					Element.removeClassName(e, "c");
					if(_r.ListSubLevel[i]) Element.hide(_r.ListSubLevel[i]);
				}
			);

			Element.addClassName(this.ListRootA[w], "c");
			//alert(this.ListSubLevel[w]);
			this.ListSubLevel[w].style.display = "block";
		}		
	}
	
	
	var B_Menus = [];
	
	Bottom_Menu = Class.create();
	Bottom_Menu.prototype = 
	{
		initialize:function(Button, Layer)
		{
			if(!$(Button) || !$(Layer)) return;
			
			var _r = this;
			this.Button = $(Button);
			this.index = B_Menus.length;
			B_Menus[this.index] = this;
			this.Layer = $(Layer);
			this.timer = 0;
			
			// Setting position
			SetPos = function(){_r.Layer.position(Position.cumulativeOffset(_r.Button)[0], 493 - _r.Layer.offsetHeight);};
			SetPos(); Event.observe(window, "resize", SetPos);
			
			// Init Mouse behavior
			// Mouseover
			
			// ---> http://particletree.com/notebook/prototype-and-the-this-keyword/ prototype and javascript closures
			Event.observe(this.Layer, "mouseover", this.Open.bindAsEventListener(this));
			Event.observe(this.Button, "mouseover", this.Open.bindAsEventListener(this));
			// Mouseout
			Event.observe(this.Layer, "mouseout", this.Defer_Hide.bindAsEventListener(this));
			Event.observe(this.Button, "mouseout", this.Defer_Hide.bindAsEventListener(this));

		
		},
		Open:function()
		{
			if(this.timer != 0) clearInterval(this.timer);
			if(B_Menus.length > 1)
			{
				$A(B_Menus).each(
					function(e, i)
					{
						if(i != this.index)
						{
							e.Layer.style.visibility = "hidden";
							status = e.Button;
							Element.removeClassName(e.Button, "c");
						}
					}
				);	
			}
			
			for(a=0;a<getSelectTag().length;a++) getSelectTag()[a].style.visibility = "hidden";
			Element.addClassName(this.Button, "c");
			this.Layer.style.visibility = "visible";
		},
		Defer_Hide:function()
		{
			this.timer = setTimeout(this.Hide.bindAsEventListener(this), 1000);
		},
		Hide:function()
		{
			for(a=0;a<getSelectTag().length;a++) getSelectTag()[a].style.visibility = "visible";
			Element.removeClassName(this.Button, "c");
			this.Layer.style.visibility = "hidden";
		}
	}



	StoresPics = 
	{
		Path:"/library/img/intern/magasins/",
		A_Pic:[],
		Pic_Buttons:[],
		Ready:0,
		Init:function()
		{
			var _r = this;
			
			// liste-magasins
			if($("resultat-liste-magasins"))
			{
				// Rewrite urls
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				$A(this.A_Pic).each(
					function(e, i)
					{
						$A(e).each(
							function(f, j)
							{
								_r.A_Pic[i][j][0] = _r.Path + _r.A_Pic[i][j][0];
								// Preload
								Preload(_r.A_Pic[i][j][0]);
								
							}
						);
					}
				);
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

				list = document.getElementsByClassName("liste-magasins")[0];
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// Starting	Lightbox
				myLightbox = new Lightbox();	
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

				$A(document.getElementsByClassName("photos", list)).each(
					function(e, i)
					{
						// Pass Lightbox External Image Array
						e.onclick = function(){myLightbox.start(this, StoresPics.A_Pic[i], 0);}
					}
				)
			}
		}
	}
	
	CountryMenu = 
	{
		Install:0,
		Container:null,
		Content:null,
		Button:null,
		Status:0,
		MoveActive:0,
		Init:function()
		{
			// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
			// ///
			// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
			if(this.Install)
			{
				
				var _r = this;
				
				if($("menu-pays-conteneur"))
				{
					this.Container = $("menu-pays-conteneur");
					this.Content = $("menu-pays");
					this.Button = $("menu-pays-interrupteur");
					this.Button.style.visibility = "visible"
					this.Button.onfocus = function(){this.blur();}
					this.Button.onclick = function()
					{
						if(_r.MoveActive == 0)
						{
							if(!_r.Status)
							{
								_r.Container.style.visibility = "visible";
								new Effect.Move(_r.Content, 
									{
										x:0,
										y:0,
										mode:'absolute',
										duration:0.5,
										beforeStart:function()
										{
											Element.addClassName(_r.Button, "on");
											_r.MoveActive = 1;
										},
										afterFinish:function()
										{
											_r.MoveActive = 0;
											_r.Status = 1;
										}
									}
								);
								
								
							}
							else
							{
								new Effect.Move(_r.Content, 
									{
										x:0,
										y:440,
										mode:'absolute',
										duration:0.3,
										beforeStart:function()
										{
											_r.MoveActive = 1;
										},
										afterFinish:function()
										{
											Element.removeClassName(_r.Button, "on");
											_r.MoveActive = 0;
											_r.Container.style.visibility = "hidden";
											_r.Status = 0;
										}
									}
								);
								
								
							}
						}
						
					}
					
					
				}
			
			}
			// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
			// ///
			// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
			
		}
		
	}
	
	RandomPicViewer = 
	{
		Path:"/library/img/colonne_droite/",
		Directory:"goodies",
		A_Pic:
		[
		 	"16.jpg",
		 	"17.jpg",
		 	"18.jpg"
		],
		Init:function()
		{
			var _r = this;
			
			// Rewrite urls
			$A(this.A_Pic).each(
				function(e, i)
				{
					_r.A_Pic[i] = _r.Path + _r.Directory + "/" + _r.A_Pic[i];
				}
			);

			if($("colonne-droite"))
			{
				Element.setBgImg($("colonne-droite"), this.A_Pic[this.RandomNumber(this.A_Pic.length)]); 
			}
		},
		RandomNumber:function(n)
		{
			r = Math.floor(n * Math.random())
			return r;
		}
		
	}
	
	
	LanguagesMenu = 
	{
		Flag:[],
		Languages:[],
		timer:0,
		Init:function()
		{			
			_r = this;
			if($("liste-pays-mg") && $("langues-disponibles"))
			{
				this.Layer = $("langues-disponibles");
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ---> Stockage | S
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				$A(document.getElementsByClassName("root", $("liste-pays-mg"))).each(
					function(e, i)
					{

						_r.Languages[i] = new Array();
						if(e.getElementsByTagName("ul".toUpperCase())[0])
						{
							$A(e.getElementsByTagName("ul".toUpperCase())[0].getElementsByTagName("li".toUpperCase())).each(
								function(f, j)
								{
									_r.Languages[i][j] = 
									[
										f.childNodes[0].innerHTML,
										f.childNodes[0].href
									];
								}
							)
						}
						
						_r.Flag[i] = e.getElementsByTagName("a".toUpperCase())[0];
						
						if(_r.Languages[i].length >= 1)
						{
							// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
							// ---> Assign Behavior | S
							// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
							Event.observe(_r.Flag[i], "mouseover", function(){_r.Open(i)}.bindAsEventListener(_r));
							Event.observe(_r.Layer, "mouseover", _r.Open.bindAsEventListener(_r));
							
							Event.observe(_r.Flag[i], "mouseout", function(){_r.Defer_Hide(i)}.bindAsEventListener(_r));
							Event.observe(_r.Layer, "mouseout", function(){_r.Defer_Hide(i)}.bindAsEventListener(_r));
							// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
							// ---> Assign Behavior | E
							// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
						}

							
					}
											  
				)
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ---> Stockage | S
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
				// ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
			}
			
		
		},
		Open:function(n)
		{	
			if(this.timer != 0)
			{
				clearInterval(this.timer);
				this.timer = 0;
			}
			
			if(typeof(n) == "number")
			{
				if(this.Languages[n].length >= 1)
				{
					this.Layer.update('');
					$A(this.Languages[n]).each(
						function(g, k)
						{
							_r.Layer.update(_r.Layer.innerHTML + '<a href="' + g[1] + '">' + g[0] + '<\/a>');
						}
					)
				}
				// Fade out all
				
/*				$A(this.Flag).each(
					function(o)
					{
						new Effect.Opacity(o, {duration:0.2, transition:Effect.Transitions.linear, from:0.3, to:0.3});
					}
				)
*/				
				// Fade in
/*				new Effect.Opacity(this.Flag[n], {duration:0.2, transition:Effect.Transitions.linear, from:0.3, to:1.0});

*/				// Repositionning
				xLeftLimit = Position.cumulativeOffset(this.Flag[0])[0];
				xRightLimit = xLeftLimit + 162;
				xRight_Layer = Position.cumulativeOffset(this.Flag[n])[0] + this.Layer.offsetWidth
				
				x = Position.cumulativeOffset(this.Flag[n])[0] - (xRight_Layer > xRightLimit?xRight_Layer - xRightLimit:0);
				y = Position.cumulativeOffset(this.Flag[n])[1] - (5 + this.Layer.offsetHeight);
				this.Layer.position(x, y);
			}
			
			this.Layer.style.visibility = "visible";
			
		},
		Defer_Hide:function(n)
		{
			if(this.timer == 0)
			{
				this.timer = setTimeout(function(){this.Hide()}.bindAsEventListener(this), 250);
				
				//
/*				$("colonne-gauche").innerHTML = n
				new Effect.Opacity(this.Flag[n], {duration:0.2, transition:Effect.Transitions.linear, from:1.0, to:0.3});
*/			}
		},
		Hide:function()
		{
			this.Layer.style.visibility = "hidden";
			this.timer = 0;
		}
	}
	

