jQuery(document).ready(function(){

	jQuery(".gallery").diaporama({
		animationSpeed: "slow",
		delay:3,
    controls: false
	});

});

/*
 *  $Id$
 *
 * (c) 2009 Thomas Rabaix <thomas.rabaix@soleoweb.com>
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.soleoweb.com>.
 */

function sfGmapWidget(options){
  // this global attributes
  this.mapzoom  = null;
  this.lng      = null;
  this.lat      = null;
  this.address  = null;
  this.map      = null;
  this.geocoder = null;

  // street view
  this.pitch    = null;
  this.yaw      = null;
  this.zoom     = null;
  this.pano     = null;

  this.svPresent = true;

  this.options  = options;

  this.init();
}

sfGmapWidget.prototype = new Object();

sfGmapWidget.prototype.init = function() {

  if(!GBrowserIsCompatible())
  {
    return;
  }

  // retrieve dom element
  this.pitch    = this.options.pitch;
  this.yaw      = this.options.yaw;
  this.zoom     = this.options.zoom;
  this.mapzoom  = this.options.mapzoom;
  this.lng      = this.options.lng;
  this.lat      = this.options.lat;
  this.svPresent = this.options.svPresent;

  this.old_lng  = null;
  this.old_lat  = null;

  this.panoOpts = {
    features: {
      streetView: true,
      userPhotos: false
    }
  };

  var point = new GLatLng(this.lat, this.lng);
  var pov = ({
    yaw: Number(this.yaw, 10),
    pitch: Number(this.pitch, 10),
    zoom: Number(this.zoom,10)
  });

  // create the google geocoder object
  this.geocoder = new GClientGeocoder();

  // create the map
  this.map = new GMap2(jQuery("#" + this.options.map).get(0));
  this.map.setCenter(point, 13);
  this.map.setUIToDefault();

  // cross reference object
  this.map.sfGmapWidget = this;
  this.geocoder.sfGmapWidget = this;

  // add the default location
  //  var point = new GLatLng(this.lat, this.lng);
  var marker = new GMarker(point);
  this.map.setCenter(point, 15);
  this.map.addOverlay(marker);


  if (this.options.svPresent)
  {
    this.myPano = new GStreetviewPanorama(jQuery("#" + this.options.pano).get(0), this.panoOpts);
    GEvent.addListener(this.myPano, "error", sfGmapWidget.handleNoFlash);
    this.svOverlay = new GStreetviewOverlay();
    this.myPano.setLocationAndPOV(point, pov);
    this.myPano.sfGmapWidget = this;
  }


}

sfGmapWidget.handleNoFlash = function(errorCode)
{
  switch (errorCode)
  {
    case GStreetviewPanorama.NO_NEARBY_PANO:
      alert("Erreur : aucun panorama trouvé.");
      break;
    case GStreetviewPanorama.FLASH_UNAVAILABLE:
      alert("Erreur : Flash doesn't appear to be supported by your browser.");
      break;
    default:
//      alert("Aucune carte Street Views");
      //      Query("#" + this.options.pano).get(0).html();
      break;
  }
}

