//JavaScript
var minWidth = 1440;
var minHeight = 950;

$(document).ready(function(){
	hellResize();
});

$(window).resize(function(){
	hellResize();
});

function hellResize(){
	//get width of main page wrapper
	masterWidth = $('div.wrap-master').width();
	//compare main wrapper width to minimum width set above
	newWidth = (masterWidth < minWidth) ? minWidth: masterWidth;
	//get height of main page wrapper
	masterHeight = $('div.wrap-master').height();
	//compare main wrapper height to minumum height set above
	newHeight = (masterHeight < minHeight) ? minHeight: masterHeight;
	//apply new width and height to hellevator wrapper
	$('div.wrap-hellevator').css('width', newWidth+'px');
	$('div.wrap-hellevator').css('height', newHeight+'px');
	$('div.wrap-hellevator div.frame div.wrap-door').css('height', newHeight+'px');
	$('div.wrap-hellevator').css('width', newWidth+'px');
	$('div.wrap-hellevator div.frame div.wrap-door').css('width', newWidth+'px');
}

//listener that initiates drop of the elevator

$('div.wrap-hellevator div.frame div.hero').click(function(){
	hideHero();
});

/*************** Hide Hero Functionality ***************/
function hideHero(){
	$('div.wrap-hellevator div.frame div.hero').fadeOut(400, function(){
		setTimeout('dropElevator()', 10)
	});
}
/*************** /Hide Hero Functionality ***************/


/*************** Drop Elevator Functionality ***************/
var i = 0;
var topOffset;
function 	dropElevator(){	
	
	topOffset = $('div.wrap-hellevator div.frame div.wrap-gap div.gap').offset();
	$('div.debug').html(topOffset.top);

	$('div.wrap-hellevator div.frame div.wrap-gap div.gap').animate({
		marginTop: [(topOffset.top - 7020)+'px', 'easeInQuad']}, {duration: 2500, 
 			step: function(now, fx) {
    		var data = fx.elem.id + ' ' + fx.prop + ': ' + now;
    		
 				var floor = Math.round(Math.round(now) / 270) * -1;   		
    		
    		$('div.wrap-hellevator div.frame div.button-panel div.button').removeClass('current');
    		$('div.wrap-hellevator div.frame div.button-panel div.floor'+floor).addClass('current');
    		$('div.debug').html(floor);
    	},
    	complete: function(){
    		crushElevator();
    	}
  });
}
/*************** /Drop Elevator Functionality ***************/

/*************** Crush Elevator Functionality ***************/
function crushElevator(){
	$('div.wrap-hellevator div.frame div.wrap-door').css('display', 'block');
	$('div.wrap-hellevator img.bg').css('display', 'none');
	$('div.wrap-hellevator div.frame div.wrap-gap').css('display', 'none');
	setTimeout('openDoors()', 1000);
}
/*************** /Crush Elevator Functionality ***************/


/*************** Door Open Functionality ***************/
function openDoors(){
	//slide left door
	doorOffset = $('div.wrap-hellevator div.frame div.wrap-door div.left-door').width();
	$('div.wrap-hellevator div.frame div.wrap-door div.left-door').animate({
		marginLeft: [(doorOffset * -1)+'px', 'easeInQuad']
	}, 3000);
	//slide button panel with left door
	$('div.wrap-hellevator div.frame div.button-panel').animate({
		marginLeft: [(doorOffset * -1)+'px', 'easeInQuad']
	}, 3000);
	
	//slide right door
	$('div.wrap-hellevator div.frame div.wrap-door div.right-door').animate({
		marginRight: [(doorOffset * -1)+'px', 'easeInQuad']
	}, 3000, function(){
		animationCompelete();
	});	
		
}
/*************** /Door Open Functionality ***************/

function animationCompelete(){
	$('div.wrap-hellevator').css('display', 'none');
	var delay = setTimeout('rotation()', 300);
	
	showVideo();
}



