﻿	$(document).ready(function() {
	    load();
	});
	
	function load() {
		var t;
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		//
        map.setCenter(new GLatLng(24, 16), 2);
		map.enableScrollWheelZoom();
		for (var i = 0; i < tours.length; i++) {
			t=new CTour(tours[i]);
			map.addOverlay(createMarker(t));
		}
		map.addControl(new GOverviewMapControl());
      }
    }
	
	function createMarker(t) {
		var marker = new GMarker(new GLatLng(t.Lat,t.Lng));
		GEvent.addListener(marker, "click", function() {
            //marker.openInfoWindowHtml(showInfoWindow(marker), {maxWidth: '250'});
			marker.openInfoWindowTabsHtml(showInfoWindow(marker), {maxWidth: '252'});
        }); 
		return marker;
	}
	
	
	function showInfoWindow(marker) {
		var pt=marker.getPoint();
		var t;
		var tabs=new Array();
		var idx=1;
		for (var i = 0; i < tours.length; i++) {
			t=new CTour(tours[i]);
			if(t.Lat==pt.lat() && t.Lng==pt.lng()) {
				tabs.push(createTourTab("No. "+idx, t));
				idx++;
			}
		}
		return tabs;
	}
	
	function createTourTab(title, t) {
		var tmp;
		tmp="<h3 style='text-align:left'>"+t.RegionName+"</h3>";
		tmp+="<img hspace='0' vspace='0' src='si.aspx?FN="+t.ImageName+"&W=180&H=140' width='180px' height='140px'  border=\"0\" class=\"imgborder\" title=\""+t.Title+"\" />";
		//tmp+="<img src='"+t.ImageName+"' border=\"0\" class=\"imgborder\" title=\""+t.Title+"\" />";
		tmp+="<h4 style='text-align:left'><a href='duration.aspx?DID="+t.Duration_ID+"'>"+t.Title+"</a></h4>";
		tmp+="<p class='Medium' style='margin-bottom:10px; text-align:left'>"+t.Overview+"</p><br/>";
		return new GInfoWindowTab(title, tmp);
	}
	
	function findTourById(id) {
		for(var i=0; i<tours.length; i++) {
			if (tours[i][0]==id) return new CTour(tours[i]);
		}
		return null;
	}
	function CTour(it) {
		this.ID=it[0];
		this.ImageName=it[1];
		this.Title=it[2];
		this.Overview=it[3];
		this.RegionName=it[4];
		this.Duration_ID=it[5];
		this.Lat=it[6];
		this.Lng=it[7];
	}