var lengthened = false;
function extend() {
	$("#texture-overlay").height($(document).height());
	$("#bottom").height($(document).height()-188);
	widen();
	bottom_rebuild();
}
function widen() {
	$("#background").width($(document).width());
	$("#texture-overlay").width($(document).width());
	$("#top-stripe").width($(document).width());
	$("#bottom-stripe").width($(document).width());	
	$("#footer-color").width($(document).width());		
	$("#footer-gradient").width($(document).width());
	center_ex();		
}
function bottom_cut () {
	if($(window).height()<1345) {	
		$("#footer-pattern").css({height: "184px"});
		$("#footer-pattern-image").css({height: "184px"});
		$("#footer-color").css({height: "184px"});
		$("#texture-overlay").css({height: "1345px"});
		$("#background").css({height: "1345px"});
		$("#bottom").css({height: "1157px"});
		if(expanded) {
			$("#bottom").css({height: $("#bottom").height() + 76 + "px"});
		}
		if(lengthened){
			$("#texture-overlay").css({height: $("#texture-overlay").height() + length + "px"});
			$("#bottom").css({height: $("#bottom").height() + length + "px"});
			$("#background").css({height: $("#background").height() + length + "px"});
		}
	}
}
function bottom_rebuild () {
		$("#footer-pattern").css({height: "339px"});
		$("#footer-pattern-image").css({height: "339px"});
		$("#footer-color").css({height: "340px"});
		$("#background").css({height: "1500px"});
		bottom_cut ();
}
function windowCheck() {
	if($(window).width()<1520) {
		widen();		
	} else {		
		center_ex();
	}		
}
function center(div) {
	var left = ($(window).width() - $(div).outerWidth()) / 2;
    $(div).css({position:'absolute', margin:0,	 left: (left > 0 ? left : 0)+'px'});
}
function center_wide(div) {
	var left = ($(window).width() - $(div).outerWidth()) / 2;
    $(div).css({position:'absolute', margin:0,	 left: (left)+'px'});
}
function center_ex () {
	center("#main-bar");
	center_wide("#footer-pattern");
	center_wide("#top-stripe-pattern");
	if($(window).width() < 1374){
		$("#top-stripe-pattern-image").width($(window).width() + ((1374 - $(window).width())*.5));
	} else {
		$("#top-stripe-pattern-image").width(1374);
	}
	if($(window).width() < 1182){
		$("#footer-pattern-image").width($(window).width() + ((1182 - $(window).width())*.5));
	} else {
		$("#footer-pattern-image").width(1182);
	}
	if($(window).width() < 1000) {
		$(".center-gradient").css({left:'87.5px'});
	} else {
		center("#top");
		center("#bottom");
	}
}
function hideDropdown() {
	$('#dropdown').hide();
}
$(document).ready(hideDropdown());
$(document).ready(extend());
$(document).ready(windowCheck());
$(document).ready(bottom_cut());
var resizeTimer;
$(window).resize(function() {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(extend, 100);
});
