var n = (document.layers) ? 1:0; 
var ie = (document.all) ? 1:0;
var safari = (navigator.userAgent.indexOf("Safari") > -1) ? 1:0;
var mac = (navigator.userAgent.indexOf('Mac') > -1) ? 1:0;

function openWin(html, name, wval, hval, sval) {
	
	// set general size vars
	var w_val = wval;
	var h_val = hval;
	var s_val = sval;

	// if browser is ie mac
	if (ie && mac) {
		w_val -= 16;
		h_val -= 16;
	}
	
	// if browser is safari
	if (safari) {
		w_val -= 2;
		h_val += 15;
	}
	
	// open the browser
	var nw=window.open(html,name,'width='+w_val+',height='+h_val+',status=yes,menubar=no,scrollbars='+s_val+',resizable=no');

	
	// move it to the upper lefthand corner
	//nw.moveTo(0,0);
	nw.moveTo(((screen.width/2)-(w_val/2)),((screen.height/2)-(h_val/2)));
	
	nw.focus();
	
}



// pull-down menu navigation.  Used with category menu.

function gotoCategory(index) {
	document.getElementById("categories").submit()
}


//taken from http://www.dhtmlkitchen.com/ used for gallery
// Remember, the image's name will be the same as the
// file name except without the extension (.gif/.jpg/.png)
  
function loadimages() {

 for (var i = 0; i < arguments.length; i++) {
	 var temp = makeId(arguments[i]);
	 eval(temp +"= new Image()");
	 eval(temp+".src ='"+ arguments[i] +"'");

 }
}

//used above
function makeId(path) {
	return path.substring(path.lastIndexOf("/")+1, path.lastIndexOf("."));
}


//swap used for gallery

function swap(id, newimg) {
	var me = document.getElementById(id);	
	me.src = newimg.src;
}


//open comments

function openComments(html) {
	var wval=255;
	var hval=540;
	var x=open( html, 'comment', 'width='+wval+',height='+hval+',directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes');
	x.moveTo(((screen.width/2)-(wval/2)),((screen.height/2)-(hval/2)));
	x.focus();
}


//captures rel="external" and launches in new window - feels like a hack but gets around limits in xhtml strict

function setExternal() {

if (!document.getElementsByTagName) return; 
var anchors = document.getElementsByTagName("a"); 
for (var i=0; i<anchors.length; i++) { 
	var anchor = anchors[i]; 
	if (anchor.getAttribute("href") && 
	  anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
	}
}
}


//from chandler via chris

function prepRollovers() {
	var rollfound=0;

	if (document.getElementsByTagName) {

// grab all the images on a page

	for (z=0;z<document.getElementsByTagName("img").length;z++) {
		thisImg = document.getElementsByTagName("img")[z];

// check that its got the proper class
		if (thisImg.className !=null) { /* safari seems to break when these two tests are combined */
			if (thisImg.className.indexOf("roll") != -1) {
				rollfound++;

// define states, preload the image and attach the event handlers
				thisImg.out = new Image(); thisImg.out.src = thisImg.src;

//hacked by essl to use with gifs and jpegs not sure if this is the best way
				if(thisImg.src.toString().indexOf(".gif")!=-1) {
					thisImg.over = new Image(); thisImg.over.src = thisImg.src.toString().replace(/.gif/i,"_o.gif");
				 }
				if(thisImg.src.toString().indexOf(".jpg")!=-1) {
					thisImg.over = new Image(); thisImg.over.src = thisImg.src.toString().replace(/.jpg/i,"_o.jpg");
				 }					
				thisImg.parentNode.onmouseover = function () {
					this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].over.src;
				};
				thisImg.parentNode.onmouseout = function () {
					this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].out.src;
				};
			}
		}		
	}
}
}


//start the party right here - happens onload in body

function startall() {

//load the roll overs for class="roll"			
	prepRollovers();

//load the script that rocks the "target" style outbound link
	setExternal();				
}


