/* javascript file*/

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

/* navigation images */
//preload('nav__off', '/i/nav/.gif');
//preload('nav__on', '/i/nav/_on.gif');

function newWindow(link, width, height) {
   var swidth = screen.width;
   var sheight = screen.height;
   var popup = null;
   var left = (swidth/2) - (width/2);
   var top = (sheight/2) - (height/2);
   var over = "";
   popup = window.open(link,"msg","scrollbars=yes,resizable=yes,height="+height+",width="+width+",left="+left+",top="+top);

}

function changeImages() {
	for (var i = 0; i < changeImages.arguments.length; i += 2) {
		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i+1]).src;
	}
}

function imageViewer(pg, imageWidth, imageHeight){
	var left = Math.floor( (screen.width - imageWidth) / 2);
	var top = Math.floor( (screen.height - imageHeight) / 2);
	newWindow = window.open(pg,"iViewer","width="+imageWidth+",status=1,scrollbars=1,resizable=1,height="+imageHeight+",left="+left+",top="+top);
	newWindow.focus();
	return false;
}

function closeup(image_name, image_height) {
    var width = 600;
    var height = ((image_height - 5) * 3) + 10;
    var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
    newWindow = window.open('',"closeup","width="+width+",status=0,scrollbars=0,resizable=1,height="+height+",left="+left+",top="+top);
    newWindow.document.write('<html><head><title>'+document.title+'</title></head><body style="margin: 0px;">');
    newWindow.document.write('<img src="/i/portfolio/closeups/'+image_name+'.jpg" />');
    newWindow.document.write('</body></html>');
    newWindow.document.close();
    newWindow.onblur = function() { newWindow.close(); }
}

function evidence(image_name, image_height) {
	if(!image_height) {
		image_height = 400;
	}
    var width = 600;
    var height = image_height + 83;
    var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
    newWindow = window.open('',"evidence","width="+width+",status=0,scrollbars=0,resizable=1,height="+height+",left="+left+",top="+top);
    newWindow.document.write('<html><head><title>'+document.title+'</title></head><body style="margin: 0px;">');
    newWindow.document.write('<div style="padding: 17px 11px 7px 0px; background-color: #EBEBDB; text-align: right; border-bottom: 3px solid white;"><img src="/i/layout/logo.gif" width="117" height="54" alt="Pelago"></div>');
    newWindow.document.write('<img src="/i/evidence/large/'+image_name+'" />');
    newWindow.document.write('</body></html>');
    newWindow.document.close();
    newWindow.onblur = function() { newWindow.close(); }
}


//webmodule launcher
function launchWebMod(mode) {
	var URL, width, height;
	if(mode == "html") {
		URL = "/wmod/index.php";
		width = 717;
		height = 385;
	} else {
		URL = "/fmod/index.php";
		width = 626;
		height = 447;
	}
	var swidth = screen.width;
	var sheight = screen.height;
	var left = (swidth/2) - (width/2);
	var top = (sheight/2) - (height/2);
	window.open(URL,"webmodule","scrollbars=no,resizable=no,height="+height+",width="+width+",left="+left+",top="+top);
}

document.addEvent = function(object, eventType,fn, useCapture) {
	if (object.addEventListener) {
		object.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (object.attachEvent) {
			var r = object.attachEvent("on"+eventType, fn);
			return r;
		}
	}
};