// IMAGE SWAP by FLETCHER MOORE
//
// Ye olde JS image swap stuff.

function swap(me) {
	if (arguments.length > 1) {
		me.src = arguments[1];
	} else {
		t = me.src.indexOf("/there");
		o = me.src.indexOf("/over");
		if (t > 0) { me.src = me.src.replace("/there","/over"); }
		if (o > 0) { me.src = me.src.replace("/over","/there"); }
	}
}

function preload() {
	i = new Array();
	for (x=0; x<arguments.length; x++) {
		i[x] = new Image();
		i[x].src = "images/" + arguments[x];
	}
}



// FIND MOUSE POSITION FOR PORTFOLIO

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Main function to retrieve mouse x-y pos.s

var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  

  return true
}

// FIND IMAGE POSITION

var trueX = 0;
var trueY = 0;

function getRealLeft(el) {
	xPos = el.offsetLeft; tempEl = el.offsetParent;
	while (tempEl != null) { 
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	} return xPos;
}

function getRealTop(el) {
	yPos = el.offsetTop; tempEl = el.offsetParent;
	while (tempEl != null) { 
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	} return yPos;
}

function return_positions(myImage) {
	if (document.all) { // determine position in IE
		trueX = getRealLeft(document.images[myImage]);
		trueY = getRealTop(document.images[myImage]);
    } else if (document.layers) { // determine position in netscape 4
 		trueX = document.images[myImage].x;
 		trueY = document.images[myImage].y;
    } else if (document.getElementById) { // determine position in NS6
 		trueX = getRealLeft(document.images[myImage]);
 		trueY = getRealTop(document.images[myImage]);
 	}
}

var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0, width=400, height=300';

function isUndefined(v) {
    var undef;
    return v===undef;
}

function raw_popup(url, target, features) {
  if (isUndefined(features)) {
    features = _POPUP_FEATURES;
  }
  if (isUndefined(target)) {
    target = '_blank';
  }
  var theWindow = window.open(url, target, features);
  theWindow.focus();
  return theWindow;
}

function popup(src, features) {
  return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}



function show(myDiv, myImage) {
	return_positions(myImage);
	d = document.getElementById(myDiv).style;
	d.visibility = 'visible';
	d.left = trueX + 30 + "px";
	d.top = trueY + 30 + "px";
}

function hide(myDiv) {
	d = document.getElementById(myDiv).style;
	d.visibility = 'hidden'; 
}

