/*
	body.js gets included at the beginning (after the body) of all pages on the
	nyphil site.  
	
	-Allows administrators to choose pages for uniquely addressable links and scavenger
	hunts
	
	-calls scavenger hunt frame (if it exists) whenever body is loaded.
*/

/*define vars*/
ispopup 		= false;
admindoc 		= false;
frameorigin 		= false;
thispage    		= self.location.href;

if(top.opener) 
{
	//a popup
	ispopup = true;
	frameorigin = top;
	if(top.opener.top.adminframe)
		admindoc = top.opener.top.adminframe;
	
}
else 
{
	//is regular page or frameset
	if(top.adminframe)
	{
	 	admindoc 	= top.adminframe;
	 	frameorigin 	= top.website;
	}

}



//if there is an admin frame, tell them about ourselves
if(admindoc)
	admindoc.pageLoaded(thispage, window);
	
//set to empty get string...
this.appContentString = "";

function flashContentChoosen(contentString)
{
	
	//remember the contentstring in case someone wants it later
	
	if(admindoc)
		admindoc.chooseFlash(frameorigin,contentString);
	else
		alert("admin does not exist");
	
}

function chooseThisPage(){
	if(admindoc)
		admindoc.choosePage(frameorigin, thispage)
	else
		alert("admin does not exist");
	
	
	}

function flashContentShowing(contentString)
{
	this.appContentString =  contentString;
	if(admindoc)
		admindoc.flashLoaded(contentString, window);
	
}

function getContentArgs(){
//this will return a url formatted get string which 
//shockwave or flash might use to reconstruct app state..
	return this.appContentString;
	}

//called by an administrator.   a selector button for admin to choose page
//if this is a page in a popup. Otherwise the main choose page button should work.
function showSelector()
{
	
		document.write("<INPUT TYPE=\"button\" value=\"choose\" onclick=\"javascript:chooseThisPage();\"  >	");
}

function showPopPage(partURL, winName, width, height, scroll)
{
	//alert("called with args: " + partURL + " " + winName + " " + width + " " + height);
	if(!winName || winName == "content")
	{
		winName = "popup";
	}
			
	if(!width)
		width  = 640;
	if(!height)
		height = 480;	
	if(!scroll)
		scroll = "no";
		
	partURL = "http://" + document.domain + partURL;
	newwin = window.open(partURL,winName,'width='+ width + ',height=' + height + ',buttons=no,scrollbars=' + scroll + ',location=no,menubar=no,resizable=' + scroll + ',status=no,directories=no,toolbar=no');
	newwin.focus();
}

function openPopAndWin(partURL, winName, width, height, scroll,newWindowUrl)
{
	//alert(partURL + '\n' + winName  + '\n' + width   + '\n' + height   + '\n' + scroll  + '\n' + newWindowUrl);
	showPopPage(partURL, winName, width, height, scroll);	
	openTopPage(newWindowUrl);
}

//function that should be called if you want to open a page in the top frameset.  It will make sure the absolute path is correct...
function openTopPage(partURL)
{
	partURL = "http://" + document.domain + partURL;
	window.top.location.href = partURL;
}

function openParentPage(partURL)
{
	partURL = "http://" + document.domain + partURL;
	if(window.top.opener) 
	{
		
		window.top.opener.top.location.href = partURL;	
	} 
	
}


//replaces the current frame, in a non-host specific way
function openPage(partURL)
{
	
	partURL = "http://" + document.domain + partURL;
	window.location.href = partURL;
}

