// JavaScript Document

$( document ).ready(function() {
	// Hide the address bar (for mobile devices)!
if( !window.location.hash && window.addEventListener ){
    window.addEventListener( "load",function() {
        setTimeout(function(){
            window.scrollTo(0, 0);
        }, 0);
    });
}
 
			 
function scaleStage() {
var stage = $('#stage'); 
var parent =  $('#stage').parent(); // Set a reusable variable to reference the parent container of the stage
var parentWidth = stage.parent().width(); // Get the parent of the stage width
var parentHeight = $(window).height(); // Get the browser window height
var stageWidth = stage.width(); // Get the stage width
var stageHeight = stage.height(); // Get the stage height
var desiredWidth = Math.round(parentWidth * 1); // Set the new width of the stage as it scales
var desiredHeight = Math.round(parentHeight * 1); // Set the new height of the stage as it scales
var rescaleWidth = (desiredWidth / stageWidth);  
var rescaleHeight = (desiredHeight / stageHeight); 
var rescale = rescaleWidth;

if (stageHeight * rescale > desiredHeight) // Do not scale larger than the height of the browser window
rescale = rescaleHeight;
// Rescale the stage!
stage.css('transform','scale(' + rescale +')');
stage.css('-o-transform','scale(' + rescale +')');
stage.css('-ms-transform','scale(' + rescale +')');
stage.css('-webkit-transform','scale(' + rescale +')');
stage.css('-moz-transform','scale(' + rescale +')');
stage.css('-o-transform','scale(' + rescale +')');
stage.css({

	"-webkit-transition":"0.2s ease-in-out",
	"-moz-transition":"0.2s ease-in-out",
	"-o-transition":"0.2s ease-in-out",
	"transition":"0.2s ease-in-out",
	 "transform-origin":"0 0",
	"-ms-transform-origin":"0 0",
	"-webkit-transform-origin":"0 0",
	"-moz-transform-origin":"0 0",
	"-o-transform-origin":"0 0",
 });
parent.height(stageHeight * rescale); // Reset the height of the parent container so the objects below it will reflow as the height adjusts
 

}



// Make it happen when the browser resizes
$( window ).resize(function() {
 if ($(window).width()<1366) {
scaleStage();
 } else{
	   $('#stage').css({
	"transform":"scale(1)",
	"-o-transform":"scale(1)",
	"-ms-transform":"scale(1)",
	"-webkit-transform":"scale(1)",
	"-moz-transform":"scale(1)",
	"-o-transform":"scale(1)",});
 }
	 
}); 
 
 

// Make it happen when the page first loads
$(document).ready(function(){
  if ($(window).width()<=1366) {
scaleStage();
 } else{
	   $('#stage').css({
	"transform":"scale(1)",
	"-o-transform":"scale(1)",
	"-ms-transform":"scale(1)",
	"-webkit-transform":"scale(1)",
	"-moz-transform":"scale(1)",
	"-o-transform":"scale(1)",});
 }
 
});
$(window).load(function(){
 if ($(window).width()<=1366) {
scaleStage();
 } else{
	   $('#stage').css({
	"transform":"scale(1)",
	"-o-transform":"scale(1)",
	"-ms-transform":"scale(1)",
	"-webkit-transform":"scale(1)",
	"-moz-transform":"scale(1)",
	"-o-transform":"scale(1)",});
 }
 
}); 


});