//<![CDATA[

function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}


function addCloseButton() {
	
	x = document.getElementById('description') ;
	if ( x && window.close ) {
		//get desc's sibling
		y = document.getElementById('content') ;
		nextSib = y.firstChild ;
		nextSib = nextSib.nextSibling ;
		
		
		afterDesc = x.nextSibling ;
				
		newDiv = document.createElement('div');
		newDiv.id = 'closebutton' ;
		
		newAnchor = document.createElement('a') ;
		newAnchor.href= 'javascript:window.close();' ;
		
		newImg = document.createElement('img') ;
		newImg.src = '/images/closebutton.gif' ;
		newImg.alt = 'close window' ;
		
		
		newBr = document.createElement('br') ;
		
		//add to the anchor
		newAnchor.appendChild(newImg) ;
		
		//add to the div
		newDiv.appendChild(newAnchor) ;
		
		newDiv.appendChild(newBr);
		
		newText = document.createTextNode('close') ;
		
		newDiv.appendChild(newText);
		
		
		
		//stick div after the desc div
		y.insertBefore(newDiv,nextSib) ;
	}

}


function setTextBoxes(xpos,ypos) {
		document.forms[0].xpos.value = xpos
		document.forms[0].ypos.value = ypos
}


function changeZoneMap(value) {
	showDiv = document.getElementById('map-'+value);
	showHolder = document.getElementById('allmaps') ;
	
	allMapDivs = showHolder.getElementsByTagName('div') ;
	
	for ( i=0; i < allMapDivs.length; i++ ) {
		allMapDivs.item(i).style.display = 'none' ;
	}
	
	showDiv.style.display = 'block' ;
	showHolder.style.display = 'block' ;
}



if ( window.attachEvent ) {
	//window.close only works on ie nowadays anyway
	window.attachEvent('onload',addCloseButton);
}
			
			

function addZoneNavEvents() {
	
	x = document.getElementById('zonenav') ;
	if ( x ) {
		urbLink = x.getElementsByTagName('li') ;
		for ( i = 0; i < urbLink.length; i++ ) {
			thisItem = urbLink.item(i);
			if ( thisItem.className == 'urban' ) {
				//get the A within it
				linksIn = thisItem.getElementsByTagName('a') ;
				if ( linksIn.length > 0 ) {
					linksIn.item(0).onclick= function(){ return doUrban(); };
				}
			}
			else if ( thisItem.className == 'tranquil' ) {
				//get the A within it
				linksIn = thisItem.getElementsByTagName('a') ;
				if ( linksIn.length > 0 ) {
					linksIn.item(0).onclick= function(){ return doTranquil(); };	
				}
			}
			else if ( thisItem.className == 'campus' ) {
				//get the A within it
				linksIn = thisItem.getElementsByTagName('a') ;
				if ( linksIn.length > 0 ) {
					linksIn.item(0).onclick= function(){ return doCampus(); };	
				}
			}
			else if ( thisItem.className == 'commercial' ) {
				//get the A within it
				linksIn = thisItem.getElementsByTagName('a') ;
				if ( linksIn.length > 0 ) {
					linksIn.item(0).onclick= function(){ return doCommercial(); };	
				}
			}
			else if ( thisItem.className == 'roots' ) {
				//get the A within it
				linksIn = thisItem.getElementsByTagName('a') ;
				if ( linksIn.length > 0 ) {
					linksIn.item(0).onclick= function(){ return doRoots(); };	
				}
			}			
		
		}
	}
}

function doUrban() {
	doIt('urban');
	//setFlashVariables('sendmovie','command=changezone&page=/zone_urban.php');
	return false;
}

function doTranquil() {
	doIt('tranquil');
	//setFlashVariables('sendmovie','command=changezone&page=/zone_urban.php');
	return false;
}

function doCampus() {
	doIt('campus');
	//setFlashVariables('sendmovie','command=changezone&page=/zone_urban.php');
	return false;
}

function doCommercial() {
	doIt('commercial');
	//setFlashVariables('sendmovie','command=changezone&page=/zone_urban.php');
	return false;
}

function doRoots() {
	doIt('roots');
	//setFlashVariables('sendmovie','command=changezone&page=/zone_urban.php');
	return false;
}

