function fbs_click(u) {
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function ImageScaler(originalWidth, originalHeight)
{
	this.winW = 0;
	this.winH = 0;
	this.fullWidth = originalWidth;
	this.fullHeight = originalHeight;
	this.aspect = (1.0*this.fullWidth)/this.fullHeight;
	this.width = originalWidth;
	this.height = originalHeight;
	this.scalingOn = true;
	
	this.setFullSize = (function(fullWidth, fullHeight)
	{
		this.fullWidth = fullWidth;
		this.fullHeight = fullHeight;
		this.aspect = (1.0*this.fullWidth)/this.fullHeight;
	});
	
	this.fitToWindow = (function()
	{
		if (typeof(window.innerWidth) == 'number')
		{
			//Non-IE
			this.winW = window.innerWidth;
			this.winH = window.innerHeight;
		}
		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			//IE 6+ in 'standards compliant mode'
			this.winW = document.documentElement.clientWidth;
			this.winH = document.documentElement.clientHeight;
		}
		else if (document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			//IE 4 compatible
			this.winW = document.body.clientWidth;
			this.winH = document.body.clientHeight;
		}
		
		this.width = this.fullWidth;
		this.height = this.fullHeight;
		
		$("#zoomCell").hide();
		
		// shrink height to fit window (with some buffer room)
		if (this.winH-100 < this.height)
		{
			$("#zoomCell").show();
			if (this.scalingOn)
			{
				this.height = this.winH-100;
				this.width = Math.round(this.height * this.aspect);
			}
		}
		
		// shrink width to fit window (with some buffer room)
		if (this.winW-100 < this.width)
		{
			$("#zoomCell").show();
			if (this.scalingOn)
			{
				this.width = this.winW-100;
				this.height = Math.round(this.width / this.aspect);
			}
		}
	});
	
	
	this.scaleImage = (function()
	{
		document.getElementById("photocell").style.width = this.width + "px";
		document.getElementById("photocell").style.height = this.height + "px";
		//document.getElementById("photo").style.width = this.width + "px";
		//document.getElementById("photo").style.height = this.height + "px";
		if (document.getElementById("menu_browse"))
		{
			document.getElementById("menu_browse").style.width = this.width + "px";
			document.getElementById("menu_browse").style.height = this.height + "px";
		}
		
		document.getElementById("contentcell").style.width = Math.max(this.width, 600) + "px";
		//document.getElementById("container").style.width = (this.width+80) + "px";
	});
	
	this.update = (function()
	{
		this.fitToWindow();
		this.scaleImage();
	});
}

function clearBox(box)
{
	if (box.value == box.defaultValue)
	{
		box.value = "";
	}
}

function isFormTag(tagName)
{
	tagName = tagName.toUpperCase();
	
	if (tagName == "INPUT" ||
		tagName == "TEXTAREA" ||
		tagName == "SELECT" ||
		tagName == "OPTION" ||
		tagName == "BUTTON") {
		return true;
	}
	
	return false;
}

function addKeyNavigation(a,b,c,d,e,f,g,h)
{
	$(document).keydown(function(event)
	{
		if (!isFormTag(event.target.tagName))
		{
			switch (event.which)
			{
				case 37:
					if (a)
						document.location = b;
					break;

				case 39:
					if (c)
						document.location = d;
					break;
				
				
				case 76:
					document.location = e;
					break;
					
				case 66:
					document.location = f;
					break;
					
				case 65:
					document.location = g;
					break;
					
				case 83:
					document.location = h;
					break;
			}
		}
	});
}
