//function to hide the tool tip
function hideToolTip () {
  toolTip.style.visibility="hidden";
};

//function to show the tool tip
function showToolTip(marker) {
  toolTip.innerHTML = marker.tooltip;
  var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
  var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
  var anchor=marker.getIcon().iconAnchor;
  var width=marker.getIcon().iconSize.width;
  var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
  pos.apply(toolTip);
  toolTip.style.visibility="visible";
}; 

$(function() {
	// initialize scrollable
	$(".scrollable").scrollable();
});


function gotoCategory(urlname){
	if(urlname != 0){
		window.location=urlname;
	}
}


//function to hide the tool tip
function hideToolTip () {
toolTip.style.visibility="hidden";
};

//function to show the tool tip
function showToolTip(marker) {
toolTip.innerHTML = marker.tooltip;
var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
var anchor=marker.getIcon().iconAnchor;
var width=marker.getIcon().iconSize.width;
var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
pos.apply(toolTip);
toolTip.style.visibility="visible";
}; 

$(function() {

	// initialize scrollable
	$(".scrollable").scrollable();

});


function toggleExtraInfo(infoid){
	$("#extrainfo"+infoid).slideToggle("fast");
}

//Menu Toggle
$(document).ready(function(){

  $(".subcitytoggle").click(function () { 
      $(".subcitys").slideToggle("fast");
  });
  
  $("a#advancedSearchClick").click(function () { 
      $("#advancedSearch").slideToggle("fast");
  });
  
  
  $(".subtiptoggle").click(function () {
  	$(".subcitys").hide();
  	$(".subcountries").hide();
    $(".subtips").slideToggle("fast");
    });
  
  $(".subcountrytoggle").click(function () {
  	$(".subcitys").hide();
  	$(".subtips").hide();   	
    $(".subcountries").slideToggle("fast");
    });
 
  
  $(".merchanttoggle").click(function () {
  	$(".merchants").hide();
    $(".merchants").slideToggle("fast");
    });
  
  $(".thematoggle").click(function () {
	  	$(".subcitys").hide();
	  	$(".subtips").hide();   	
	    $(".themas").slideToggle("fast");
	    });
	 
      
  $("body").click(function () {
  	$(".subcitys").hide();
  	$(".subtips").hide();
  	$(".themas").hide();
  	$(".subcountries").hide();
  	$(".merchants").hide();
    });    
  
  $(".airlineticketrow").click(function () {  
	   	var merchant = $(this).attr('class'); 
		pageTracker._trackPageview('/merchants/'+merchant+''); 	   
	    window.location=$(this).find("a").attr("href");
	    return false;   
  }); 
  
  $(".airlineticketmerchantrow").click(function () {  
	   	var merchant = $(this).attr('class'); 
		pageTracker._trackPageview('/merchants/'+merchant+''); 	   
		window.open($(this).find("a").attr("href"));
	    return false;   
}); 
  
  
});

$(function() {
  $('a[rel*=external]').click( function() {
  	var merchant = $(this).attr('class'); 
  	pageTracker._trackPageview('/merchants/'+merchant+'');     
      window.open(this.href);
      return false;
  });
});

//load Google Map
function load(get, latcenter, longcenter, zoomlevel) {

  if (GBrowserIsCompatible()) {
  	var map = new GMap2(document.getElementById("googlemap"));
	var geocoder = new GClientGeocoder();
	map.setCenter(new GLatLng(0,0),0);
	geocoder.setBaseCountryCode("nl");

	//add controls
    map.addControl(new GMapTypeControl());

	//create randomnumber to prevent caching and retrieve xml file
    if(get != '' && get != 'false')
    {
    	GDownloadUrl("xml/hotellist.php?"+get, function(data, responseCode) {
    	    var xml = GXml.parse(data);
 
    		//store markers in markers array
    	    var markers   = xml.documentElement.getElementsByTagName("marker");
    	    
    	    //create bounds
    	    var bounds = new GLatLngBounds();
    	
    		//loop over the markers array
    		  for (var i = 0; i < markers.length; i++) {		  
    				// create marker icon
    				var icon = new GIcon();
    				icon.image =markers[i].getAttribute("icon");
    				icon.iconSize = new GSize(15, 20);
    				icon.iconAnchor = new GPoint(15, 20);
    				icon.infoWindowAnchor = new GPoint(5, 1);			  
    			    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    			                            parseFloat(markers[i].getAttribute("lng")));
    			    //map.addOverlay(new GMarker(point));
    			    bounds.extend(point);
    	
    		        var html 	 = markers[i].getAttribute("html");
    		        var deeplink = markers[i].getAttribute("deeplink");
    		        var marker 	 = createMarker(point, html, icon, deeplink);
    		        map.addOverlay(marker);
    				map.addControl(new GMapTypeControl());
    			  }
    		  	// end loop


      		 if(zoomlevel != false){
      			 map.setZoom(zoomlevel);
      		 }else{
      
      			map.setZoom(14);
      		 }
    		   
    			   map.setCenter(new GLatLng(latcenter, longcenter));
    		   
    	       map.setUIToDefault();
    	       map.disableScrollWheelZoom();

    		  }
    		); //close GDownloadUrl
    }

	//Create marker and set up event window
	function createMarker(point,html,icon, deeplink){
	  var marker = new PdMarker(point,icon);
	  GEvent.addListener(marker, "click", function() {
		  window.location=deeplink;
	  }); 
	  GEvent.addListener(marker, 'mouseover', function() {
			marker.setTooltip(html);
	   }); 
	  return marker;
	}

  } //close GBrowserIsCompatible
} //close load

