
var debug = false;
var map = null;
var map_floormap_div = null;
var chicago = new google.maps.LatLng(40.740, -74.18);
var infowindow = null;
var groundOverlayMap =null;
var tourMap = null;
var panoramaMap = null;//
var floorMap = null;
var church = new google.maps.LatLng(36.712803,-76.322869);
var swChurchCoord = new google.maps.LatLng(40.716216,-74.213393);
var neChurchCoord = new google.maps.LatLng(40.765641,-74.139235);
var tourMarker = null;
var markerArr = null;
var contentType = '';
var content = null;
//var church = new google.maps.LatLng(36.712843, -76.32214899999997);

var entryPanoId = null;
google.maps.Marker.prototype.locationName = 'office';
var roomArr =  [
['sanctuary', 40.74052025477915, -74.1727043914795], 
['office_pastor', 40.7245205591596, -74.14978759765626],
['parking',40.75931172999705, -74.18051498413087]
];
function initializeVirtualTour() {
	map_floormap_div = document.getElementById("map_floorplan");
	if(map_floormap_div != null){
		church = chicago;
		initializeBaseMap() ;
		initMarkers();	
		initInfoWindow();	
	}
}



function initializeBaseMap() {
  var mapOptions = {
    zoom: 14,
	minZoom:14,
	maxZoom:17,
    center: church,
	mapTypeControl: false,
    mapTypeControlOptions: {
      mapTypeIds: ['coordinate'],
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    }
  };
  map = new google.maps.Map(map_floormap_div, mapOptions);
  map.mapTypes.set('coordinate',coordinateMapType);
  map.setMapTypeId('coordinate');

	var imageBounds = new google.maps.LatLngBounds(swChurchCoord, neChurchCoord);
	groundOverlayMap = new google.maps.GroundOverlay("hop2_resources/images/floor_plan.jpg", imageBounds, {clickable:false});
	groundOverlayMap.setMap(map);
	if(debug == true){
		tourMarker = new google.maps.Marker({
			position: church,
			map: map,
			clickable: true,
			visible: true
		});	
		addMapListener();
	}
}	
function addMapListener(){
   google.maps.event.addListener(map,'click', function(event) {
	infowindow.setContent(event.latLng.toString());
	infowindow.open(map, tourMarker);
  });    
}



function initInfoWindow(){
	infowindow = new google.maps.InfoWindow({ content: '<div id="room_info"></div>', maxWidth: '500px'});
		google.maps.event.addListener(infowindow, "domready", function() {
			
      }
    );	
}

function initMarkers(){
	markerArr = [];
	for(var i = 0; i < roomArr.length; i++){
		var pos = new google.maps.LatLng(roomArr[i][1], roomArr[i][2]);
		var marker = new google.maps.Marker({
			position: pos,
			map: map,
			clickable: true,
			visible: true
		});
		marker.locationName = roomArr[i][0];
		addClickListener(marker);
		markerArr.push(marker);		
	}	
}

function addClickListener(marker){
	   google.maps.event.addListener(marker, 'click', function() {
		var content = null;
		contentType = marker.locationName;
	content = null;
		switch(contentType){
			case 'sanctuary':
				//_hnudHm4JMk
				content = createRoomInfoVideoPanel('Sanctuary','yCw0VjWK97Y');
			break;
			case 'office_pastor':
				content = createRoomInfoVideoPanel('Pastors Office','85RLs1FpBIY');
			break;
			case 'parking':
			var picassaLink = 'https://picasaweb.google.com/otols00/RCCGHOP941WESTRDPARKINGLOT?feat=directlink';
			var picassa = '<embed type="application/x-shockwave-flash" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" width="288" height="192" flashvars="host=picasaweb.google.com&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fotols00%2Falbumid%2F5608189093427885409%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
				content = createSlideshowInfoPanel('Parking Lot' ,picassa, picassaLink);
			break;					
			default:
			break;
		}
		if(content != null){
		infowindow.open(map, marker);
		setTimeout("",10000);		
		infowindow.setContent(content);
		//
		}
	});
}
function updateInfowindow(){
	
}
function createRoomInfoVideoPanel(name, videolink){
	var youtube = '<object width="400" height="200"><param name="movie" value="http://www.youtube.com/v/'+videolink+'?fs=1&amp;hl=en_US&showinfo=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videolink+'?fs=1&amp;hl=en_US&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="200"></embed></object>';

	str = '<table width="100%"  align="center" cellpadding="0" cellspacing="2" border="0">';
	str += '<tr>';
	str += '<td valign="middle" align="left">'+name+'</td>';
	str += '</tr>';		
	str += '<tr>';
	str += '<td valign="middle"  height="200px" style="position:relative;top:0px;left:0px;z-index:10;">'+ youtube +'</td>';
	str += '</tr>';		
	str += '</table>';
	return str;
}
function createSlideshowInfoPanel(name, slideshowEmbed, slideshowLink){

	str = '<table width="100%"  align="center" cellpadding="0" cellspacing="2" border="0">';
	str += '<tr>';
	str += '<td valign="middle" align="left"><a href="'+slideshowLink+'">'+name+'</a></td>';
	str += '</tr>';		
	str += '<tr>';
	str += '<td valign="middle" >'+ slideshowEmbed +'</td>';
	str += '</tr>';		
	str += '</table>';
	return str;
}

function CoordMapType() {
}

CoordMapType.prototype.tileSize = new google.maps.Size(256,256);
CoordMapType.prototype.maxZoom = 19;

CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
  var div = ownerDocument.createElement('DIV');
 // div.innerHTML = coord;
  div.style.width = this.tileSize.width + 'px';
  div.style.height = this.tileSize.height + 'px';
  div.style.fontSize = '10';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';
  div.style.borderColor = '#FFFFFF';
  div.style.backgroundColor = '#FFFFFF';
  return div;
};

CoordMapType.prototype.name = "New Church";
CoordMapType.prototype.alt = "Tile Coordinate Map Type";

var coordinateMapType = new CoordMapType();
