/* 
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':500,
			'max':1050,
			'screen':$(window).height(),
			'content':$('#content').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');
		}

		if(height.screen > height.min && height.screen < height.max){
			$('#container').css('height', height.screen+'px');
			$('#content').css('top', (height.screen-height.content)/2+'px')
		}
		// minimum height
		else if(height.screen <= height.min){
			$('#container').css('height', height.min+'px');
			$('#content').css('top', '0')
		}
		// maximum height
		else {
			$('#container').css('height', height.max+'px');
			$('#content').css('top', (height.max-height.content)/2+'px')
		}

	}
}

LinkHandler = {
	rewriteLinksExternal: function() {
		$('a.external').bind('click', function (e) {
			$(this).attr('target', '_blank');
		});
	}
}


$(document).ready(function(){
	Container.adjust();
	LinkHandler.rewriteLinksExternal();
	$(window).bind('resize', Container.adjust);
	$("#content").fadeIn("normal");
});