/*NOTES:

No data is in KML format its already in JSON - as its not going to be updated often.
The virtual tours are creating my using a JQUERY PLUGIN called jquery.panorama.js it not in global as we have had to hack it a little for this App.

*/


<!-- THIS IS THE CODE OF THE VIRTUAL TOUR SECTION -- >


function virtual_tours_content() {
	
	cleanup_overlays();	
	$sidehtml = $("<h2>Virtual Tours</h2><table id='sidebarTABLE'><tbody id='sidebarTBODY'></tbody></table><br><h2>More Tours</h2><p>More information on guided tours can be found on the <a href='http://www.adelaide.edu.au/tours/'>Campus Tours website.</a></p><ul><li><a href='http://www.adelaide.edu.au/tours/virtual/nt/'>Flash Virtual Tours</a></li></ul>");
	$("#sidebar").empty();
	$("#sidebar").append($sidehtml);
	virtual_tours_markers();
}

function virtual_tours_markers() {
	$ul = $("<ul class='nobullet' ></ul>")	
    $li = $("<li></li>");
	
	var vticon = new GIcon(G_DEFAULT_ICON);
	vticon.image = "http://www.adelaide.edu.au/global/images/icons/gmaps/kml/virtualtour.png";
	vticon.iconSize = new GSize(32, 37);
	vticon.iconAnchor = new GPoint(15, 37);
	vticon.infoWindowAnchor = new GPoint(15, 6);
	vticon.shadow = "http://www.adelaide.edu.au/global/images/icons/gmaps/kml/shadow-university.png";
	vticon.shadowSize = new GSize(51.0, 37.0);
	
	var markerOptions = {icon:vticon};
	centre_map();
	
	
	for (var id in vtours)
	{
		function MarkerManagement (id)
		{
			var tour = vtours[id];
			var name = tour['name'];
			
		    var $sublayername = $("<a id='" + id +"'href='#'>" + name +"</a>").click(function(){ tour_info(this.id); return false;});
	        var $sublayericon = $('<img width="22" height="22" src="http://www.adelaide.edu.au/global/images/icons/gmaps/kml/virtualtour.png" />');
			var $TD = $('<td></td><td></td>');
		    $TD.eq(0).append($sublayericon);
		    $TD.eq(1).append($sublayername);
			var $TR = $('<tr></tr>');
		    $TR.append($TD);
		    $("#sidebarTBODY").append($TR);
	
			var src = tour['src'];
			var point = new GLatLng(tour['lat'], tour['lng']);
			var marker = new GMarker(point, markerOptions);

		GEvent.addListener(marker, "click", function() {
			tourinfowindow(name, src, point);
		});
		
		map.addOverlay(marker); 		
		}
	MarkerManagement(id);	
	}
	
}

// opens infowindows for virtual tours from sidebar controls.
function tour_info(id) {
	var tour = vtours[id];
	var name = tour['name'];
	var point = new GLatLng(tour['lat'], tour['lng']);
	var src = tour['src'];
	tourinfowindow(name, src, point);
}

function tourinfowindow(name, src, point) {
	map.setZoom(17);
	var myHtml = "<div id='page' style='width:450px; height:410px'><h2>" + name + "</h2></div>";
	var imgHTML = "<img src='" + src + "' class='panorama' height='375px' width='2640px'>";
	map.openInfoWindowHtml(point, myHtml ,{onOpenFn: function(){ $("#page").append(imgHTML)  }, onCloseFn: function() {centre_map();}});
	setTimeout("$('img.panorama').panorama();",200);
}
	