//load Google Map
function loadCityOverview() {

  if (GBrowserIsCompatible()) {
  	var map = new GMap2(document.getElementById("googlemap"));
	var geocoder = new GClientGeocoder();
	map.setCenter(new GLatLng(0,0),0);
	geocoder.setBaseCountryCode("nl");

	//add controls
    map.addControl(new GMapTypeControl());


    	GDownloadUrl("xml/citylist.php", function(data, responseCode) {
    	    var xml = GXml.parse(data);
 
    		//store markers in markers array
    	    var markers   = xml.documentElement.getElementsByTagName("marker");
    	    
    	    //create bounds
    	    var bounds = new GLatLngBounds();
    	
    		//loop over the markers array
    		  for (var i = 0; i < markers.length; i++) {		  
    				// create marker icon
    				var icon = new GIcon();
    				icon.image =markers[i].getAttribute("icon");
    				icon.iconSize = new GSize(15, 20);
    				icon.iconAnchor = new GPoint(15, 20);
    				icon.infoWindowAnchor = new GPoint(5, 1);			  
    			    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    			                            parseFloat(markers[i].getAttribute("lng")));
    			    //map.addOverlay(new GMarker(point));
    			    bounds.extend(point);
    	
    		        var html 	 = markers[i].getAttribute("html");
    		        var deeplink = markers[i].getAttribute("deeplink");
    		        var marker 	 = createMarker(point, html, icon, deeplink);
    		        map.addOverlay(marker);
    				map.addControl(new GMapTypeControl());
    			  }
    		  	// end loop
    		  
    	       // ===== determine the zoom level from the bounds =====
      		   var zoomlevel = map.getBoundsZoomLevel(bounds);

   	           // ===== determine the centre from the bounds ======
    		   map.setZoom(4);
    		   
    		   map.setCenter(new GLatLng('47.26921', '11.4041'));
    		   
    	       map.setUIToDefault();
    	       map.disableScrollWheelZoom();

    		  }
    		); //close GDownloadUrl
    

	//Create marker and set up event window
	function createMarker(point,html,icon, deeplink){
	  var marker = new PdMarker(point,icon);
	  GEvent.addListener(marker, "click", function() {
		  window.location=deeplink;
	  }); 
	  GEvent.addListener(marker, 'mouseover', function() {
			marker.setTooltip(html);
	   }); 
	  return marker;
	}

  } //close GBrowserIsCompatible
} //close load


//load Google Map
function loadCountryMap(country) {
if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("googlemap"));
	var geocoder = new GClientGeocoder();
	map.setCenter(new GLatLng(0,0),0);
	geocoder.setBaseCountryCode("nl");

	//add controls
	map.addControl(new GMapTypeControl());

	//create randomnumber to prevent caching and retrieve xml file

	    GDownloadUrl("xml/country.citylist.php?urlname="+country, function(data, responseCode) {
	    var xml = GXml.parse(data);
	
		//store markers in markers array
	    var markers = xml.documentElement.getElementsByTagName("marker");
	
	    //create bounds
	    var bounds = new GLatLngBounds();
	
		//loop over the markers array
		  for (var i = 0; i < markers.length; i++) {
			  
				// create marker icon
				var icon = new GIcon();			
				icon.image = "http://www.stedenreis.com/images/markers/Bezienswaardigheden.png";
				icon.shadow = "http://www.stedenreis.com/images/markers/Bezienswaardigheden.png";
				icon.iconSize = new GSize(12, 20);
				icon.iconAnchor = new GPoint(22, 20);
				icon.infoWindowAnchor = new GPoint(5, 1);			  
			    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
			                            parseFloat(markers[i].getAttribute("lng")));
			    //map.addOverlay(new GMarker(point));
			    bounds.extend(point);
	
		        var html 	 = markers[i].getAttribute("html");
		        var deeplink = markers[i].getAttribute("deeplink");
		        var marker 	 = createMarker(point, html, icon, deeplink);
		        map.addOverlay(marker);
				map.addControl(new GMapTypeControl());
			  }
		  	// end loop
		  
	      // ===== determine the zoom level from the bounds =====
		  var zoomlevel = map.getBoundsZoomLevel(bounds);
	
		   var zoomlevel = zoomlevel-1;
		   
		   
		   map.setZoom(zoomlevel);
	
	       // ===== determine the centre from the bounds ======
		   map.setZoom(zoomlevel);
		   map.setCenter(bounds.getCenter());
	       map.setUIToDefault();
	       map.disableScrollWheelZoom();
		  }
		); //close GDownloadUrl


	//Create marker and set up event window
	function createMarker(point,html,icon, deeplink){
	  var marker = new PdMarker(point,icon);
	  GEvent.addListener(marker, "click", function() {
		  window.location=deeplink;
	  }); 
	  GEvent.addListener(marker, 'mouseover', function() {
			marker.setTooltip(html);
	   }); 
	  return marker;
	}
  } //close GBrowserIsCompatible
} //close load

//function to hide the tool tip
function hideToolTip () {
	toolTip.style.visibility="hidden";
};

//function to show the tool tip
function showToolTip(marker) {
	toolTip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(toolTip);
	toolTip.style.visibility="visible";
}; 

