/*
 * The Bespoke iPhone Handlers
 * by mark@thebespokepixel.com
 * Version 1.0 (October 2007)
 */

IPHONE_DEBUG_MODE = true;
if(IPHONE_DEBUG_MODE && !utilitiesLoaded) alert("Please include utilities.js");

if(typeof theBespoke == "undefined") var theBespoke = new Object();

/*
 * iPhone Events
 */
theBespoke.iPhoneManager = function() {
	this.orientationRegisterArray = new Array();
	this.onChangeOrientation = function() { return false; };
}

theBespoke.iPhoneManager.prototype = {
	changeOrientation: function() {
		orient = this.getOrientation();
		for (var i = 0; i < this.orientationRegisterArray.length; i++) {
			this.orientationRegisterArray[i].setAttribute("orient", orient);
		}
		this.onChangeOrientation(orient);
	},
	getOrientation: function() {
		switch(window.orientation) {
			case 0:
			case 180: 
				return "portrait";
			break;
			
			case -90:
			case 90:
				return "landscape";
			break;
	        }
		return "unknown";
	},
	hideURLbar: function() {
		setTimeout(this.hideURLbarAction, 0);
	},
	hideURLbarAction:function () {
	        window.scrollTo(0, 1);
	},
	registerOrientationTarget: function() {
		orient = this.getOrientation();
		for (var i = 0; i < arguments.length; i++) {
			this.orientationRegisterArray.push(arguments[i]);
			arguments[i].setAttribute("orient", orient);
		}
	}
}
/*
 * Create namespace shortcuts
 */
var iPhoneManager = theBespoke.iPhoneManager;