function doIt(which) {
	//alert('doit '+which);
//	setFlashVariables('sendmovie','page=/zones/'+which+'/&command=changezone');
//	setFlashVariables('sendmovie','page=http://www.submerge.org.uk&command=changezone');
setFlashVariables('sendmovie','page=/zones/'+which+'/');

}

/*
		
		firstH1 = x.getElementsByTagName('h1') ;
		firstH1 = firstH1.item(0);
		

		if ( firstH1.className == 'news' ) {
			afterH1 = firstH1.previousSibling;
			afterH1 = afterH1.previousSibling;
		}
		else {
			afterH1 = firstH1.nextSibling ;
		}
		
		
		insertBeforeThis = x.childNodes[3] ;
		
		y = x.getElementsByTagName('p') ;
		firstP = y.item(0) ;
		newAnchor = document.createElement('a') ;
		newAnchor.className = 'printpage' ;
		newAnchor.href= 'javascript:window.print();' ;
		newText = document.createTextNode('print page') ;
		
		/* add to the anchor */
//		newAnchor.appendChild(newText) ;
		
		/* stick anchor onto an existing object */
	//	x.insertBefore(newAnchor,afterH1) ;
//	}
	/* real jobs pages need a quicksearch submit button if they have js */
	//addQuickJobSearchGo();

//}

/*function addQuickJobSearchGo() {
	x = document.getElementById('jobsearchform') ;
	if ( x ) {
		newDiv2 = document.createElement('div') ;
		newDiv2.id = 'go_but' ;
		
		newLink = document.createElement('a') ;
		newLink.title = 'Submit form and find matching jobs' ;
		newLink.className = 'submit_green' ;
		newLink.href = 'javascript:document.getElementById(\'jobsearchform\').submit();' ;
		
		newText2 = document.createTextNode('Go');
		
		newLink.appendChild(newText2);
		
		newDiv2.appendChild(newLink);
		
		
		ns = document.getElementById('notscriptsubmit') ;


		x.insertBefore(newDiv2,ns) ;
	}

}*/


isIE = (document.all) ? true:false;

/*
if (window.attachEvent) {
	window.attachEvent("onload", focusIt);
}
else if (document.addEventListener || window.addEventListener) {
	if (document.addEventListener) {
		document.addEventListener("load", focusIt, false);
	};
	if (window.addEventListener) {
		window.addEventListener("load", focusIt, false);
	};
}
else {
	if (typeof window.onload == "function") {
		var fOld = window.onload;
		window.onload = function(){ fOld(); focusIt(); };
	}
	else {
		window.onload = focusIt;
	};
};


 */

if ( window.attachEvent ) {
	window.attachEvent('onload',addZoneNavEvents);
}
else if (document.addEventListener || window.addEventListener) {
	if (document.addEventListener) {
		document.addEventListener("load", addZoneNavEvents, false);
	};
	if (window.addEventListener) {
		window.addEventListener("load", addZoneNavEvents, false);
	};
}
else {
	if (typeof window.onload == "function") {
		var fOld = window.onload;
		window.onload = function(){ fOld(); addZoneNavEvents(); };
	}
	else {
		window.onload = addZoneNavEvents;
	};
};


/*
 * FlashObject embed
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 * v1.1.0 - 03-31-2005
 *
 * writes the embed code for a flash movie, includes plugin detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.write("objId");
 *
 * for best practices, see:
 *  http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
 *
 */

var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";

	this.params = new Object();
	this.variables = new Object();

	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

var FOP = FlashObject.prototype;

FOP.addParam = function(name, value) { this.params[name] = value; }

FOP.getParams = function() { return this.params; }

FOP.getParam = function(name) { return this.params[name]; }

FOP.addVariable = function(name, value) { this.variables[name] = value; }

FOP.getVariable = function(name) { return this.variables[name]; }

FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;	
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
    	variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else if (this.altTxt) {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}

/* ---- detection functions ---- */
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
   			flashversion_tens = y.charAt(y.indexOf('.')-2);
			if (parseInt(flashversion_tens) > 0) {
				flashversion = parseInt(flashversion) + parseInt(flashversion_tens * 10);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	return (getFlashVersion() >= ver) ? true:false; }

// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}


			
//]]>
