function LoadTour()
{
	document.getElementById('TitleContent').innerHTML = Title;
	Navigation(NavigationStyle);
	DisplayScene(CurrentScene);
	
	if(!IDX)
	{
//	document.getElementById('AgentInfoContent').innerHTML = AgentPhoto.replace('BACKGROUNDCOLOR','%23'+aiBackgroundColor).replace('WIDTH',aiImageWidth).replace('HEIGHT',aiImageHeight);
//	document.getElementById('AgentInfoContent').innerHTML += AgentInfo;

document.getElementById('AgentInfoContent').innerHTML = GetContactInfo();
//	if(AgentMoreInfo != '')
//	 document.getElementById('AgentInfoContent').innerHTML += AgentMoreInfo;
	}//alert('here');
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Display Scene                                                                                                                //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function DisplayScene(SceneNumber)
{
  if(document.getElementById('Options') != null)
  {
  	document.getElementById('Options').style.visibility = "hidden";
  }

  	
	var ImgSrc = "";
	if (ImageList[SceneNumber][4] == "still")
	{	
		ImgSrc = "<img src=\"";
		ImgSrc += ImageList[SceneNumber][0]
		ImgSrc += "&w="+ViewWidth;
		ImgSrc += "&h="+ViewHeight;
		ImgSrc += "&bg=%23"+ViewBackgroundColor;
		ImgSrc += "\">";
		//alert(ImgSrc);
	}
	
	if (ImageList[SceneNumber][4] == "pano")
	{	
		var pViewWidth = Math.round(ViewWidth*1.25);
			fn = ImageList[SceneNumber][0];
		//fn = fn.replace(" ", "+").replace(" ", "+").replace(" ", "+").replace(" ", "+");
		fn = fn.replace(/ /g, "+");///.replace(" ", "+").replace(" ", "+").replace(" ", "+");
		//var pViewHeight = Math.round(ViewHeight*1.25);
		ImgSrc = '<applet codebase="http://tours.ilookabout.com/toursv3/" code="Viewer.class" width='+ViewWidth+' height='+ViewHeight+' archive="ilaviewer3.zip" mayscript=true>';
		ImgSrc += '<PARAM NAME=usecaches VALUE="yes">';
		ImgSrc += '<PARAM NAME=splash VALUE="Profiles/' + ProfileGUID + '/Splash.gif">';
		ImgSrc += '<PARAM NAME=panotype VALUE="sphere">';
		ImgSrc += '<PARAM NAME=boundsrect VALUE="' + ImageList[SceneNumber][5] + '">';
		ImgSrc += '<PARAM NAME=orientation VALUE="3">';
		ImgSrc += '<PARAM NAME=filename VALUE="' + fn + '&w='+ pViewWidth +'">';
		ImgSrc += '<PARAM NAME=helpurl VALUE="help.htm">';

		ImgSrc += '<font color="White"><br>You currently do not have Java runtime installed on your computer.';
		ImgSrc += '<br>To install Java click on the following link to download the software from the';
		ImgSrc += ' Sun Microsystems website.<br><br><P align="center"><A href="http://www.java.com" title="Click to download Java"><img src="../images/getjava.gif" border=0></A></P></font>';
		ImgSrc += '</applet>'
		
		//alert(ImgSrc);
	}
	
				if (ImageList[SceneNumber][4] == "windowsmedia")
	{	
		//var pViewWidth = Math.round(ViewWidth*1.25);
		//var pViewHeight = Math.round(ViewHeight*1.25);
		ImgSrc = "<OBJECT id='VIDEO' width='"+ViewWidth+"' height='"+ViewHeight+"' CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'>";
        ImgSrc += "<PARAM NAME='URL' VALUE='" + ImageList[SceneNumber][0] + "'>";
        //    showcontrols="True" showstatusbar="False" 
        ImgSrc += "<PARAM NAME='uiMode' VALUE='full'>";
        ImgSrc += "<PARAM NAME='showcontrols' VALUE='True'>";
        ImgSrc += "<PARAM NAME='SendPlayStateChangeEvents' VALUE='True'>";
        ImgSrc += "<PARAM NAME='AutoStart' VALUE='True'>";
        ImgSrc += "<PARAM name='uiMode' value='none'>";
        ImgSrc += "<PARAM name='PlayCount' value='1'>";
        ImgSrc += "</OBJECT>";
		
		//alert(ImgSrc);
	}
	
	
	
	if (ImageList[SceneNumber][4] == "quicktime")//'still')//
	{	
		//var pViewWidth = Math.round(ViewWidth*1.25);
		//var pViewHeight = Math.round(ViewHeight*1.25);
		ImgSrc = "<div style='height:"+(ViewHeight)+"; widthpx:"+ViewWidth+"px;margin:0; padding:0;' >";
		ImgSrc += "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' height='"+ViewHeight+"' width='"+ViewWidth+"' id='qt'>";
ImgSrc += "<param name='src' value='"+ImageList[SceneNumber][0]+"'>";
ImgSrc += "<param name='scale' value='tofit'>";
ImgSrc += "<param name='autoplay' value='true'>";
ImgSrc += "<param name='controller' value='true'>";
ImgSrc += "<embed height='"+ViewHeight+"' width='"+ViewWidth+"' src='"+ImageList[SceneNumber][0]+"' pluginspage='http://www.apple.com/quicktime/download/' type='video/quicktime' controller='true' autoplay='true'>";
ImgSrc += "</object></div>";
		
		//alert(ImgSrc);
		//document.qt.autopan = window.setInterval('{var d = new Date();if (document.qt.GetPluginStatus()=="Complete"){document.qt.SetPanAngle(document.qt.GetPanAngle()+(d.getTime()-document.qt.autotime)/-41.67);document.qt.autotime=d.getTime()}}',25);
	}



	if (ImageList[SceneNumber][4] == "cube")//ilaviewer3
	{	
		ImgSrc = '<applet codebase="http://tours.ilookabout.com/toursv3/" code="Viewer.class" width='+ViewWidth+' height='+ViewHeight+' archive="ilaviewer3.zip" mayscript=true>';
		ImgSrc += '<PARAM NAME=splash VALUE="Profiles/' + ProfileGUID + '/Splash.gif">';
		
		//&Size=LARGE&Quality=HIGH
		
		ImgSrc += '<PARAM NAME=yawStart VALUE="'+ImageList[SceneNumber][5] +'">';
		var timg = ImageList[SceneNumber][0];
		timg = timg.replace("#PROFILEGUID#",ProfileGUID);
		
		//Change to High Quality if requested
		//if((Mode.indexOf('H') == -1) && (Mode.indexOf('W') == -1))
		//	timg = timg.replace("&Size=LARGE&Quality=HIGH","&Size=MED&Quality=MED");
		
		ImgSrc += '<PARAM NAME=filename VALUE="http://tours.ilookabout.com' + timg + '">';
		ImgSrc += '<PARAM NAME=panotype VALUE="cube">';
		ImgSrc += '<PARAM NAME=helpurl VALUE="help.aspx">';
		ImgSrc += '</applet>'
	}
	
		if (ImageList[SceneNumber][4] == "cubex")//ilaviewer2
	{	
		ImgSrc = '<applet codebase="http://tours.ilookabout.com/toursv3/" name=ilaviewer2 code="ilaviewer2.class" width='+ViewWidth+' height='+ViewHeight+' archive="ilaviewer2.zip" mayscript=true>';
		//ImgSrc += '<PARAM NAME=usecaches VALUE="yes">';
		ImgSrc += '<PARAM NAME=splash VALUE="Profiles/' + ProfileGUID + '/Splash.gif">';
		//ImgSrc += '<PARAM NAME=panotype VALUE="cube">';
		ImgSrc += '<PARAM NAME=yawStart VALUE="'+ImageList[SceneNumber][5] +'">';
		//ImgSrc += '<PARAM NAME=orientation VALUE="2">';
		var timg = ImageList[SceneNumber][0];
		timg = timg.replace("#PROFILEGUID#",ProfileGUID);
		ImgSrc += '<PARAM NAME=filename VALUE="' + timg + '">';
		ImgSrc += '<PARAM NAME=helpurl VALUE="help.aspx">';
		
		ImgSrc += '<PARAM NAME="toolbar" VALUE="ilatoolbar.gif">';
		ViewBackgroundColor = ViewBackgroundColor.replace('%23','');
		ImgSrc += '<PARAM NAME="backgroundcolor" VALUE="'+ViewBackgroundColor+'">';
		ImgSrc += '<font color="White"><br>You currently do not have Java runtime installed on your computer.';
		ImgSrc += '<br>To install Java click on the following link to download the software from the';
		ImgSrc += ' Sun Microsystems website.<br><br><P align="center"><A href="http://www.java.com" title="Click to download Java"><img src="../images/getjava.gif" border=0></A></P></font>';
		ImgSrc += '</applet>'

	}
	
	document.getElementById('ViewBody').innerHTML = ImgSrc;
	
	if (ImageList[SceneNumber][4] == "quicktime")
	{	
		var qt = document.getElementById('qt')
		qt.autopan = window.setInterval('CheckPan()',25);
	}
	
	//Change Control Text
	var ThisControlHTML = GetControlHTML();//ControlHTML; //CurrentScene
	document.getElementById('ControlBody').innerHTML = ThisControlHTML;

	var ImgDes = "";
	
	if (ImageList[SceneNumber][3] != '')
	{
		ImgDes = '<b>'+ImageList[SceneNumber][2]+'</b> - ' 
		ImgDes += ImageList[SceneNumber][3];
	}
	else
	{
		ImgDes = '<b>'+ImageList[SceneNumber][2]+'</b>' 
	}
	//alert(ImgDes);
	document.getElementById('DescriptionContent').innerHTML = ImgDes;
	
	
	if((NavigationStyle == "thumbnail") || (NavigationStyle == "thumbnailcaption"))
	{
	//Change Current Thumb
	var tNav = "";
	tNav += "<img alt=\""+ImageList[SceneNumber][2];
	if (ImageList[SceneNumber][3] != "")
	{
	tNav += " - "+ImageList[SceneNumber][2];
	}
	tNav += "\" src=\"" + ImageList[SceneNumber][1] + "&w="+ThumbWidth+"&h="+ThumbHeight+"&bg=%23"+NavBackgroundColor +"\" border=0 width="+ThumbWidth+" height="+ThumbHeight+"><br>";
	tNav += ImageList[SceneNumber][2];
	document.getElementById('thumb'+SceneNumber).innerHTML = tNav;

//alert(LastScene);
	if ((LastScene > -1) && (LastScene != SceneNumber))
	{
		tNav = "<a href=\"javascript:;\" class=thumb onclick=\"DisplayScene("+LastScene+");\">";
		tNav += "<img alt=\""+ImageList[LastScene][2];
		if (ImageList[LastScene][3] != "")
		{
		tNav += " - "+ImageList[LastScene][2];
		}
		tNav += "\" src=\"" + ImageList[LastScene][1] + "&w="+ThumbWidth+"&h="+ThumbHeight+"&bg=%23"+NavBackgroundColor +"\" border=0 width="+ThumbWidth+" height="+ThumbHeight+"><br>";
		tNav += ImageList[LastScene][2];
		tNav += '</a>';
			
		document.getElementById('thumb'+LastScene).innerHTML = tNav;
	}
	}
	LastScene = SceneNumber;
	//alert(SceneNumber);
	Navigation(NavigationStyle);
	//class=SelectedThumb
	
}

var st = true;
function CheckPan()
{
 var qt = document.getElementById('qt')
// var d = new Date(); 
// if (qt.GetPluginStatus()=="Complete") 
// {
// if(st)
// {
// st = false;
//	var a = qt.GetPanAngle();
	//alert(qt.autotime);
//	if((qt.autotime > 0))
//	{
//	 a = a + (d.getTime() - (qt.autotime));
//	 a = a / -41.67;
//	}
//	else
//	{
//		a = (-0.2)
//	}
	//alert(a);
	//qt.SetPanAngle(a);
	qt.SetPanAngle(qt.GetPanAngle()-0.05 );
//   qt.autotime = d.getTime();
// }
// }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
// Build Navigation                                                                                //
/////////////////////////////////////////////////////////////////////////////////////////////////////

function Navigation(NavStyle)
{	
NavigationStyle = NavStyle;
//alert(NavStyle);
	var Nav = '';
	if ((NavStyle == "text") || (NavStyle == "button"))
	{
		if (NavStyle == "text")
		{	
			var t = "";
			Nav += "<table width=\""+(NavWidth-20)+"\" cellpadding=\"0\" cellspacing=\"4\" id=textitem>";// style=\"overflow: scroll;\"><div><ul  style=\" \">"; //
			for ( var i = 0; i < ImageList.length; i++ )
			{
				if(ImageList[i][7] != t)
				{
					t = ImageList[i][7];
					Nav += "<tr><td colspan=\"2\"><div class=\"NavCategory\">"+t+"</div></td></tr>";
					
				}
				
				cap = ImageList[i][2];
				if(cap.length > 17)
				{
					if(cap.substring(0,18).indexOf(" ") == -1)
					{
						cap = cap.substring(0,17)+"&#8230;";
					}
				}
				
				if(i == LastScene)
				{
				Nav += "<tr><td valign=\"top\">-</td><td valign=\"top\" class=\"textitemOn\">";
				Nav += cap;// + '<br>'
				Nav += '</td></tr>';
				}
				else
				{
				Nav += "<tr><td valign=\"top\">-</td><td valign=\"top\"><a class=\"textitem\" href=\"#\" onclick=\"DisplayScene("+i+");\">";
				Nav += cap;// + '<br>'
				Nav += '</a></td></tr>';
				
				
				}
			}
			Nav += "</table>";
		}
		else
		{	
			var t = "";
		//	Nav += "<div id=\"list-menu\"><ul style=\"margin-left:0;\">"; 
			Nav += "<div id=\"textcontainer\"><ul id=\"textlist\">"; //
			for ( var i = 0; i < ImageList.length; i++ )
			{
				if(ImageList[i][7] != t)
				{
					t = ImageList[i][7];
					Nav += "<li><div class=\"NavCategory\">"+t+"</div></li>";
					
				}
				
				cap = ImageList[i][2];
				//if(cap.length > 18)
				//	{cap = cap.substring(0,18)+"&#8230;";}
				if(i == LastScene)
				{
				Nav += "<li id=\"textactive\"><a href=\"#\" style=\"text-decoration:none;\" id=\"textcurrent\">";
				Nav += cap;// + '<br>'
				Nav += '</a></li>';
				}
				else
				{
				Nav += "<li><a href=\"#\" style=\"text-decoration:none;\" onclick=\"DisplayScene("+i+");\">";
				Nav += cap;// + '<br>'
				Nav += '</a></li>';
				
				
				}
			}
			Nav += "</ul></div>";

		}
		
		
		
	}
	
	//Do thumb
	if ((NavStyle == "thumbnail") || (NavStyle == "thumbnailcaption"))
	{
		if (NavStyle == "thumbnail")
		{
			var t = "";
			//Nav += "<div id=\"list-menu\">";//style=\"margin-left: 0px;\"
			for ( var i = 0; i < ImageList.length; i++ )
			{
				if(ImageList[i][7] != t)
				{
					t = ImageList[i][7];
					Nav += "<div class=\"NavCategory\">"+t+"</div>";
					
				}
				
				var f = " style=\"Filter: Gray;\"";
				if(i == LastScene) {f = "";}
				
				Nav += "<div class=thumb id=thumb style=\"display: inline; margin:2px;\"><span id=thumb"+i+"><a href=\"javascript:;\" class=thumb onclick=\"DisplayScene("+i+");\">";
				Nav += "<img"+f+" alt=\""+ImageList[i][2];
				if (ImageList[i][3] != "")
				{
				Nav += " - "+ImageList[i][2];
				}
				//NavBackgroundColor = "red";
				//NavBackgroundColor = NavBackgroundColor.replace("#","%23");
				Nav += "\" src=\"" + ImageList[i][1] + "&w="+ThumbWidth+"&h="+ThumbHeight+"&bg=%23"+NavBackgroundColor +"\" border=0 width="+ThumbWidth+" height="+ThumbHeight+">";
				
				Nav += '</a></span></div>';
			}
			//Nav += "</div>";
		}
		else
		{
			
			var t = "";
			//Nav += "<div id=\"list-menu\">";//style=\"margin-left: 0px;\"
			for ( var i = 0; i < ImageList.length; i++ )
			{
				//Group Titles
				if(ImageList[i][7] != t)
				{
					t = ImageList[i][7];
					Nav += "<div class=\"NavCategory\">"+t+"</div> ";
					
				}
			
				var f = " style=\"Filter: Gray;\"";
				if(i == LastScene) {f = "";}
				Nav += "<table cellspacing=0 cellpadding=2><tr><td align=center valign=middle class=thumb id=thumb style=\"text-decoration:none; width:"+ThumbWidth+"; height:"+ThumbHeight+";\"><span id=thumb"+i+"><a href=\"javascript:;\" class=thumb onclick=\"DisplayScene("+i+");\">";
				Nav += "<img"+f+" alt=\""+ImageList[i][2];
				if (ImageList[i][3] != "")
				{
				Nav += " - "+ImageList[i][2];
				}
				NavBackgroundColor = NavBackgroundColor.replace("#","%23");
				
				//Create thumb with no padding
				ratio = ImageList[i][8];
				
				tw = ThumbWidth;
				th = ThumbHeight;
				
				//alert(ratio+" -  "+ tw +" "+th);
					
				//if(tw > th)
				if(ratio >= 1)
				{
					if((tw/th) < 1)
					{
					//	alert(1);
						tw = Math.round((ThumbWidth/ratio)+0.5);
					}
					else
					{
					//alert(2);
						th = Math.round((ThumbHeight/ratio)+0.5);
					}
				}
				else
				{
					if((tw/th) >= 1)
					{
					//alert(3);
						tw = Math.round((ThumbWidth*ratio)+0.5);
					}
					else
					{
					//alert(4);
						th = Math.round((ThumbHeight*ratio)+0.5);
					}
				}
				
				
				Nav += "\" src=\"" + ImageList[i][1] + "&w="+tw+"&h="+th+"&bg=%23"+NavBackgroundColor +"\" border=0 width="+tw+" height="+th+" align=\"absmiddle\">";
				
				cap = ImageList[i][2];
				//if(cap.length > 7)
				//{cap = cap.substring(0,7)+"&#8230;";}
				//if(cap.length > 7)
				{
				//	if(cap.substring(0,8).indexOf(" ") == -1)
					{
						//cap = cap.substring(0,7)+"&#8230;";
					}
				}
				//Nav += "<br>"+cap;
				Nav += "</a></td><td onclick=\"DisplayScene("+i+");\" align=left valign=middle ";
				Nav += "style=\"display: inline; cursor: hand; width: "+(NavWidth-ThumbWidth-22)+"px; height: "+ThumbHeight+"; overflow: hidden; text-overflow: ellipse; text-decoration:none;\">" + cap + "";
				Nav += '</a></td></tr></table>';
			}
			//Nav += "</div>";
		}
	}
//	alert(Nav);
	if(IDX)
		document.getElementById('NavigationIDXContent').innerHTML = Nav;
	else
		document.getElementById('NavigationContent').innerHTML = Nav;

}

function cBut(ID, Name){
   if (ID != CurrentID){
      ImageID = "b" + ID + "_" + Name;
      if (document.images) {document.images[ImageID].src=eval(Name+".src"); }
   }
   else
   {
     ImageID = "b" + ID + "_on";
		 if (document.images) {document.images[ImageID].src=eval(Name+".src"); }s
   }
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Resize Agent                                                                                                                 //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ResizeAgent(tSize)
{
		var offset = AgentMaximizedHeight-AgentMinimizedHeight;
		//alert(offset);
		
		var AgentInfoTop = document.getElementById('AgentInfo').offsetTop;
		tempEl = document.getElementById('AgentInfo').offsetParent;
		while (tempEl != null) 
		{
  		AgentInfoTop += tempEl.offsetTop;
	  	tempEl = tempEl.offsetParent;
  	}
  	
	 	AgentInfoHeight = document.getElementById('AgentInfo').offsetHeight;
		AgentInfoBodyHeight = document.getElementById('AgentInfoBody').offsetHeight;
		NavigationHeight = document.getElementById('Navigation').offsetHeight;
		NavigationBodyHeight = document.getElementById('NavigationBody').offsetHeight;
		NavigationBodyContentHeight = document.getElementById('NavigationContent').offsetHeight;
		//alert(AgentInfoBodyHeight);


	if (tSize)
	{
		//Maximize
		document.getElementById('AgentInfoHeader').innerHTML = AgentMaximizedImage;
		document.getElementById('AgentInfo').style.height = (AgentInfoHeight - offset);
		document.getElementById('AgentInfo').style.top = (AgentInfoTop - offset);
		document.getElementById('AgentInfoBody').style.height = (AgentInfoBodyHeight + offset);
		document.getElementById('Navigation').style.height = (NavigationHeight - offset);
		document.getElementById('NavigationBody').style.height = (NavigationBodyHeight - offset);
		document.getElementById('NavigationContent').style.height = (NavigationBodyContentHeight - offset);
	}
	else
	{
		//Minimize
		document.getElementById('AgentInfoHeader').innerHTML = AgentMinimizedImage;
		document.getElementById('AgentInfo').style.height = (AgentInfoHeight + offset);
		document.getElementById('AgentInfo').style.top = (AgentInfoTop + offset);
		document.getElementById('AgentInfoBody').style.height = (AgentInfoBodyHeight - offset);
		document.getElementById('Navigation').style.height = (NavigationHeight + offset);
		document.getElementById('NavigationBody').style.height = (NavigationBodyHeight + offset);
		document.getElementById('NavigationContent').style.height = (NavigationBodyContentHeight + offset);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Popup Window                                                                                                                 //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var newViewer = null

function openwin(page,w,h)
{ 
	if(newViewer && !newViewer.closed)
           newViewer.close();
  
  page = page.replace("#","%23");
  if (page.indexOf("#") > -1)
  {
  page = page.replace("#","%23");
  }
  //alert(page);
	newViewer=window.open(page,'EmailMe','width='+w+',height='+h+',toolbar=no,scrollbars=yes,resizable=yes,status=no,copyhistory=0');
}
function closeViewer() 
{
	if(newViewer && !newViewer.closed)
		newViewer.close(); 
}
