jQuery(document).ready(function($){
	// fix header search button to remove x/y params from search urls
	var offset = Math.round(($('#headersearch').height() - $('#headersearch .search-field').outerHeight()) / 2);
	$('#headersearch .search-field').css({'margin-top': offset+'px', 'float':'left'});
	$('#headersearch .search-submit').replaceWith('<a href="#" class="search-submit"></a>');
	$('#headersearch a.search-submit').click(function(){
		$('#headersearch').submit();
		return false;
	});
	// search toggle
	$('#headersearch .search-field').toggleVal({'populateFrom':'custom','text':'Search Zola'});
	// quick fix on navigation spacing issue for IE
	$('.navigation').each(function(){
		if ($.trim($(this).text()) == '') $(this).hide();
	});
	
	
	var $window = $(window).width();
	var $mcHeight = $('#maincontent').height();
	var $windowHeight = $(window).height();
	var $document = $(document).height();
	var $position = $(document).find('#container').offset();
	var $left = ($position.left - 94) + 'px';
	var $right = ($position.left + 956) + 'px';
	var $bounds = jQuery('#container').width() + ((jQuery('#gutter-left').width() + jQuery('#border-left').width() - 18)*2);
	if($window < $bounds){
		jQuery('#border-left').css('left', $left);
		jQuery('#border-right').css('left', $right);
	}
	if($window > $bounds){
			jQuery('#border-right').css('left', '');
		}
	
	
	if(($mcHeight + $('#header').height()) < $windowHeight){
		//alert('mc');
		$('#maincontent').height($windowHeight - $('#header').height());
	}
	
	/*
var $that = "width: " + $(window).width() + " height " + $(window).height();
	alert($that);
*/ 
});

jQuery(document).ready(function($) {

	//window resize
	jQuery(window).resize(function($) {
	
		var $contentHeight = jQuery('#footer').outerHeight() + jQuery('#footer').offset().top;
		var $window = jQuery(window).width();
		var $document = jQuery(document).height();
		var $windowHeight = jQuery(window).height();
		var $mcHeight = jQuery('#maincontent').height();
		jQuery('.sidebars').height($document);
		var $position = jQuery(document).find('#container').offset();
		var $left = ($position.left - 94) + 'px';
		var $right = ($position.left + 956) + 'px';
		var $bounds = jQuery('#container').width() + ((jQuery('#gutter-left').width() + jQuery('#border-left').width() - 18)*2);
		if($window < $bounds){
			jQuery('#border-left').css('left', $left);
			jQuery('#border-right').css('left', $right);
		}
		if($window > $bounds){
			jQuery('#border-right').css('left', '');
		}
		
		if(($mcHeight + jQuery('#header').height()) < $windowHeight){
			jQuery('#maincontent').height($windowHeight - jQuery('#header').height());
		}
		
			jQuery('#maincontainer').height($windowHeight);
		
		if( $windowHeight > $contentHeight ) {
			jQuery('#maincontent').height($windowHeight - jQuery('#header').height());
		}
	});
	
	
	
	
});

window.setInterval(setSidebars, 1000);

function setSidebars() {
	var $positionX = jQuery('#maincontent').height() + jQuery('#header').height();
	jQuery('.sidebars').height($positionX);
		
		
}
