var ssIndexes = Object();
var pes = Object();

window.onload = height;

function height() {
	if (!netscape()) {
		if ($('subcontainer') != null && $('subcontainer').offsetHeight < 534) {
			$('subcontainer').style.height = '536px';
		}
	}
}

function startShow(albumId, fileNames, urls, start) {
	ssIndexes[albumId] = start;
	new PeriodicalExecuter(function(pe) {
		ssNext(albumId, fileNames, urls, false);
		pes[albumId] = pe;
	}, 2 + Math.random());
}

function ssNext(albumId, fileNames, urls, clicked) {
	if (clicked || pes[albumId] != null) {
		ssIndexes[albumId]++;
		if (ssIndexes[albumId] > fileNames.length - 1) {
			ssIndexes[albumId] = 0;
		}
		$('ssImage' + albumId).src = 'photos/' + fileNames[ssIndexes[albumId]];
		$('ssUrl' + albumId).href = urls[ssIndexes[albumId]];
	}
	if (clicked && pes[albumId] != null) {
		pes[albumId].stop();
		delete pes[albumId];
		startShow(albumId, fileNames, urls, ssIndexes[albumId]);
	}
}

function ssPrevious(albumId, fileNames, urls, clicked) {
	if (clicked || pes[albumId] != null) {
		ssIndexes[albumId]--;
		if (ssIndexes[albumId] < 0) {
			ssIndexes[albumId] = fileNames.length - 1;
		}
		$('ssImage' + albumId).src = 'photos/' + fileNames[ssIndexes[albumId]];
		$('ssUrl' + albumId).href = urls[ssIndexes[albumId]];
	}
	if (clicked && pes[albumId] != null) {
		pes[albumId].stop();
		delete pes[albumId];
		startShow(albumId, fileNames, urls, ssIndexes[albumId]);
	}
}

var di = 0;

function loaded() {
	for (var i = 0; i < 100; i++) {
		var temp = document.createElement('div');
		temp.id = i;
		temp.style.width = '20px';
		temp.style.height = '20px';
		temp.style.backgroundColor = 'black';
		document.body.appendChild(temp);
		moveTo(temp, 100, 100, 2000, 50);
	}
}

function moveTo(o, x, y, totalTime, stepTime) {
	try {
		o.style.left = from_left(o) + 'px';
		o.style.top = from_top(o) + 'px';
		o.style.position = 'absolute';
		
		var numSteps = Math.ceil(totalTime / stepTime);
		var incrementX = (x - parseInt(o.style.left)) / numSteps;
		var incrementY = (y - parseInt(o.style.top)) / numSteps;
		
		moveInterval(o, numSteps, stepTime, incrementX, incrementY);
	}
	catch (e) {
		d(e);
	}	
}

function moveInterval(o, numSteps, stepTime, incrementX, incrementY) {
	try {
		o = $(o);
		if (numSteps) {
			o.style.left = (parseFloat(o.style.left) + incrementX).toString() + 'px';
			o.style.top = (parseFloat(o.style.top) + incrementY).toString() + 'px';
			setTimeout('moveInterval("' + o.id + '", ' + --numSteps + ', ' + stepTime + ', ' + incrementX + ', ' + incrementY + ')', stepTime);
		}
		else {
			moveTo(o, Math.round(Math.random() * 1000), Math.round(Math.random() * 750), 2000, 50);
		}
	}
	catch (e) {
		alert(e);
	}
}

function round2(num, precision) {
	if (typeof num == 'number' && typeof precision == 'number') {
		return Math.round(num * precision) / precision;
	}
	else {
		return num;
	}
}

Date.prototype.getAmpm = function() {
	if (this.getHours() >= 12) {
		return 'pm';
	}
	else {
		return 'am';
	}
}

Date.prototype.getHours12 = function() {
	if (this.getHours() == 0) {
		return 12;
	}
	else if(this.getHours() > 12) {
		return this.getHours() - 12;
	}
	else {
		return this.getHours();
	}
}

Date.prototype.getFullSeconds = function() {
	if (this.getSeconds() < 10) {
		return '0' + this.getSeconds().toString();
	}
	else {
		return this.getSeconds();
	}
}

Date.prototype.getMinutes2 = function() {
	if (this.getMinutes() == 0) {
		return '00';
	}
	else {
		return this.getMinutes();
	}
}

function toggle(o) {
	if (get_style(o, 'display') == 'none') {
		o.style.display = '';
	}
	else {
		o.style.display = 'none';
	}
}

function dom_remove(o) {
	if (o.parentNode != null) {
		o.parentNode.removeChild(o);
	}
}

function clone_object(what) {
	for (i in what) {
		this[i] = what[i];
	}
}

function false_function() { return false; }

var dline = 1;
var useDebug = true;

function d_on() {
	useDebug = true;
}

function d_off() {
	useDebug = false;
}

