// --------------------------------------------------------------------------------
// ShibImages RC6
// This program is provided under the GNU/GPL license.
// See LICENSE file for more informations
// 
// Website : http://shibby.nl
// Contact email : shibimages@shibby.nl
// Author : Tomas Hastings (en) tomas@shibby.nl
//--------------------------------------------------------------------------------
function open_window(page)
{
	var pop_width=700;
	var pop_height=550;
	var H = (screen.height - pop_height) / 2;
	var L = (screen.width - pop_width) / 2;
	pop_up = window.open(page,"shibimages","status=yes,scrollbars=yes,resizable=yes,height="+pop_height+",width="+pop_width+",top="+H+",left="+L);
}
function slapWindow() {
	var iWidth = 0, iHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		// Non-IE
		iWidth = window.innerWidth;
		iHeight = window.innerHeight;
	} else {
		if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			// IE 6+ in 'standards compliant mode'
			iWidth = document.documentElement.clientWidth;
			iHeight = document.documentElement.clientHeight;
		} else {
			if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				// IE 4 compatible
				iWidth = document.body.clientWidth;
				iHeight = document.body.clientHeight;
			}
		}
	}
	iWidth = document.images[0].width - iWidth + 48;
	iHeight = document.images[0].height - iHeight + 72;
	window.resizeBy(iWidth, iHeight);
	self.focus();
}
function copy2Clipboard()
{
	// ie only, future version only display if ie?
	var textRange = document.body.createTextRange();
	textRange.moveToElementText(oCodeSpan);
	textRange.execCommand("Copy");
}

function keystroke(e) {
	// borrowed from viewer.vinz.nl
	var kcode, key;
	if (e == null) { // IE
		kcode = event.keyCode;
	} else { // Mozilla
		if (e.altKey || e.ctrlKey) return true;
		kcode = e.which;
	}
	key = String.fromCharCode(kcode).toLowerCase();
	switch (key) {
		case " ":
			if (document.height) {
				if ((window.innerHeight + window.pageYOffset) < document.height) {
					window.scrollBy(0, window.innerHeight/2);
				} else {
					next();
				}
			} else {
				next();
			}
			return false;
		case "n":
			next(); return false;
		case "p":
			prev(); return false;
		// backspace
		case String.fromCharCode(8): prev(); return false;
		case "h": scrollBy(-35,0); return false;
		case "j": scrollBy(0,35); return false;
		case "k": scrollBy(0,-35); return false;
		case "l": scrollBy(35, 0); return false;
	}
	return true;
}
document.onkeypress = keystroke;
