/**
 * JavaScript functions for OATShoes.com
 */

// run after page loads
jQuery(document).ready( function() {
	// adjust the menu display method
	setFixedMenu();
	
	// adjust columns heights
	adjust_columns_delayed();	
});

// checks if the sidebar is fully visible and if yes, sets it to fixed position
function setFixedMenu() {
	
	// do this only if window width is wider than 900px - otherwise the content goes over the fixed menu
	var win_width = jQuery(window).width();
	
	// get the sidebar height
	var win_height = jQuery(window).height();
	var sidebar_height = jQuery('#sidebar').height();
	if ( (sidebar_height+163) < win_height && ( win_width > 1000 )) {
		// set sidebar fixed
		jQuery('#sidebar').css('position','fixed');
	} else {
		// sidebar bigger than window - set scrolling
		jQuery('#sidebar').css( { 'position':'absolute' , 'z-index':'10' } );
	}
}

function adjust_columns() {
	// set mingheight - either height of win or left sidebar, depends what is bigger
	var win_height = jQuery(window).height();
	var menu_height = jQuery('ul#menu').height() + 549;
	if ( menu_height > win_height ) {
		var min_height = menu_height;
	} else {
		var min_height = win_height;
	}

	// right column
	var right_col_height = jQuery('#right_column').height();
	if (right_col_height < (min_height - 160)) {
		jQuery('#right_column').css('height',min_height-160 );
	} 

	// middle column
	var gray_col_height = jQuery('#gray_column').height();
	if (gray_col_height < (min_height - 160)) {
		jQuery('#gray_column').css('height',min_height-160 );
	} 

	// big column
	var big_col_height = jQuery('#main.bg').height();
	if (big_col_height < (min_height - 210)) {
		jQuery('#main.bg').css('height',min_height-210 );
	}				
}

// with little delay - need to wait for gallery images in IE
function adjust_columns_delayed() {
	jQuery('#right_column').css('height','auto');
	jQuery('#gray_column').css('height','auto');
	jQuery('#main.bg').css('height','auto');
	
	setTimeout("adjust_columns()",300);		
}




//If the User resizes the window, adjust the #container height
jQuery(window).bind("resize", setFixedMenu);
//.. and resize columns
jQuery(window).bind("resize", adjust_columns_delayed);
