﻿var resizephotopanels = false;
var ie56 = false;
var ie567 = false;
var popup = null;
var nokill = false;

function openPopUp(fileUrl, width, height, normal) {
	// close any other popups, thanks
	// no need for the following; use window name instead to prevent recycling. By the way, auto-closing onunload or onfocus is NOT desired for the player either!
	if (popup != null) { // || (popup.closed)) {
		closePopUp();
	}


	var attribs = '';
	var size = "no";

	// if no dimensions provided, apply default/percentage dimensions [and set the window to be resizable]
	if (height == null) {height = 0.6; size="yes";}
	if (width == null) {width = 0.6; size="yes";}

	// do percentage values
	if (height <= 1) height = (screen.height * height);
	if (width <= 1) width = (screen.width * width);

	// force minimum dimensions if desired
	// if (height < 375) height = 375;
	// if (width < 600) width = 600;

	// if the screen is smaller than the proposed window, make the window resizable and adjust the proposed window's dimensions accordingly...
	if(screen.width < width) {width = (screen.width * 0.9); size = "yes";}
	if(screen.height < height) {height = (screen.height * 0.75); size = "yes";}

	// if the screen is very small, ensure that the window resizable
	// if(screen.width <= 800 || screen.height <= 600) size = "yes";

	// center the window // THIS DOESN'T WORK RIGHT YET
	// find position
	WndTop  = Math.max(Math.round((screen.height - height) / 2),0);
	WndLeft = Math.max(Math.round((screen.width  - width)  / 2),0);

	// if normal variable is set, enable sizing override. STRONGLY RECOMMENDED - imagine if size was off on a normal window! Dumb.
	if (normal) {size = "yes";}
	// alert("size is " + size);

	// collect the attributes
	attribs = "width=" + width + ",height=" + height + ",top=" + WndTop + ",left=" + WndLeft;

	if (normal) {attribs += ",resizable=" + size + ",scrollbars=" + size + ",status=yes,toolbar=yes,directories=yes,menubar=yes,location=yes";} else {attribs += ",resizable=" + size + ",scrollbars=" + size + ",status=no,toolbar=no,directories=no,menubar=no,location=no";}

	// UNUSED ATTRIBS: dependant,

	popup = window.open(fileUrl,'seanine',attribs); // optional window name in this case prevents multiple windows and causes auto-recycles even when original window is browsed. Nice.
	// window.open(fileUrl,'seanine',attribs); // window name prevents multiple windows and causes auto-recycles! Nice.
	popup.focus(); // brings popup to front whenever a new one is loaded.
}
function closePopUp() { // virtually unusable/redundant in current context since you are naming your popup window 
	// close the current window
	if(popup != null)
	{
		popup.close();
		popup = null;
	}
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function setmessage(boxname,newtext) {
	var mesgtext = new getObj(boxname);
	if (mesgtext.obj.value == '' || mesgtext.obj.value == 'enter search terms')  mesgtext.obj.value = newtext;
}
function changecolor() {
	var box = new getObj('q');
	box.obj.style.color = "#e5e5e5";
}

window.onload = function() {
	
	if (resizephotopanels) {
		if (ie567) document.getElementById('gallery1').style.height = (document.getElementById('gallery1').offsetHeight);
		if (ie567) document.getElementById('gallery2').style.height = (document.getElementById('gallery2').offsetHeight);
		if (ie567) document.getElementById('gallery3').style.height = (document.getElementById('gallery3').offsetHeight);		
		//if (ie56) document.getElementById('main').style.height = (document.getElementById('main').offsetHeight);		
		if (ie56) document.getElementById('mainbottom').style.bottom = "0px";		
	}
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop
	if (!document.getElementsByTagName) {
		return false;
	}
	// create an array of objects of each link in the document
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags)
	for (var i=0; i < popuplinks.length; i++) {
		// if the link has a class of "popup"...
		if (popuplinks[i].className.indexOf("popupaudioplayer") != -1) {
			// add an onclick event on the fly to pass the href attribute
			// of the link to our second function, openPopUp
			popuplinks[i].onclick = function() {
				openPopUp(this.getAttribute("href"),430,109);
				return false;
			}
		}
		if (popuplinks[i].className.indexOf("popupvideoplayer") != -1) {
			// add an onclick event on the fly to pass the href attribute
			// of the link to our second function, openPopUp
			popuplinks[i].onclick = function() {
				openPopUp(this.getAttribute("href"),428,397);
				return false;
			}
		}
		if (popuplinks[i].className.indexOf("popupnormal") != -1) {
			// add an onclick event on the fly to pass the href attribute
			// of the link to our second function, openPopUp
			popuplinks[i].onclick = function() {
				openPopUp(this.getAttribute("href"),0.6,0.6,1);
				return false;
			}
		}
	}
}

window.onunload = function () {
	// closePopUp();
}
