/*
 * CREATIVE SKILLS
 *
 * (C)opyright 2005. All rights reserved.
 *
 * Web Design, Development & Content Management System
 * by Adrian Keeling-Look, LOOKsystems Limited
 * mailto: adrian@looksystems.ltd.uk
 *
 * Graphic Design & Artistic Direction
 * by Elizabeth Haven, Empress
 * mailto: elizabeth@empress-design.co.uk
 * 
 */

/*
 * Submit Once - insipred on lightbox
 * Lightbox JS: Fullsize Image Overlays 
 * by Lokesh Dhakar - http://www.huddletogether.com
 *
 * For more information on this script, visit:
 * http://huddletogether.com/projects/lightbox/
 */

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function apply_submitonce(objForm) {
	if (typeof objForm == 'string') objForm = document.getElementById(objForm);
	if (objForm != undefined) {
		objForm.onsubmit = function() { submitonce(this); return true; }
	} else {
		for (var f = 0; f < document.forms.length; ++f) {
			document.forms[f].onsubmit = function() { submitonce(this); return true; }
		}
	}
}

var showoverlay = true;
function submitonce(objForm) {

	if (!objForm) return;
	if (showoverlay) {
		var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
	}
	// if (typeof(objForm.submit) == 'function') objForm.submit();
	for (objElement in objForm.elements) {
		objElement.disabled = true;
	}

}

// DOCUMENT FOCUS

function sf() {
	var e = 0;
	if (!document.forms.length) return;
	var myform = document.forms[0];
	while (e < myform.elements.length) {
		switch (myform.elements[e].type) {
		case "text":
		case "textarea":
		case "password":
			myform.elements[e].focus();
			return;
		}
		e++;
	}
}

// PRELOAD IMAGES

function images_preload() {
	if (!document.images) return;
	var a, args = preload.arguments;
	for (a = 0; a < args; ++a) {
		if (args[a].indexOf(args[a], '#') < 0) {
			var image = new Image;
			image.src = args[a];
		}
	}
}

// POPUP SUPPORT

var popups = new Object;
var popups_child;

function popups_initialise() {
	if (!document.links.length) return;
	var a = 0;
	while (a < document.links.length) {
		var id = document.links[a].id;
		if (!popups[id]) id = document.links[a].id;
		if (!popups[id] && id.substring(0, 5) == 'popup') id = 'popup';
		if (popups[id] != null || id == 'popup') {
			var href = document.links[a].href;
			document.links[a].href = "javascript:popup('"+id+"','"+href+"')";
			document.links[a].target = "_self";
		}
		a++;
	}
}

function popup(id, url) {
	var name, features;
	if (popups != null) features = popups[id];
	if (features != null) {
		name = features[0];
		var x = features[1];
		var y = features[2];
		var w = features[3];
		var h = features[4];
		if (x < 0) x = (window.screen.availWidth - w) / 2;
		else if (window.screenX != null) x += window.screenX;
		if (y < 0) y = (window.screen.availHeight - h) / 2;
		else if (window.screenY != null) y += window.screenY;
		features = features[5];
		if (features != "") features += ",";
		features += "width="+w+",height="+h;
		features += ",screenX="+x+",screenY="+y;
		features += ",left="+x+",top="+y;
	}
	if (popups_child != null) {
		if (popups_child.close != null) popups_child.close();
		else name = '';
	}
	popups_child = window.open(url, name, features);
	if (popups_child != null && popups_child.focus != null) popups_child.focus();
}

// ROLLOVER SUPPORT

var rollovers = new Object;

function ro(image, src) {
	if (!image || !src) return;
	image.src = src;
}

// DOCUMENT INITIALISE

function init() {
	popups_initialise();
	sf();
}
