window.addEventListener("load", pageLoaded, false);
window.addEventListener("orientationchange", updateOrientation, false);

function pageLoaded()
{
	fullscreen();
	fixHovers();
	
	setTimeout("updateOrientation();", 10);
}

function hideAddressBar()
{
	if(window.pageYOffset <= 1)	window.scrollTo(0, 1);
}

function updateOrientation()
{
	var orientation	= "portrait";
	if(window.orientation == 90 || window.orientation == -90)	orientation	= "landscape";
	document.body.setAttribute("orient", orientation);
	
	hideAddressBar();
}

function fullscreen()
{
	var a	= document.getElementsByTagName("a");
	for(var i=0; i<a.length; i++)
	{
		if(a[i].target != "_blank")
		{
			a[i].onclick	= function()
			{
				window.location	= this.getAttribute("href");
				return false;
			}
		}
	}
}


function fixHovers()
{
	var links	= document.getElementsByTagName("a");
	var l		= links.length;
	for(var i=0; i<l; i++)
	{
	   links[i].addEventListener("touchstart", replaceTouchStart, false);
	   links[i].addEventListener("touchend", replaceTouchEnd, false);
	   links[i].addEventListener("touchcancel", replaceTouchEnd, false);
	}
}

function replaceTouchStart()
{
	this.className	+= " hover";
}

function replaceTouchEnd()
{
	this.className.replace(" hover", "");
}