/* 
Budweiser.com Container Controller JavaScript file 
Used for sizing and positioning of containers on the screen.
*/

Container = {
	adjust:function(){
		// width definitions
		var width = {
			'min':1024,
			'max':1680,
			'screen':$(window).width()
		};
		// height definitions
		var height = {
			'min':608,
			'max':1024,
			'screen':$(window).height(),
			'content':$('#content').height(),
			'contentCon':$('#content-container').height(),
			'headFoot':$('#header-container').height() + $('#footer-container').height()
		}
		// middle width
		if(width.screen > width.min && width.screen < width.max){
			$('#container').css('width', '100%');
			$('#content').css('left', (width.screen-width.min)/2+'px');
		}
		// minimum width
		else if(width.screen <= width.min){
			$('#container').css('width', width.min+'px');
			$('#content').css('left', '0');
		}
		// maximum width
		else {
			$('#container').css('width', width.max+'px');
			$('#content').css('left', (width.max-width.min)/2+'px');
		}
		// pages that have default layout, adjust height and vertical centering
		if($('#content-container').hasClass('default')){
			// middle height
			if(height.screen > height.min && height.screen < height.max){
				$('#container').css('height', height.screen+'px');
				$('#content-container').css('height', height.screen-height.headFoot+'px');
				$('#content').css('top', ((height.screen-height.headFoot)-height.content)/2+'px')
			}
			// minimum height
			else if(height.screen <= height.min){
				$('#container').css('height', height.min+'px');
				$('#content-container').css('height', height.min-height.headFoot+'px');
				$('#content').css('top', '0')
			}
			// maximum height
			else {
				$('#container').css('height', height.max+'px');
				$('#content-container').css('height', height.max-height.headFoot+'px');
				$('#content').css('top', ((height.max-height.headFoot)-height.content)/2+'px')
			}
		}
		else{
			if(height.screen > (height.contentCon+height.headFoot)){
				$('#container').css('height', height.screen+'px');
				$('#content-container').css('height', height.screen-height.headFoot+'px');
			}
		}
		
		if($('#arrow-container').length>0){
			$('#arrow-container').css('top', (($("body").height()/2)-$("#arrow-container .left").height()-60)+'px');
		}
	}
}

$(document).ready(function() {
	if(!$('#content-container').hasClass('no-resize')){
		Container.adjust();
		$(window).bind('resize', Container.adjust);
	}
    if ($.browser.msie) {
        $(window).bind('resize', Flash.fixResizing);
    }
    //Width Fix for flash top Navegation
    $("div#header-container").css("width", "100%");
    //Tittle align fixes
    $("#our-beer-intro #copy h2").css("margin-left", "68px");
    $("#our-legacy-intro #copy h2").css("margin-left", "35px");
});