function ClassSlides()
{
	this.CurrentImage = 0;
	this.steps = 10;
	this.timeout = false;
	this.DoubleClickUrl = '';
	this.arrayPhotosList = new Array();
	this.map = null;
	
	this.addPhoto = function(unArrayPhoto){
	    this.arrayPhotosList[this.arrayPhotosList.length] = unArrayPhoto;
	}
	
	this.ClickThumb = function(n)
	{
		document.getElementById('Thumb' + this.CurrentImage).className = 'thumb';
		document.getElementById('Thumb' + n).className = 'on';
		this.CurrentImage = n;
		this.displayInfoPhotoXL();
		this.From = document.getElementById('ThumbnailDiv').scrollTop;
		this.To = n*92 - 184;
		this.DoStep(0);
	}

	this.DoStep = function(step)
	{
		step ++;
		document.getElementById('ThumbnailDiv').scrollTop = this.Factor(step / this.steps) * (this.To - this.From) + this.From;
		if (this.timeout) clearTimeout(this.timeout);
		if (step < this.steps) this.timeout = setTimeout('Slides.DoStep(' + step + ')', 10);
	}

	this.Up = function()
	{
		var Next = this.CurrentImage - 1;
		if (Next < 0) Next = 0;
		this.ClickThumb(Next);
	}

	this.Down = function()
	{
		Next = this.CurrentImage + 1;
		if (Next > this.arrayPhotosList.length - 1) Next = this.arrayPhotosList.length - 1;
		this.ClickThumb(Next);
	}

	this.Factor = function(f)
	{
		return .5 - Math.cos(f * Math.PI) * .5;
	}

	this.Initialize = function()
	{
		if (document.getElementById('ThumbnailDiv'))
		{
		    //this.CurrentImage = 0;
		   
			var sHtml = '';
			var au_moins_un_GPS = false;
			for(var i=0; i<this.arrayPhotosList.length; i++)
			{
			    var ArrayPhotos = this.arrayPhotosList[i];
				sHtml += '<div style="height:90px;overflow:hidden;"><a href="javascript:Slides.ClickThumb(' + i + ')"><img';
				if (i == 0)
				{
					sHtml += ' class="on"';
				}
				else
				{
					sHtml += ' class="thumb"';
				}
				sHtml += ' id="Thumb' + i + '" src="' + ArrayPhotos["linkThumb"] + '" alt="' + ArrayPhotos["titre"] + '" style="min-height:90px;" /></a></div>';
				
	            if ((ArrayPhotos["GPS_lat"] != 0) && (ArrayPhotos["GPS_long"] != 0)) au_moins_un_GPS = true;
	            if ((ArrayPhotos["GPS_lat_etablissement"] != 0) && (ArrayPhotos["GPS_long_etablissement"] != 0)) au_moins_un_GPS = true;
			}
			document.getElementById('ThumbnailDiv').innerHTML = sHtml;
			if ((au_moins_un_GPS) && (this.map == null)) this.loadMap();
			this.displayInfoPhotoXL();
		}
		else
		{
			setTimeout('Slides.Initialize()', 250)
		}
	}
	
	this.clearAndReplaceMarker = function (){
	    var auMoinsUnMarker = false;
	    if (this.map != null){
	        this.map.clearOverlays();
	        
	        var map_centree = false;
            var currentPictGeopositionnee = false;
	        var x = this.arrayPhotosList[this.CurrentImage]["GPS_lat"];
	        var y = this.arrayPhotosList[this.CurrentImage]["GPS_long"];
            if ((x != 0) && (y !=0)) currentPictGeopositionnee = true;
            map_centree = currentPictGeopositionnee;
            
	        for(var i=0; i<this.arrayPhotosList.length; i++)
		    {
		        var markerPlace = false;
		        markerPlace = this.addMarkerOnMap(i);
		        if ((markerPlace) && (!map_centree)) map_centree = this.centerThisPoint(i);
		        if (i == this.CurrentImage) this.centerPointOnMap();
			    if (!auMoinsUnMarker) auMoinsUnMarker = markerPlace;
		    }
		    var markerPlace = false;
		    markerPlace = this.addMarkerEtablissement();
		    if ((markerPlace) && (!currentPictGeopositionnee)) this.centerMapOnEstablishment();
		    if (!auMoinsUnMarker) auMoinsUnMarker = markerPlace;
		    
		    	
		}
		var display_map = "block";
		if (!auMoinsUnMarker) display_map = "none";
		document.getElementById("mapG").style.display = display_map;
		return auMoinsUnMarker;
	}
	
	
	
	this.displayInfoPhotoXL = function(){
	    var ArrayPhotos = this.arrayPhotosList[this.CurrentImage];
	    document.getElementById('PhotoXL').alt =  ArrayPhotos["titre"];
	    document.getElementById('PhotoXL').src = ArrayPhotos["link"];
	    document.getElementById("titre").innerHTML  = ArrayPhotos["titre"];
	    document.getElementById("commentaire").innerHTML  = ArrayPhotos["commentaire"];
	    document.getElementById("dateModification").innerHTML  = ArrayPhotos["dateModification"];
	    this.clearAndReplaceMarker();
	}
	
	
	
	this.loadMap = function(){
        if (GBrowserIsCompatible()) {
            // ON CREE LA MAP
	        this.map = new GMap2(document.getElementById("mapG"));

	        this.map.addControl(new GMapTypeControl());
	        this.map.addControl(new GLargeMapControl());	 
	        this.map.enableScrollWheelZoom();
       
	        var center = new GLatLng(0, 0);
    		this.map.setCenter(center, 10);
        }
    }
    
    this.addMarkerOnMap = function(n){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[n];
	        var x = ArrayPhotos["GPS_lat"];
	        var y = ArrayPhotos["GPS_long"];
            if ((x != 0) && (y != 0)){
                 var monMarker = this.makeMarker(n);
                 if (monMarker != null) this.map.addOverlay(monMarker);
                 return true;       
            }
        }
        return false;   
    }
    
    this.makeMarker = function(n){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[n];
	        var x = ArrayPhotos["GPS_lat"];
	        var y = ArrayPhotos["GPS_long"];
	        
	        if ((x != 0) && (y != 0)){
	            var point = new GLatLng(x,y);
	            
	            if (n == this.CurrentImage){
	                var monMarker = new GMarker(point);      	            
	            }
	            else{
                    var baseIcon = new GIcon();
                    baseIcon.iconSize=new GSize(12,20);
                    baseIcon.shadowSize=new GSize(20,22);
                    baseIcon.iconAnchor=new GPoint(6,20);
                    baseIcon.infoWindowAnchor=new GPoint(5,1);
	                var icon = new GIcon(baseIcon, 'http://labs.google.com/ridefinder/images/mm_20_green.png', null, 'http://labs.google.com/ridefinder/images/mm_20_shadow.png');
	                
	                var monMarker = new GMarker(point, icon);
	            }
        	    
	            //var titre = ArrayPhotos["titre"];
                GEvent.addListener(monMarker, "click", function() {
                    Slides.ClickThumb(n);
                    //if (titre != "") monMarker.openInfoWindowHtml("<b>"+titre+"</b>");
                });
                return monMarker;
            }
        }
        return null;
    }
    
    this.addMarkerEtablissement = function(){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[0];
	        var x = ArrayPhotos["GPS_lat_etablissement"];
	        var y = ArrayPhotos["GPS_long_etablissement"];
	        
	        if ((x != 0) && (y != 0)){
	            var point = new GLatLng(x,y);
	                
                var baseIcon = new GIcon();
                baseIcon.iconSize=new GSize(12,20);
                baseIcon.shadowSize=new GSize(20,22);
                baseIcon.iconAnchor=new GPoint(6,20);
                baseIcon.infoWindowAnchor=new GPoint(5,1);
                var icon = new GIcon(baseIcon, 'http://labs.google.com/ridefinder/images/mm_20_blue.png', null, 'http://labs.google.com/ridefinder/images/mm_20_shadow.png');
                
                var monMarker = new GMarker(point, icon);
                this.map.addOverlay(monMarker);
                if (ArrayPhotos["isGpsEtablissement"] == "True")this.map.setCenter(point);
                return true;     
            }
        }
        return false;
    }
    
    this.centerPointOnMap = function (){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[this.CurrentImage];
	        var x = ArrayPhotos["GPS_lat"];
	        var y = ArrayPhotos["GPS_long"];
            if ((x != 0) && (y !=0)){
                var center = new GLatLng(x, y);
		        this.map.setCenter(center);
		    }  
		}
    }
    
    this.centerThisPoint = function (n){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[n];
	        var x = ArrayPhotos["GPS_lat"];
	        var y = ArrayPhotos["GPS_long"];
            if ((x != 0) && (y !=0)){
                var center = new GLatLng(x, y);
		        this.map.setCenter(center);
		        return true;
		    } 
		    return false;
		}
    }
    
    this.centerMapOnEstablishment = function (){
        if (this.map != null){
            var ArrayPhotos = this.arrayPhotosList[this.CurrentImage];
	        var x = ArrayPhotos["GPS_lat_etablissement"];
	        var y = ArrayPhotos["GPS_long_etablissement"];
            if ((x != 0) && (y !=0)){
                var center = new GLatLng(x, y);
		        this.map.setCenter(center);
		    }  
		}
    }

}