 
	var gmap = {
		initialize: function(shops) {
			 	gmap.shops = new Array();
				gmap.debug = false;
				gmap.shops = shops;
			 
			
				gmap.small = document.getElementById("gmap");	
				gmap.wideInit = false;
		
				gmap.smallMap = new GMap2(gmap.small);
				gmap.smallMap.markers = new Array(); 	
				mapCenter = new GLatLng(47,1);

				gmap.smallMap.setCenter(mapCenter,5);
				controls = gmap.smallMap.addControl(new GSmallZoomControl3D());
				gmap.smallMap.disableScrollWheelZoom();
				gmap.setUpMarkers(gmap.smallMap);	
							/*GEvent.addListener(gmap.smallMap, "zoomend", function(oldZoom,currentZoom) {
							        if (currentZoom>8 && gmap.smallMap.visibleMarkers != 'on'){
									 	 
							}
							});
							GEvent.addListener(gmap.smallMap, "moveend", function() {
			
							});
							*/
		 
		},
		initWideMap: function() {
					gmap.wide = document.getElementById("gmap-wide");
					gmap.wideMap = new GMap2(gmap.wide);
					gmap.wideMap.markers = new Array();
					var currentZoom = gmap.smallMap.getZoom();
					 	
					gmap.wideMap.setCenter(gmap.smallMap.getCenter(),currentZoom);
					controls = gmap.wideMap.addControl(new GLargeMapControl3D());
					gmap.wideMap.disableScrollWheelZoom();
					gmap.setUpMarkers(gmap.wideMap);
					
					/*
					GEvent.addListener(gmap.wideMap, "zoomend", function(oldZoom,currentZoom) {
					       	  if (currentZoom>8  && gmap.wideMap.visibleMarkers != 'on'){
								 
								}
							 	
					});
					GEvent.addListener(gmap.wideMap, "moveend", function() {
					      
					});
					*/
		},
	showWide: function() {
			var smallMapSearch =	document.getElementById('qAddresssmallMap').value ;	
			
			if(gmap.wideInit != true){
			 	 gmap.wide = document.getElementById("gmap-wide");
				 gmap.wide.container = document.getElementById("gmap-wide-container");
				 gmap.wide.container.style.display = 'block';
				 gmap.initWideMap();
				 document.getElementById('qAddresswideMap').value =	smallMapSearch ;
				 if (smallMapSearch !='')
				 gmap.search('wideMap');
				 gmap.wideInit = true;
			} 
			else{
			if(gmap.wide.container.style.display == 'none'){
			gmap.wide.container.style.display = 'block';
			document.getElementById('qAddresswideMap').value =	document.getElementById('qAddresssmallMap').value ;
			
				var smallZoom = gmap.smallMap.getZoom();
		 
			if (smallMapSearch!='')
				 gmap.search('wideMap');
			else
			gmap.wideMap.setCenter(gmap.smallMap.getCenter(),smallZoom);	
			}else{
			gmap.wide.container.style.display = 'none';
			document.getElementById('qAddresssmallMap').value = document.getElementById('qAddresswideMap').value;
			gmap.search('smallMap');			
			}
			}
	}, 
	setUpMarkers: function(whichMap){
	 	var blueIcon = new GIcon(G_DEFAULT_ICON);
		markerOptions = {icon:blueIcon,draggable:false};
		for (var i = 0; i < gmap.shops.length; i++) {
					shopInfos = gmap.shops[i];
					shopInfos.point = new GLatLng(parseFloat(shopInfos.latitude),parseFloat(shopInfos.longitude));
					gmap.shops[i].point = shopInfos.point;
					shopInfos.whichMap = whichMap;
					if(shopInfos.point.x !=0 && shopInfos.point.y !=0 ){
					marker = new GMarker(shopInfos.point,markerOptions);
					GEvent.bind(marker,"click",shopInfos, function() {
	 							this.whichMap.openInfoWindowHtml(this.point, gmap.markerWindow(this));
					      });
					}
			 
					whichMap.markers.push(marker);
		  	}
	},
	markerWindow: function(shop){
			//var markerWindow = '['+shop.id+']';
			var markerWindow = '';
			markerWindow += '<ul class="gmapOpenW"><li class="hilight">'+shop.name+'</li>';
			markerWindow += '<li>'+shop.address+'</li>';
			markerWindow += '<li>'+shop.city+' '+shop.zipcode+'</li>';
			if (shop.phone)
			markerWindow += '<li>Tel : '+shop.phone+'</li>';
			if (shop.infos)
			markerWindow += '<li>'+shop.infos+'</li>';
			if (shop.description)
			markerWindow += '<li><img class="ps-logo" src="http://m.bestofmedia.com/i/tomsguide/op/hp-photosmart/logos/'+shop.description+'" alt="'+shop.name+'" /></li>';
			markerWindow += '</ul>';
			return(markerWindow);
	},
	showHideMarkers: function(status,whichMap){
		if (status=='on'){
			whichMap.visibleMarkers = 'on';
		for (var i = 0; i < gmap[whichMap].markers.length; i++) {
					whichMap.addOverlay(gmap[whichMap].markers[i]);	
		}}
		else{
			whichMap.visibleMarkers = 'off';
		for (var i = 0; i < gmap[whichMap].markers.length; i++) {
					whichMap.removeOverlay(gmap[whichMap].markers[i]);	
		}}
	},
	focusSearch:function(e) {
			
			gmap.currentSearchPoint = new GLatLng(e.y+0.01,e.x) ;
		 	gmap.s.setCenter(gmap.currentSearchPoint,12);
			var blueIcon = new GIcon(G_DEFAULT_ICON);
			blueIcon.image = "http://img.bestofmedia.com/img/bestofmedia/admin/content/blue.png";
			markerOptions = {icon:blueIcon };

			gmap.s.currentMarker = new GMarker(gmap.currentSearchPoint, markerOptions);
			

			var minKm = gmap.drawAlentours(e,0.25); // rayon 30 km
			if (minKm == 9000000){
			minKm = gmap.drawAlentours(e,1); // rayon de 130 km	
			}
			var unit = 'km';
			gmap.s.addOverlay(gmap.s.currentMarker);
			meilleureDistance = minKm/1000;
			meilleureDistance = Math.round(meilleureDistance*10)/10;
			
			if (meilleureDistance<1){
				meilleureDistance = Math.round(minKm*1)/1;
				unit = 'm';
			}
			
			var windowHtml =  '<ul class="gmapOpenW"><li class="hilight">&gt; Votre recherche : <span class="ps-openW-s"></span></li>';
				windowHtml +=  '<li class="upperc" style="padding-bottom: 15px">'+queryAddress.value+'</li>';
			if (gmap.nearestShop.name){	
				windowHtml +=  '<li><span class="hilight">&gt; À environ '+meilleureDistance+' '+unit+' : </span></li>';
				windowHtml += '<li><a href="#" class="neutral" onclick="gmap.panToShop('+gmap.nearestShop.lineId+')">'+gmap.nearestShop.name +'</a></li>';
				windowHtml += '<li>'+ gmap.nearestShop.address +'</li>';
				windowHtml += '<li>'+gmap.nearestShop.zipcode +' '+ gmap.nearestShop.city +'</li>'; 
			if (gmap.nearestShop.infos)	
				windowHtml += '<li>'+gmap.nearestShop.infos+'</li>'; 
				
			if (gmap.nearestShop.description)	
				windowHtml += '<li><a href="#" onclick="gmap.panToShop('+gmap.nearestShop.lineId+')"><img class="ps-logo-s" src="http://m.bestofmedia.com/i/tomsguide/op/hp-photosmart/logos/'+gmap.nearestShop.description+'" alt="'+gmap.nearestShop.name+'" /></a></li>';
				windowHtml += '<li><a href="#" class="gmapOpenWHref" onclick="gmap.panToShop('+gmap.nearestShop.lineId+')">Afficher le magasin</a></li>';
				}
			else {
				var maxDistance = parseFloat(gmap.currentSearchPoint.distanceFrom(gmap.ne));
				meilleureDistance = maxDistance/1000;
				meilleureDistance = Math.round(meilleureDistance*1)/1;
				windowHtml += '<li>Aucun magasin à moins de '+ meilleureDistance +' km</li>';
			}
			 
			windowHtml += '</ul>';	
			gmap.s.openInfoWindowHtml(gmap.currentSearchPoint,windowHtml);
				
		 	GEvent.addListener(gmap.s.currentMarker, "click", function(){gmap.s.openInfoWindowHtml(gmap.currentSearchPoint,windowHtml)});
		},
	drawAlentours: function(currentSearchPoint,gap){
			gmap.s.clearOverlays();
			 
			nwLat = currentSearchPoint.y+gap;
			nwLon = currentSearchPoint.x-gap;
			gmap.nw = new GLatLng(nwLat,nwLon) ;
			
			
			swLat = currentSearchPoint.y-gap;
			swLon = currentSearchPoint.x-gap;
			gmap.sw = new GLatLng(swLat,swLon) ;
			
			seLat = currentSearchPoint.y-gap;
			seLon = currentSearchPoint.x+gap;
			gmap.se = new GLatLng(seLat,seLon) ;
			
			neLat = currentSearchPoint.y+gap;
			neLon = currentSearchPoint.x+gap;
			gmap.ne = new GLatLng(neLat,neLon) ;
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
			blueIcon.image = "http://img.bestofmedia.com/img/bestofmedia/admin/content/blue.png";
			markerOptions = {icon:blueIcon };
			var blueMarkerOptions = {icon:blueIcon,draggable:true};
			if (gmap.debug == true){
			var msw = new GMarker(gmap.sw,blueMarkerOptions);
			gmap.s.addOverlay(msw);
			var mne = new GMarker(gmap.ne,blueMarkerOptions);
			gmap.s.addOverlay(mne);

			var mnw = new GMarker(gmap.nw,blueMarkerOptions);
			gmap.s.addOverlay(mnw);
			var mse = new GMarker(gmap.se,blueMarkerOptions);
			gmap.s.addOverlay(mse);

			var polyline = new Array();
			polyline.push(gmap.nw);
			polyline.push(gmap.ne);
			polyline.push(gmap.se);
			polyline.push(gmap.sw);
			polyline.push(gmap.nw);
			var p = new GPolyline(polyline);
			gmap.s.addOverlay(p);
			}
			var alentours = new GLatLngBounds(gmap.sw,gmap.ne);
			
			
			gmap.nearestShop = {};
			var minKm = 9000000;
			for (var i = 0; i < gmap.shops.length; i++) {
						if (alentours.containsLatLng(gmap.shops[i].point)){
							gmap.s.addOverlay(gmap.s.markers[i]);	
							var distance = parseFloat(gmap.currentSearchPoint.distanceFrom(gmap.shops[i].point));
						 	if (distance<minKm){
							 	 gmap.nearestShop = gmap.shops[i];
								 gmap.nearestShop.lineId = i;	
								 var minKm = distance; 
								}
						}	
			}
		return minKm ;
	},	
	search:function(whichMap){	
		geoCoder = new GClientGeocoder();
		queryAddress = document.getElementById('qAddress'+whichMap);
		gmap.s = gmap[whichMap];
		geoCoder.getLatLng(queryAddress.value + ', France', gmap.focusSearch);
		return false;
	},
	panToShop:function(lineId){
		var p = gmap.shops[lineId].point; //gmap.s.markers[lineId];	
	 	gmap.s.openInfoWindowHtml(p, gmap.markerWindow(gmap.shops[lineId]));
		gmap.s.panTo(p);
	},
	printMap:function(){
		window.print();
		return false;
	},
	printFromSmallMap:function(){
		gmap.showWide();
		t=setTimeout("gmap.printMap()",5000);
		return false;
	}
	
	}
	
	var rotate = {
		initialize: function(shops) {
					rotate.shops = shops;
					for (var i = 0; i < shops.length; i++) {
							
					}
					
					rotate.c=0;
					rotate.go = 1;
					rotate.t;
					rotate.speed = 4000;
					rotate.wrapper = document.getElementById('ps-rotate');
					rotate.play();
	},
	play:	function(){
			if (rotate.c < rotate.shops.length && rotate.shops[rotate.c].infos=='')
				rotate.c = rotate.c+1;	

			if (rotate.c>=rotate.shops.length)
				rotate.c = 0;
			rotate.display();
			rotate.c=rotate.c+1;	
			if (rotate.go == 1)
			rotate.t=setTimeout("rotate.play()",rotate.speed);
		},
	display: function(){
		 	rotate.wrapper.innerHTML = '';
			var li = document.createElement('li');
			rotate.wrapper.appendChild(li);
			li.appendChild(document.createTextNode(rotate.shops[rotate.c].name));
			
			li = document.createElement('li');
			rotate.wrapper.appendChild(li);
			li.appendChild(document.createTextNode(rotate.shops[rotate.c].zipcode+' '+rotate.shops[rotate.c].city));
 			
			li = document.createElement('li');
			li.className = 'hilight'; 
			rotate.wrapper.appendChild(li);
			li.appendChild(document.createTextNode(rotate.shops[rotate.c].infos));
	},	
	prev: function(){
		rotate.go = 0;
		rotate.c=rotate.c-1;
		if (rotate.c<0)
		rotate.c = rotate.shops.length-1;	
		rotate.display();
		return false;
	},
	next: function(){
		rotate.go = 0;
		rotate.c=rotate.c+1;
		if (rotate.c>=rotate.shops.length){
			rotate.c = 0;
		}	
		rotate.display();
		return false;
	}
	}	
