  //shimmyShim(document.getElementById('Matches'));
 // create shim to hide selects in IE
function shimmyShim(object)
{
	//if (navigator.userAgent.indexOf("MSIE") != -1)
	//{
		var iframeShim = document.createElement("<iframe scrolling='no' frameborder='0' id='shim"+object.id+"' "+
		                                        "style='position:absolute; top:0px;"+
		                                        "left:0px; display:block; "+
		                                        "width: 100%; z-index:-1;' src='javascript:false'></iframe>");
		iframeShim.style.height = object.offsetHeight;
		iframeShim.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		var result = object.appendChild(iframeShim);
		//alert("here");
	//}
}

function toggleMapPanel(theLink){
  if (theLink.className == 'mapLaunch') {
	document.getElementById('showhideTxt').innerHTML = 'Hide Map';
    var mapDiv = document.getElementById("mapLayerContainer");
    mapDiv.style.display = "block";
    theLink.className = 'mapHide';
    document.getElementById('rightCol').className = 'rightCol1';
    loadMapData();
  } else if (theLink.className =='mapHide' ) { 
	document.getElementById('showhideTxt').innerHTML = 'Show on Map';  
    var allDivs = document.getElementById("mapLayerContainer");
    allDivs.style.display = "none";
    theLink.className = 'mapLaunch';
    document.getElementById('rightCol').className = 'rightCol';
  } else if (theLink.className == 'hideMapTab') {
	document.getElementById('showhideTxt').innerHTML = 'Show on Map';  
    var allDivs = document.getElementById("mapLayerContainer");
    allDivs.style.display = "none";
    document.getElementById('rightCol').className = 'rightCol';
  } 
}

function toggleMapPanelHN(theLink,hostelnumber){
  if (theLink.className == 'showonmap') {
	 
    var allDivs = document.getElementById("gPopupMapFeature");
    allDivs.style.display = "block";
    allDivs.style.visibility='visible';
    plotSingleHostelMap(theLink,hostelnumber);
    var pos = getPosition(theLink); //gets the x/y coords of the button
    allDivs.style.top=(pos.offsetTop - 370)+'px'; //re-positions the div top
    allDivs.style.left=(pos.offsetLeft - 260) +'px'; //repositions the div left
    allDivs.style.position = "absolute";
    allDivs.style.zindex = 19999;
    
    //shimmyShim(document.getElementById('gPopupMapFeature')); 
  } 
}

function closeMiniMap(theLink) {
    var allDivs = document.getElementById("gPopupMapFeature");
    allDivs.style.display = "none";
}

function getPosition(element) {
  var left = 0;
  var top = 0;
  if(element.offsetParent) {
    while(element) {
      left += element.offsetLeft;
      top += element.offsetTop;
      element = element.offsetParent;
    }
  }
  return {offsetLeft: left, offsetTop: top};
}


function GetCurrencyValue (currency) {
  for (var i = 0; i < document.theForm.elements.length; i++) {
    if (document.theForm.elements[i].name == 'FABCurrency') {
      for (var j = 0; j < document.theForm.elements[i].length; j++) {
        if (document.theForm.elements[i].options[j].value == currency) {
          document.theForm.elements[i].options[j].selected = true;
        }
      }
    }
  }
}

function registerCurrency (currency) {
  var rand = Math.random();

  document.images.currencyImage.src = '/getcurrency_img.php?Currency=' + currency + '&r=' + rand;
}

var map;
var minimap;
var markerArray = new Array();
var markerHtml = new Array();
var initialCentre;

function buildPropIcon () {
  propIcon = new GIcon();
  propIcon.image            = '/images/hostels.com/maps/hostels-com-map-pin-standard.png';
  propIcon.shadow           = '/images/hostels.com/maps/hostels-com-map-pin-shadow.png';
  propIcon.iconSize         = new GSize(30,32);
  propIcon.shadowSize       = new GSize(59, 32);
  propIcon.iconAnchor       = new GPoint(6, 18);
  propIcon.infoWindowAnchor = new GPoint(9, 6);
  propIcon.imageMap         = [1,1, 1,18, 6,18, 6,21, 10,18, 20,18, 20,1, 1,1];

  return propIcon;
}

function buildPropFeaturedIcon () {
  propIcon = new GIcon();
  propIcon.image            = '/images/hostels.com/maps/hostels-com-map-pin-featured.png';
  propIcon.shadow           = '/images/hostels.com/maps/hostels-com-map-pin-shadow.png';
  propIcon.iconSize         = new GSize(30,32);
  propIcon.shadowSize       = new GSize(59, 32);
  propIcon.iconAnchor       = new GPoint(6, 18);
  propIcon.infoWindowAnchor = new GPoint(9, 6);
  propIcon.imageMap         = [1,1, 1,18, 6,18, 6,21, 10,18, 20,18, 20,1, 1,1];

  return propIcon;
}

