if
(function() {

	var ua = navigator.userAgent + '';

	if (ua.match(/ip(hone|od|ad)|android|opera m(ob|in)i/i)) return true;
	if (window.screen.width <= 480) return true;

}())
(function() {

	function prot(that, prot) { for (var i in prot) that[i] = prot[i]; }
	
	function createButton(href, text, action) {

		var a = document.createElement('a');
		a.href = href;
		a.onclick = action;
		a.innerHTML = text;
		a.className = 'nav-button';
		return a;

	}

	function MobileApp() {

		var _active;
		var _button;
		var _event;
		var _navigationMode = false;

		prot(this, {


			bind: function(fn) {
				var that = this;
				return function() {
					return fn.apply(that, arguments);
				};
			},

			init: function() {
				_active = false;
				_event = false;
				this.activate ();
			},

			createButton: function() {
				var h1 = document.getElementsByTagName('h1');
				if (h1 && h1[0]) {
					var a = createButton('#nav', 'Menu', this.bind(this.buttonClicked));
					h1[0].parentNode.insertBefore (a, h1[0].nextSibling);
					_button = a;
				}
			},

			updateNavigationMode: function() {
				if (_navigationMode) {
					document.documentElement.className = 'mobile mobile-nav';
				} else {
					document.documentElement.className = 'mobile';
				}
			},

			buttonClicked: function() {
				_navigationMode = !_navigationMode;
				this.updateNavigationMode ();
				return false;
			},

			createNavigationHeader: function() {
				var nav;
				if (nav = document.querySelector('.navigation')) {
					var a = createButton('#', 'Back', this.bind(this.buttonClicked));
					nav.insertBefore (a, nav.firstChild);
					var h1 = document.createElement('h1');
					h1.innerHTML = 'Menu';
					nav.insertBefore (h1, nav.firstChild);
				}
			},

			domLoaded: function() {
				this.createButton ();
				this.updateNavigationMode ();
				this.createNavigationHeader ();
			},

			activate: function() {
				_active = true;
				document.documentElement.className = 'mobile';
				if (!_event) {
					_event = false;
					document.addEventListener ('DOMContentLoaded', this.bind(this.domLoaded), false);
				}
			},

			deactivate: function() {
				_active = false;
				document.documentElement.className = '';
			}


		});
		this.init ();

	}

	new MobileApp();

})();

