window.focus();
var reload=1;
var curFirstTour=4;
var PTZVal = new Array(3); //holds pan,tilt,zoom vals
var MovieFormat;
var QTParam=new Array(6);
QTParam[1]="273;0;66";
QTParam[2]="220;0;67";
QTParam[3]="271;0;73";
QTParam[4]="302;0;70";
QTParam[5]="112;0;61";

function GetCurDir()
{
	var currentdir;
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	currentdir=locarray[(locarray.length-2)];
	return(currentdir);
}

function launchQTSlideshow()
{
	var curdir,slidespath;
	curdir=GetCurDir();
	slidespath="../"+curdir+"/slides.mov";	
	//slidespath="slides.mov";
	top.frames["qtmovie"].launchQTSlides(slidespath);	
}

function launchQTTour(tournum)
{
	//alert("Gary in launchQTTour");
	PTZVal = new Array(3); //holds pan,tilt,zoom vals
	var curdir,moviepath;
	curdir=GetCurDir();
	moviepath="../"+curdir+"/vt"+tournum+".mov";
	PTZVal=QTParam[tournum].split(";");
	top.frames["qtmovie"].launchQT(moviepath,PTZVal[0],PTZVal[1],PTZVal[2]);

}


function launchTour()
{
	top.frames["qtmovie"].ReloadTourSWF(curFirstTour);
	reload=0;
}

function changeFormat()
{
	var curselection,tempstring;
	var destination=window.qtmovie;
	var thebox=document.d352;
	
	curselection=thebox.d343.options[thebox.d343.selectedIndex].value;
	if(document.FlashQuickTime.myradio[0].checked)
	{
		reload=1;		
		MovieFormat="Flash";
		jumpbox(curselection);
		
	}
	else
	{
		MovieFormat="QuickTime";
		jumpbox(curselection);
	}
	Set_Cookie("movieformat",MovieFormat,360,'/'); // set default cookie to Flash
	writeHelpLink();
}

function jumpboxQT(tourname)
{
	var tourpath = "../qtfull/vt"+tourname+".htm";
	reload=1;
	if(tourname == "flyer.fdf")
	{
	    window.open(tourname);
	    return;
	}
	
	var destination=window.qtmovie;
	var thebox=document.d352;
	if(tourname>0)
	{
		destination.location.href=tourpath;	
		return;
	}
	else
	{
		//alert(tourname);
		if(tourname == "slides.htm")
		{
			tourname = "../qtfull/qtslides.htm";
			//tourname="qtslides.htm";
			//destination.location.href="qtslides.htm";
			destination.location.href=tourname;
		
		}
		else if(tourname == "../flashhelp.htm")
		{
			tourname = "../qthelp.htm";
			//destination.location.href="qtslides.htm";
			destination.location.href=tourname;
		
		}
		else
		{
			destination.location.href=thebox.d343.options[thebox.d343.selectedIndex].value;
		}
	}	
}

function jumpbox(tourname)
{
	if(MovieFormat == "QuickTime") // show content in quicktime instead of flash;
	{
		jumpboxQT(tourname)
		return;
	}
	if(tourname == "flyer.fdf")
	{
	    window.open(tourname);
	    return;
	}
	var destination=window.qtmovie;
	var thebox=document.d352;
	if(tourname>0 && reload ==0)
	{
		top.frames["qtmovie"].ChangePano(tourname);
	}
	else if(tourname>0 && reload ==1)
	{
		curFirstTour=tourname;
		reload=1;
		destination.location.href="vt.htm";
		
		return;
	}
	else
	{
		destination.location.href=thebox.d343.options[thebox.d343.selectedIndex].value;
		reload=1;
	}
}

function writeHelpLink() // write the name of the link for help based on the mode... Uses global, MovieFormat
{
	var linkname,x,tempstring;
	linkname=MovieFormat+" Help";
	x=document.getElementById("helplink");
	tempstring="<p align='left'><font size='2'>&nbsp;&nbsp;&nbsp;<a href='#' STYLE='text-decoration:none' onClick='javascript:updateHelp()'><b>"+linkname+"</b></a></p></font>";
	x.innerHTML=tempstring;
	
}

function updateHelp()
{
	var indexnum=document.d352.d343.options.length;
	indexnum--; //help is always last index
	var destination=window.qtmovie;

	document.d352.d343.options.selectedIndex=indexnum;
	if(MovieFormat == "Flash")
	{
		destination.location.href="../flashhelp.htm";
	}
	else
	{
		destination.location.href="../qthelp.htm";
	}
	reload=1;
}

function isNav() {
	return (navigator.appName == "Netscape")
}

function isIE() {
	return (navigator.appName == "Microsoft Internet Explorer")
}

function correctsize()
{
	window.moveTo(0,0);
	window.resizeTo(window.screen.availWidth,window.screen.availHeight);	MovieFormat=Get_Cookie('movieformat');
	//alert("MovieFormat =="+MovieFormat);
	if(MovieFormat==null)
	{
		//alert("gary no cookie present");
		//alert("This message will only be shown once...\nWelcome to the new pdxvtours Flash/QuickTime viewer! \nFor assistance with setup or operation, click Help on left below."); 

		Set_Cookie("movieformat","Flash",360,'/'); // set default cookie to Flash
		MovieFormat="Flash";
		document.FlashQuickTime.myradio[0].checked=true;
		window.qtmovie.location.href="vt.htm";
		//alert("gary no cookie present");
	}
	else
	{
		
		if(MovieFormat=="Flash")
		{
			document.FlashQuickTime.myradio[0].checked=true;
			window.qtmovie.location.href="vt.htm";
			//alert("gary in flash");
		}
		else // MovieFormat set to QuickTime
		{
			//alert("gary in quicktime");
			document.FlashQuickTime.myradio[1].checked=true;
			jumpbox(curFirstTour);
		}
	}
	writeHelpLink();
}


function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
