/*
	Last published on : 27-Apr-10 11:31
	Location          : \commercial\destinationguide\cms\destinationguide_onlrb\static\js
	Filename          : slider.js
*/
/*  
	Last published on : 6/9/2008 13:45
	Location          : \commercial\destinationguide\cms\destinationguide\static\js
	Filename          : slider.js
*/
var gMapImagePath = window.contextroot + "/static/img/map-gfx/";
// == Some global variables ==
var XSLIDERLENGTH = 67;
var MAXZOOM = 17;

// == Create a Custom GControl ==
function XSliderControl() {}
XSliderControl.prototype = new google.maps.Control();

// == This function positions the slider to match the specified zoom level ==
XSliderControl.prototype.setSlider = function(zoom) {
  var left = Math.round((XSLIDERLENGTH/MAXZOOM*zoom));
 
  this.slide.left = left;
  this.knob.style.left = left+"px";
    /* unnecesary because no bubble is only displayed when hovering.
  close_all_windows();
    if(multi != 1){
    if(activeMarker != undefined && active != undefined){
      show_custom_info_window(activeMarker, active);
    }
    window.setTimeout(function() {hide();},20);
  } else {
    if(checkerHover == 1){
      show_custom_info_window(activeMarkerHover, activeHover);
    } else {
      show_custom_info_window(activeMarker, active);
    }
  } */
}

// == This function reads the slider and sets the zoom level ==
XSliderControl.prototype.setZoom = function() {
  var z=Math.round(this.slide.left*MAXZOOM/XSLIDERLENGTH);
  this.map.setZoom(z);
  /* unnecesary tempcoord */
 // var tempcoord = map.fromDivPixelToLatLng(map_point[active]);
}

// == This gets called bu the API when addControl(new YSlider()) is used ==
XSliderControl.prototype.initialize = function(map) {
  // obtain Function Closure on a reference to "this"
  var that=this;
  // store a reference to the map so that we can call setZoom() on it
  this.map = map;
  
  // Is this MSIE, if so we need to use AlphaImageLoader
  var agent = navigator.userAgent.toLowerCase();
  if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){this.ie = true} else {this.ie = false}

  // create the background graphic as a <div> containing an image
  var container = document.createElement("div");
  container.className = "map-slider";
  
  var slidercontainer = document.createElement("div");
  slidercontainer.className = "map-slider-container";
  // Handle transparent PNG files in MSIE
  if (this.ie) {
    container.innerHTML = '<img src="'+ gMapImagePath +'zoomBG.gif"  width=112 height=23 >';
    container.appendChild(slidercontainer);
  } else {
    container.innerHTML = '<img src="'+ gMapImagePath +'zoomBG.png"  width=112 height=23 >';
  }

  // create the knob as a GDraggableObject
  this.knob = document.createElement("img"); 
  this.knob.src = gMapImagePath + "zoomScrub.png";
  this.knob.height = "13";
  this.knob.width = "13";
  this.knob.style.marginLeft = "15px";
  this.knob.style.marginTop = "5px";
  this.knob.style.top = "-5px";
  this.knob.style.position = "absolute";
  if (this.ie) {
    this.knob.src = gMapImagePath + "zoomScrub.gif";
    this.knob.className = "zoomScrubIE"
  }
  container.appendChild(this.knob);
  if (this.ie) {
    this.slide=new google.maps.DraggableObject(this.knob, {container:slidercontainer});
  } else {
    this.slide=new google.maps.DraggableObject(this.knob, {container:container});
  }

  // attach the control to the map
  map.getContainer().appendChild(container);
  
  // Listen for other things changing the zoom level and move the slider
  google.maps.Event.addListener(map, "zoomend", function(a,b) {
    that.setSlider(b);
  });

  // Listen for the slider being moved and set the zoom level
  google.maps.Event.addListener(this.slide, "dragend", function() {that.setZoom()});

  return container;
}

// == Set the default position for the control ==
XSliderControl.prototype.getDefaultPosition = function() {
  return new google.maps.ControlPosition(G_ANCHOR_BOTTOM_RIGHT);
}