function createMarker (map, point, propIcon, html, hostelName) {
  var marker = new GMarker(point, {icon: propIcon, title: hostelName});

  GEvent.addListener(marker, 'click', function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function addPlotCityHostelsMap(divID,centerLat,centerLng,zoomLevel) {

  if (GBrowserIsCompatible()) {
    normalIcon =  buildPropIcon();
    featuredIcon = buildPropFeaturedIcon();

    window.mapControls = {};
    window.mapControls['largeC'] = new GLargeMapControl(); 
    window.mapControls['menuC'] = new GMenuMapTypeControl();

    mapState = document.getElementById('shownMap').value;
    if ((divID == 'plotCityHostelsMap') && (mapState == "false" || !window.map)) {
      map = new GMap2(document.getElementById(divID));

      initialCentre = centerPoint;

      map.addControl(window.mapControls['largeC']); 
      map.addControl(window.mapControls['menuC']);
      document.getElementById('shownMap').value = true;
      window.map=map;
    }

    miniMapState = document.getElementById('shownMiniMap').value;
    if ((divID == 'plotCityHostelsMiniMap') && (miniMapState == "false" || !window.minimap)) {
      minimap = new GMap2(document.getElementById(divID));
      normalIcon =  buildPropIcon();
      featuredIcon = buildPropFeaturedIcon();

      initialCentre = centerPoint;
  
      minimap.addControl(window.mapControls['largeC']); 
      minimap.addControl(window.mapControls['menuC']);
      document.getElementById('shownMiniMap').value = true;
      window.minimap = minimap;
    } else if ((divID == 'plotCityHostelsMiniMap') && (miniMapState == "true")) {
      if (window.minimarker) {
         window.minimap.removeOverlay(window.minimarker);
      }
    }

    // add marker for every hostel we have the co-ords of.
    var lat, lng, hnum, hname;
    var point;
    var html;  
    if (divID == 'plotCityHostelsMiniMap') { 
        hnum  = arguments[4][0];
        hname = arguments[4][1];
        lat   = arguments[4][2];
        lng   = arguments[4][3];
        isFeatured = arguments[4][4];  
        html  = arguments[4][5];
        point = new GLatLng(lat, lng);
        propIcon = isFeatured  == '1' ? featuredIcon : normalIcon;
        var centerPoint = new GLatLng(lat, lng);
        window.minimap.setCenter(centerPoint, zoomLevel);

        window.minimarker = createMarker(window.minimap, point, propIcon, html, hname);
        window.minimap.addOverlay(window.minimarker);
        markerArray[hnum] = window.minimarker;
        markerHtml[hnum] = html;
    } else {  
      for (var i = 4; i < arguments.length; ) {
        hnum  = arguments[i]; i++;
        hname = arguments[i]; i++;
        lat   = arguments[i]; i++;
        lng   = arguments[i]; i++;
        isFeatured = arguments[i]; i++;  
        html  = arguments[i]; i++; 
        point = new GLatLng(lat, lng);
        propIcon = isFeatured  == '1' ? featuredIcon : normalIcon;
        var centerPoint = new GLatLng(centerLat, centerLng);
        window.map.setCenter(centerPoint, zoomLevel);
  
        window.marker = createMarker(window.map, point, propIcon, html, hname);
        window.map.addOverlay(window.marker);
        markerArray[hnum] = window.marker;
        markerHtml[hnum] = html;
      }
    }
  }
}

function MoveMap (xVal, yVal, hnum) {
  map.panTo(markerArray[hnum].getPoint(), 13);

  if (markerArray[hnum]) {
    markerArray[hnum].openInfoWindowHtml(markerHtml[hnum]);
  }
}


function updateManPosition (latlng) {
  window.streetviewMiniMe.setLatLng(latlng);
  openStreetviewAtPos(latlng);
}

function cleanup () {
}

function onNewLocation (location) {
  window.streetviewMiniMe.setLatLng(location.latlng);

  // Get the original x + y coordinates
  var iw = map.getPane(G_MAP_FLOAT_PANE).firstChild;
  var originalX = parseInt(iw.style.left);
  var originalY = parseInt(iw.style.top);

  // Move the infowindow 
  map.getInfoWindow().reposition(location.latlng, new GSize(10, -10));

  // Get the new x + y coordinates
  var iw = map.getPane(G_MAP_FLOAT_PANE).firstChild;
  var newX = parseInt(iw.style.left);
  var newY = parseInt(iw.style.top);

  // Re-position the map to show the infowindow in full
  map.getDragObject().moveBy(new GSize(-(newX - originalX), -(newY - originalY))); 
}

function onYawChange (newYaw) {
  var GUY_NUM_ICONS = 16;
  var GUY_ANGULAR_RES = 360/GUY_NUM_ICONS;

  if (newYaw < 0) {
    newYaw += 360;
  }

  guyImageNum = Math.round(newYaw/GUY_ANGULAR_RES) % GUY_NUM_ICONS;
  guyImageUrl = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-" + guyImageNum + ".png";

  window.streetviewMiniMe.setImage(guyImageUrl);
}

function onDragEnd (latlng) {
  openStreetviewAtPos(latlng);  
}
