


/**
 * THE BEER-WARE LICENSE
 * <lauri@rooden.ee> wrote this file. As long as you retain this notice you 
 * can do whatever you want with this stuff at your own risk. If we meet some 
 * day, and you think this stuff is worth it, you can buy me a beer in return.
 * -- Lauri Rooden -- https://github.com/lauriro/boot.js
 */



/**
 * Hide toolbar in mobile bi height
 * Set devise type by width
 */



!function(win, d, n) {
  var last, lastSize, lastOrient
	, b = d.body
	, heights = 
		{ 356: 416 // iPhone 1-4s Portrait
		, 444: 504 // iPhone 5 Portrait
		, 196: 416 // iPhone1-5 Landscape
		, 208: 416 // iPhone1-5 Landscape without addressbar
		}
  , resize = (heights[b.offsetHeight] ? by_size : win.devicePixelRatio && win.devicePixelRatio > 1 ? by_ratio : by_size).once(300)
	
	function by_ratio() {
		last !== ( last = win.outerHeight) && setSize( (last/win.devicePixelRatio)|0 )
	}

	function by_size() {
		// Reset body height so we can measure it again
		b.style.height = ""
		setSize( heights[b.offsetHeight] )
	}

	function forecast_height() {
		setTimeout(function(){
			screen.height > win.innerHeight && setSize(win.innerHeight+1)
		}, 300)
		return screen.height + 100
	}

  function setSize(size) {
		if (size < 700) {
			b.style.height = (size < 300 ? 300 : size) + "px"
		}
		setTimeout(function() { scrollTo(0, 2) }, 300)
		//var el = d.activeElement
		//if (lastSize && el && el.tagName == "INPUT") return
		setClasses()
  }

  function setClasses() {
    var width = b.offsetWidth
		, next = width < 601 ? "mob" : ( width < 1025 ? "tab" : "full")

    if ( next != lastSize ) {
      b.addClass( next ).rmClass( lastSize )
			lastSize = next
    }

    next = width > b.offsetHeight ? "landscape" : "portrait"

    if ( next != lastOrient) {
      b.addClass( next ).rmClass( lastOrient )
			lastOrient = next
    }
		M && M.emit("resize")
  }

	// iOS
  if ("standalone" in n) {
    if (n.standalone || b.offsetHeight > 600) {
      //Event.add(d, "touchmove", Event.stop); // disable drag on standalone mode
      resize = setClasses
    }
  } else {
		Event.add(win, "resize", resize )
	}

	Event.add(b, "orientationchange", resize)
		
	Event.add(win, "load", resize)
}(this, document, navigator)




