$(document).ready(function() {
	var windowX;
	var windowY;
	var newContainerWidth;
	var newContentWidth;
	var newImageWidth;
	var newFooterWidth;
	var newH1Width;
	var newWideTitleWidth;
	var preContainerWidth;
	
	$(window).bind("resize", resizeFrame);
	$(window).bind("load", setFrame);

	function resizeFrame(e){
		checkSize();
	};
	
	function setFrame(e){
		checkSize();
		setDivs();
	};

	function checkSize() {
		windowY = $(window).height();
		windowX = $(window).width();
		if(windowX > 1240) {
			newImageWidth = (1240 / 2) - 26;
			newFooterWidth = 1240 - 26;
			newContentWidth = 1240 / 2;
			newH1Width = (1240 / 2) - 5;
			newContainerWidth = 1240;
			newWideTitleWidth = 1240 - 70;
		} else if(windowX < 960) {
			newImageWidth = (960 / 2) - 26;
			newFooterWidth = 960 - 26;
			newContentWidth = 960 / 2;
			newH1Width = (960 / 2) - 5;
			newContainerWidth = 960;
			newWideTitleWidth = 960 - 70;
		} else {
			newImageWidth = (windowX / 2) - 26;
			newFooterWidth = windowX - 26;
			newContentWidth = windowX / 2;
			newH1Width = (windowX / 2) - 5;
			newContainerWidth = windowX;
			newWideTitleWidth = windowX - 70;
		}
		
		if(newContainerWidth > preContainerWidth) {
			changeCont();
			setTimeout(animateDivs,80);
		} else if (newContainerWidth < preContainerWidth) {
			setTimeout(changeCont,80);
			animateDivs();
		}
		
		preContainerWidth = newContainerWidth;
	};
	
	function animateDivs() {
		$('#content').stop().animate({'width':newContentWidth + 'px'});
		if (pageId!="contact-us") { 
			$('#image').stop().animate({'width':newImageWidth + 'px'});
		};
		$('h1').stop().animate({'width':newH1Width + 'px'});
		$('#widetitle').stop().animate({'width':newWideTitleWidth + 'px'});
		$('.text-area').stop().animate({'width':(newH1Width - 26) + 'px'});
		$('h2').stop().animate({'width':'100%'});
		$('#footer').stop().animate({'width':newFooterWidth + 'px'});
	};
	
	function changeCont() {
		$('#container').stop().animate({'width':newContainerWidth + 'px'});
	};
	
	function setDivs() {
		$('#container').css({'width':newContainerWidth + 'px'});
		$('#content').css({'width':newContentWidth + 'px'});
		if (pageId!="contact-us") { 
			$('#image').css({'width':newImageWidth + 'px'});
		};
		$('h1').css({'width':newH1Width + 'px'});
		$('#widetitle').css({'width':newWideTitleWidth + 'px'});
		$('.text-area').css({'width':(newH1Width - 26) + 'px'});
		$('h2').css({'width':'100%'});
		$('#footer').css({'width':newFooterWidth + 'px'});
	};
});