document.ondblclick = clear_debug;

function clear_debug() {
	if ($('debug') != null) {
		$('debug').style.display = 'none';
		$('debug').innerHTML = '';
	}
}

function d() {
	if (!useDebug) {
		return false;
	}
	//alert('called d with argument' + arguments[0]);
	if (document.body == null) {
		var argStr = '';
		for (var i = 0; i < arguments.length; i++) {
			argStr += '\'' + arguments[i] + '\',';
		}
		argStr = argStr.substr(0, argStr.length-1);
		setTimeout('d(' + argStr + ')', 100);
	}
	else {
		if ($('debug') == null) {
			try {
				var div = document.createElement('<div id="debug" style="position:absolute; right:0px; top:0px; background-color:black; color:lime; border:1px solid white; padding:3px 10px 3px 10px; font-family:Verdana; font-size:11px; width:500px; height:150px; overflow:auto;"></div>');
			}
			catch(e) {
				var div = document.createElement('div');
				div.setAttribute('id', 'debug');
				div.setAttribute('style', 'position:fixed; right:0px; top:0px; background-color:black; color:lime; border:1px solid white; padding:3px 10px 3px 10px; font-family:Verdana; font-size:11px; width:500px; height:150px; overflow:auto;');	
			}
			document.body.appendChild(div);
		}
		$('debug').style.display = '';
		switch (arguments.length) {
			case 1:
				// just add this string to the window
				$('debug').innerHTML += 'Line ' + dline++ + ': ' + arguments[0] + '<br />';
			break;
					
			case 2:
			
			break;
		}
		$('debug').scrollTop = $('debug').scrollHeight - $('debug').clientHeight;
	}
}

function trim(str) {
	return str.replace(/^\s*|\s*$/g, '');
}

function get_style(element, property) {
	try
	{
		if (element.style[property])
			return element.style[property];
		else if (element.currentStyle)
			return element.currentStyle[property];
		else if (document.defaultView && document.defaultView.getComputedStyle)
		{
			var style = document.defaultView.getComputedStyle(element, null);
			return style.getPropertyValue(property);
		}
	}
	catch (e) {}

	return null;
}

function right_side(o) {
	return from_left(o) + o.offsetWidth;
}

function bottom_side(o) {
	return from_top(o) + o.offsetHeight;
}

function hide() {
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') {
			element = document.getElementById(element);
			element.style.display = 'none';
		}
	}
}

function show() {
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') {
			element = document.getElementById(element);
			element.style.display = '';
		}
	}
}

function addslashes(str) {
	return str.replace(/([\'\\\"])/gi, '\\$1');
}

function stripslashes(str) {
	if (typeof str == 'string') {
		return str.replace(/\\([\'\"\\])/gi, '$1');
	}
	else {
		return str;
	}
}

function is_email(str) {
	if (str.match(/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/gi)) {
		return true;
	}
	else {
		return false;
	}
}

function explode(delim, str) {
	return str.split(delim);
}

function end(array) {
	return array[array.length-1];
}

function get_ext(str) {
	return end(explode('.', str));
}

function from_left(o) {
	var left = 0;
	if (get_style(o, 'position') == 'absolute') {
		left += parseInt(o.style.left);
	}
	else {
		left += o.offsetLeft;
	}
	if (o.offsetParent) {
		left += from_left(o.offsetParent);
	}
	return left;
}

function from_top(o) {
	var top = 0;
	if (get_style(o, 'position')  == 'absolute') {
		top += parseInt(o.style.top);
	}
	else {
		top += o.offsetTop;
	}
	if (o.offsetParent) {
		top += from_top(o.offsetParent);
	}
	return top;
}

function netscape() {
	if (navigator.appName == 'Netscape') {
		return true;
	}
	else {
		return false;
	}
}

function is_ie() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		return true;
	}
	else {
		return false;
	}
}

function get_screen_width() {
	if (netscape()) {
		return window.innerWidth;
	}
	else {
		return document.body.clientWidth;
	}
}

function get_screen_height() {
	if (netscape()) {
		return window.innerHeight;
	}
	else {
		return document.body.clientHeight;
	}
}

function get_scroll_x() {
	var scrOfX = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfX = window.pageXOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfX;	
}

function get_scroll_y() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

function screen_top() {
	return get_scroll_y();
}

function screen_right() {
	return get_screen_width() + get_scroll_x();
}

function screen_bottom() {
	return get_screen_height() + get_scroll_y();
}

function screen_left() {
	return get_scroll_x();
}

function move_to_center(o) {
	o.style.position = 'absolute';
	o.style.left = screen_left() + Math.floor(get_screen_width() / 2) - Math.floor(o.offsetWidth / 2) + 'px';
	o.style.top = screen_top() + Math.floor(get_screen_height() / 2) - Math.floor(o.offsetHeight / 2) + 'px';
}