var lib = {
	browser: function()
	{
		this.ua = navigator.userAgent.toLowerCase();
		this.dom = document.getElementById ? 1 : 0;
		this.op7 = (this.dom && this.ua.indexOf('opera 7') > -1 || this.ua.indexOf('opera/7') > -1) ? 1 : 0;
		this.ie5 = (this.dom && this.ua.indexOf('msie 5') > -1) ? 1 : 0;
		this.ie6 = (this.dom && this.ua.indexOf('msie 6') > -1) ? 1 : 0;
		this.moz = (this.dom && this.ua.indexOf('mozilla') > -1 && this.ua.indexOf('gecko') > -1) ? 1 : 0;
	},

	noLinkFocus: function()
	{
		if(links = document.getElementsByTagName('a'))
		{
			for(i=0;links[i];i++)
			{
				links[i].onfocus = new Function('this.blur()');
			}
		}
	}
}

lib.browser.prototype = {
	getInnerWidth: function()
	{
		if (window.innerWidth)
		{
			return window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
			return document.documentElement.clientWidth;
		}
		else if (document.body.clientWidth)
		{
			return document.body.clientWidth;
		}
		return 0;
	},

	getInnerHeight: function()
	{
		if (window.innerHeight)
		{
			return window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			return document.documentElement.clientHeight;
		}
		else if (document.body.clientHeight)
		{
			return document.body.clientHeight;
		}
		return 0;
	}
}

lib.event = {
	init: function(e)
	{
		lib.document.getcanvas();
		e = window.event ? window.event : e;
		this.mousex = typeof e.clientX != 'undefined' ? e.clientX + lib.document.scrollx : 0;
		this.mousey = typeof e.clientY != 'undefined' ? e.clientY + lib.document.scrolly : 0;
		this.layerx = typeof e.offsetX != 'undefined' ? e.offsetX : typeof e.layerX != 'undefined' ? e.layerX : 0;
		this.layery = typeof e.offsetY != 'undefined' ? e.offsetY : typeof e.layerY != 'undefined' ? e.layerY : 0;
		this.type = e.type;
		this.target = e.srcElement || e.target;
		if (this.target.nodeType == 3 || this.target.tagName.toLowerCase() == 'img') this.target = this.target.parentNode;
	},

	preventdefault: function(e)
	{
		if (window.event) window.event.returnValue = false;
		else if (e.preventDefault) e.preventDefault();
	},

	cancelbubble: function(e)
	{
		if (window.event) window.event.cancelBubble = true;
		else if (e.stopPropagation) e.stopPropagation();
	}
}

lib.document = {
	getcanvas: function()
	{
		if (document.documentElement && document.documentElement.scrollLeft) this.scrollx = document.documentElement.scrollLeft;
		else if (document.body && document.body.scrollLeft) this.scrollx = document.body.scrollLeft;
		else if (window.scrollX) this.scrollx = window.scrollX;
		else this.scrollx = 0;

		if (document.documentElement && document.documentElement.scrollTop) this.scrolly = document.documentElement.scrollTop;
		else if (document.body && document.body.scrollTop) this.scrolly = document.body.scrollTop;
		else if (window.scrollY) this.scrolly = window.scrollY;
		else this.scrolly = 0;
		
		if (document.documentElement && document.documentElement.clientWidth) this.width = document.documentElement.clientWidth;
		else if (document.body && document.body.clientWidth) this.width = document.body.clientWidth;
		else if (window.innerWidth) this.width = window.innerWidth;
		else this.width = 0;

		if (document.documentElement && document.documentElement.clientHeight) this.height = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) this.height = document.body.clientHeight;
		else if (window.innerHeight) this.height = window.innerHeight;
		else this.height = 0;
		
		this.w = this.width + this.scrollx;
		this.h = this.height + this.scrolly;
	}
}

var listener = {
	add: function(obj, et, fn, capture)
	{
		if (obj.addEventListener) { obj.addEventListener(et, fn, capture); return true; }
		else if (obj.attachEvent) { var ae = obj.attachEvent('on' + et, fn); return ae; }
	},
	remove: function(obj, et, fn, capture)
	{
		if (obj.removeEventListener) { obj.removeEventListener(et, fn, capture); return true; }
		else if (obj.detachEvent) { var re = obj.detachEvent('on' + et, fn); return re; }
	}
}

var bw = new lib.browser();

function initPhotoThumbs()
{
	if(bw.dom)
	{
		var links = document.getElementById('CONTENT').getElementsByTagName('a');
		for(i=0;i<links.length;i++)
		{
			if(links[i].className == 'photoThumb')
			{
				listener.add(links[i],'click',openPhoto,true);
			}
		}
	}
}

function openPhoto(e)
{// photoFileURL?width=num&height=num
	lib.event.init(e);
	var photoInfo = lib.event.target.href;
	var pairs = photoInfo.split('?');
	var photoFile = pairs[0];
	pairs = pairs[1].split('&');
	var photoWidth = (pairs[0].split('='))[1];
	var photoHeight = (pairs[1].split('='))[1];
	var left = (screen.width - photoWidth) / 2;
	var top = (screen.height - photoHeight) / 2;
	window.open('photo.html?photo='+photoFile,'','width='+photoWidth+', height='+photoHeight+',top='+top+',left='+left+',scrollbars=no,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no');
	lib.event.cancelbubble(e);
	lib.event.preventdefault(e);
}

function initPage()
{
	if(bw.dom)
	{
		initPhotoThumbs();
		lib.noLinkFocus();
	}
}

function resizePage()
{
}

onload = initPage;
onresize = resizePage;