/* ***************************************************************
		Function to reset the gallery viewport to a still image, so 
		media isn't playing in more than one window at once
***************************************************************** */
function swapreset() {
	document.getElementById('GalleryViewport').innerHTML   =  
		'<img alt="" src="/img/ipixbackground.jpg" width="211" height="159" />';
}


/* ***************************************************************
		Draws a modal popup in front of the browser for displaying
		media from the media gallery
***************************************************************** */
function modalWin(URL, width, height) {
	swapreset();
	if (window.showModalDialog) { 
		window.showModalDialog(URL,'new_win','dialogWidth:'+width+'px;dialogHeight:'+height+'px');
	} else {
	window.open(URL,'new_win','height='+height+',width='+width+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
	}
}



/* ***************************************************************
    Sets the sizing for the media gallery popup window
***************************************************************** */
function GalleryEnlargePopUp(URL,type) {
	if(type == 'tour') {
		width = 450; 	height = 380;
	}
	if(type == 'video') {
		width = 450; 	height = 380;
	}
	if(type == 'image') {
		width = 660; 	height = 625;
	}
		modalWin(URL,width,height);   // call modalWin function to produce window
}



/* ****************************************************************
    function for swapping Images into the Media Gallery Viewport
***************************************************************** */
function MGSwapImage(SiteAlias, PropertyAlias, ImageID, MediaServerFQDN) {

	// swap in the image to the viewport  (uses INNERHTML method)
	document.getElementById('GalleryViewport').innerHTML   =  
		'<img alt="" src="http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/images/med/'+ImageID+'_M_.jpg" width="211" height="159" />';

	// swap in the contents of the "enlarge" container underneath the viewport
	document.getElementById('GalleryViewportEnlarge').innerHTML =
		'<a href="'+ImageID+'/" onclick="GalleryEnlargePopUp(\''+ImageID+'/\',\'image\'); return false;">Enlarge</a>';
}



/* ***************************************************************
		function for swapping Flash Progressive Download videos
		into media gallery viewport
***************************************************************** */

function MGSwapVideo(SiteAlias, PropertyAlias, VideoID, MediaServerFQDN, CurrentFQDN) {

	// set up some common variables
	var FLVPlayerSourceDir = '/img';
	var SkinSourceDir = '/img';
	var SkinName = 'Clear_Skin_1';
	
	// sets the format of the URL for accessing media; is inserted into the enlarge link
	var MediaPageURL = 'http://'+MediaServerFQDN+'/videos/'+SiteAlias+'/'+PropertyAlias+'/'+VideoID+'/';
	
	// swap in the Flash Progressive download object code  (uses INNERHTML method)
	document.getElementById('GalleryViewport').innerHTML =
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="211" height="159" id="FLVPlayer1">'+
			'<param name="movie" value="'+FLVPlayerSourceDir+'/FLVPlayer_Progressive.swf" />'+
			'<param name="salign" value="lt" />'+
			'<param name="quality" value="high" />'+
			'<param name="scale" value="noscale" />'+
			'<param name="FlashVars" value="&MM_ComponentVersion=1&skinName='+SkinSourceDir+'/'+SkinName+'&streamName=http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/video/'+VideoID+'&autoPlay=true&autoRewind=false" />'+
			'<embed src="'+FLVPlayerSourceDir+'/FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName='+SkinSourceDir+'/'+SkinName+'&streamName=http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/video/'+VideoID+'&autoPlay=true&autoRewind=false" quality="high" scale="noscale" width="211" height="159" name="FLVPlayer1" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
		'</object>';
		
	// swap in the contents of the "enlarge" container underneath the viewport
	document.getElementById('GalleryViewportEnlarge').innerHTML =
		'<a href="'+MediaPageURL+'" onclick="GalleryEnlargePopUp(\''+MediaPageURL+'\',\'video\');  return false;">Enlarge</a>';
}



/* ***************************************************************
		function for swapping virtual tours into gallery viewport
***************************************************************** */
function MGSwapTour(SiteAlias, PropertyAlias, TourID, MediaServerFQDN, CurrentFQDN, TourType) { 

	switch(TourType) {
	
		case 'ipx':
		
			// swap in the tour to the viewport (uses INNERHTML method)
			document.getElementById('GalleryViewport').innerHTML     = 
				'<applet height="159" codebase="http://'+CurrentFQDN+'/img" archive="IpixViewer.jar" width="211" align="bottom" code="IpixViewer.class" name="IpixViewer">'+
					'<param name="URL" value="http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/tours/'+TourID+'.ipx" />'+
					'<param name="toolbar" value="on" />'+
					'<param name="splashbg" value="f7f2ea" />'+
					'<param name="splash" value="http://'+CurrentFQDN+'/img/ipixbackground.jpg">'+
					'<param name="HelpURL" value="help/java3_2" />'+
					'<param name="SpinSpeed" value="-5" />'+
					'<param name="SpinStyle" value="flat" /><img alt="beach pictures" src="http://'+CurrentFQDN+'/img/ipixbackground.jpg" width="211" height="159" class="imgGallery" /></applet>';
		
				// swap in the contents of the "enlarge" container underneath the viewport
				document.getElementById('GalleryViewportEnlarge').innerHTML =
					'<a href="http://'+MediaServerFQDN+'/tours/'+SiteAlias+'/'+PropertyAlias+'/'+TourID+'/" onclick="GalleryEnlargePopUp(\'http://'+MediaServerFQDN+'/tours/'+SiteAlias+'/'+PropertyAlias+'/'+TourID+'/\', \'tour\');  return false;">Enlarge</a>';
		
			break;
		
		case 'mov':
		
			// swap in the tour to the viewport (uses INNERHTML method)
			document.getElementById('GalleryViewport').innerHTML =
				'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" '+
					'width="211" height="159" align="middle">'+
					'<param name="src" value="http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/tours/'+TourID+'.mov" />'+
					'<param name="autoplay" value="true" />'+
					'<embed src="http://'+MediaServerFQDN+'/DATA/'+SiteAlias+'/'+PropertyAlias+'/tours/'+TourID+'.mov" autoplay="true" width="211" height="159" align="middle" bgcolor="black" '+
					'pluginspage="http://www.apple.com/quicktime/download/">'+
				'</embed></object>';
	
			// swap in the contents of the "enlarge" container underneath the viewport
			document.getElementById('GalleryViewportEnlarge').innerHTML =
				'<a href="http://'+MediaServerFQDN+'/tours/'+SiteAlias+'/'+PropertyAlias+'/'+TourID+'/" onclick="GalleryEnlargePopUp(\'http://'+MediaServerFQDN+'/tours/'+SiteAlias+'/'+PropertyAlias+'/'+TourID+'/\', \'tour\');  return false;">Enlarge</a>';
		
			break;
	}

}




/* ***********************************************
   Google Maps Stuff
**************************************************** */

function createMarker(point) {
  var marker = new GMarker(point);

/* GEvent.addListener(marker, "mouseover", function() {

  });

  GEvent.addListener(marker, "click", function() {

  }); */

  return marker;
}

function loadmap(lat,lng) {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(lat, lng), 12);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			var point = new GLatLng (lat,lng);
			map.addOverlay(createMarker(point));
  }
}

function mapReload() {
	
	click_count++;
	
	if (click_count < 3) {

		GUnload();
		loadmap(CurrentLat, CurrentLong);

	}	
}

function StartMap() {
	try {
		mapReload();
		
		if (document.getElementById("detailstabnav3") != null) {
		
			var el = document.getElementById("detailstabnav3");
			
		} else {
			
			var el = document.getElementById("maintabnav2");
			
		}
		
		if (el.addEventListener){
			el.addEventListener('click', mapReload, false); 
		} else if (el.attachEvent){
			el.attachEvent('onclick', mapReload);
		}
	} catch(e) {}
	
}
