//popWin = null;
mapWin = null;
pdfWin = null;
photoWin = null;
pathToRoot = "/";
// On page load, initializes window reference variable

var resizable, scrollbars, menubar, statusbar, locationbar, toolbar;

constants:{
  resizable = 1;
  scrollbars = 2;
  menubar = 4;
  statusbar = 8;
  locationbar = 16;
  toolbar = 32;
}
function winPop(windowname,imgURL,width,height,options) {
    // Check for window state
	//alert(this[windowname]);
	//if(popWin!=null) alert(popWin.closed);
  if(window[windowname] != null){
	window[windowname].close();
  }
 // var windowname = "popWin";
  var attr  = "width="+width+",";
      attr += "height="+height;
  if(options>=32){
      attr += ",toolbar=yes";
      options -= 32;
  }
  if(options>=16){
      attr += ",locationbar=yes";
      options -= 16;
  }
  if(options>=8){
      attr += ",statusbar=yes";
      options -= 8;
  }
  if(options>=4){
      attr += ",menubar=yes";
      options -= 4;
  }
  if(options>=2){
      attr += ",scrollbars=yes";
      options -= 2;
  }
  if(options>=1){
      attr += ",resizable=yes";
      options -= 1;
  }
  window[windowname] = open(imgURL,windowname,attr);
}

function closePopWin(){
  //  if (!(mapWin==null || mapWin.closed )) { mapWin.close(); }
	if (!(pdfWin==null || pdfWin.closed)) { pdfWin.close(); }
	if (!(photoWin==null || photoWin.closed)) { photoWin.close(); }
}
window.onunload = closePopWin;

function popPhoto( photoName, intWidth, intHeight ) {
	if(!intWidth) {intWidth=0;}
	if(!intHeight) {intHeight=0;}
	
	winPop
	(
	 	"photoWin",
		pathToRoot+"photoDetail.cfm?photo="+photoName,
		(intWidth>0)?intWidth:550,
		(intHeight>0)?intHeight:550,
		//parseInt(intWidth)+30,
		//(boolCaption)?parseInt(intHeight)+37:parseInt(intHeight)+17,
		//statusbar+menubar+resizable
		menubar+resizable
	);
}

function popPDF(strFileName, intWidth, intHeight) {
	if(!intWidth) {intWidth=0;}
	if(!intHeight) {intHeight=0;}

	winPop
	(
	 	"pdfWin",
		strFileName,
		(intWidth>0)?intWidth:650,
		(intHeight>0)?intHeight:500,
		statusbar+menubar+resizable
	);
}

/*function popImage(strFileName,width,height)
{
	winPop
	(
	 	"imageWin",
		strFileName,
		width,
		height,
		statusbar+menubar+resizable+scrollbars
	);
}*/

function popMap(strFileName) {
	
	tempPath = strFileName;
	qmark = tempPath.indexOf('?');
	
	if (qmark > 0) {
		tempPath = tempPath.substr(0, qmark);
	}

	if (tempPath.charAt(tempPath.length-1) == "/") {
		tempPath = tempPath.substr(0, tempPath.length-1);	
	}
								 
	last = tempPath.lastIndexOf('/');
	lastdir = tempPath.substr(last+1, tempPath.length);
	
	switch(lastdir) {
		case "construction":
			width = 640;
			height = 490;
		break;	
		case "parkandride":
			width = 640;
			height = 490;
		break;	
		case "detail":
			width = 510;
			height = 490;
		break;	
		case "breakout":
			width = 680;
			height = 590;
		break;
		default:
		// schedule
			width = 640;
			height = 540;
		break;		
	}
	
	winPop
	(
	 	"mapWin",
		strFileName,
		width,
		height,
		statusbar+menubar+resizable+scrollbars
	);
}
