/**
 * This library makes it possible to initially display a web page with a
 * zoom and scroll position.  This makes browsing the web pages on iPhones
 * much easier.
 * 
 * @author Bob Buffone
 * @copyright (c) 2008 Bob Buffone, http://rockstarapps.com/
 * @version 1.0.0
 * @license MIT-LICENSE
 * 
 *	
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *	
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *	
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
(function(){
	
	//Variable used to control the zoom and 
	//position of the page when it is loaded.
	var viewport = {
		initialScale: 0.4488078541374474,
		width: 980
	};
	//(-80) is for the navigation bar, otherwise you can't read it 
	//until it is fully loaded
	var scrollPosition = {
		left: 135,
		top: (98-80)
	};	
	//test for both iPod and iPhone. Thanks, Jay.
	if (/iP(hone|od)/i.test(navigator.userAgent)) { // sniff  	
		//write the meta tag for the initial scale.  This should 
		//happen in the <head> section of the html page.
		document.write('<meta name="viewport" content="width='+
					viewport.width+'; initial-scale=' + 
					viewport.initialScale + '">');
        
		//This loop will catch the page is loaded with out needing 
		//to use the onLoad event.
		var _timer = setInterval(function(){
		if (/loaded|complete|interactive/.test(document.readyState)) {
			clearInterval(_timer);
								 
			//This will scroll the content into view, 
			//could be enhanced with animated scrolling but less is more.
			//if the user started scrolling then let them handle it.
			if (window.pageXOffset == 0 && window.pageYOffset == 0)
				window.scrollTo(scrollPosition.left, 
				scrollPosition.top);
		}}, 10);
    }
})();
