/*
Name:       touch device handling (iPhone and iPod Touch)
Version:    0.1 (Dezember 10 2009)
Company:    stadt.werk	
Author:     Finn Rudolph
Support:	rudolph@stadtwerk.org

Licence:    This script is licensed under a Creative Commons 
            Attribution-Noncommercial 3.0 Unported License 
            (http://creativecommons.org/licenses/by-nc/3.0/).

            You are free:
                + to Share - to copy, distribute and transmit the work
                + to Remix - to adapt the work

            Under the following conditions:
                + Attribution. You must attribute the work in the manner specified by the author or licensor 
                  (but not in any way that suggests that they endorse you or your use of the work). 
                + Noncommercial. You may not use this work for commercial purposes. 

            + For any reuse or distribution, you must make clear to others the license terms of this work.
            + Any of the above conditions can be waived if you get permission from the copyright holder.
            + Nothing in this license impairs or restricts the author's moral rights.
*/

/* Sets CSS class name for the body tag depending on device orientation */
function setOrientationCSS()
{
	switch(window.orientation)
	{    
		 case 0: 
			document.body.setAttribute('class','portrait');
			break;  

		 case -90:
			document.body.setAttribute('class','landscape');
			break;  

		 case 90: 
			document.body.setAttribute('class','landscape');
			break;  
	} 
}

/* Hides the Safari addressbar by scrolling it out of the viewport */
function hideAddressBar(timeout)
{
	setTimeout( function(){ window.scrollTo(0, 50); }, timeout);
}

domReady(function()
{
	/* Check for touch devices (iPhone and iPod Touch) */
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) 
	{
		hideAddressBar(1000);
		setOrientationCSS();

		window.onorientationchange = function()
		{
			setOrientationCSS();
			hideAddressBar(10);
		}
 	}
});
