/*global*/
var scrolling = 0;

function updatePageLayout() 
{
	var s_left_col_div = document.getElementById('s_left_col');
	var s_sub_nav_div = document.getElementById('s_sub_nav');
	var scrollButtonsInside = document.getElementById('s_scroll_arrows_inside');
	var x,y;
	var added_right_col = document.getElementById('s_added_right_col');
	var small_screen_content = document.getElementById('s_small_screen_content');
	var loggin_information = document.getElementById('s_login_info');
	var thefooter = document.getElementById('s_bottom_front');
	var thehead = document.getElementById('s_top_front');
	
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	/* RESIZE */
	if ( x < 735 ) {
		if (small_screen_content.innerHTML == '') small_screen_content.innerHTML = added_right_col.innerHTML;
		added_right_col.style.display = 'none';
		small_screen_content.style.display = 'block';
		thehead.style.width = thefooter.style.width = (x-18)+'px';
		loggin_information.style.display = 'none';
	}
	else if ( x < 905 ) { /* 875px + 30px margin */
		if (small_screen_content.innerHTML == '') small_screen_content.innerHTML = added_right_col.innerHTML;
		added_right_col.style.display = 'none';
		small_screen_content.style.display = 'block';
		small_screen_content.style.width = '310px';
		thehead.style.width = thefooter.style.width = '735px';
		loggin_information.style.display = 'block';
	} else { /* large screen */
		added_right_col.style.display = 'block';
		small_screen_content.style.display = 'none';
		thehead.style.width = '735px';
		thefooter.style.width = '875px';
		small_screen_content.style.width = '110px'; /* the width of the added right column */
		loggin_information.style.display = 'block';
	}	
	
	/* add scrolling if needed */
	s_left_col_div.style.height = 'auto';
	document.getElementById('s_extra_nav_padding').style.display='none';
	if ( y-145 < 15+s_left_col_div.clientHeight ) {
		scrollButtonsInside.style.display = 'block';
		s_left_col_div.style.height = (y-160)+'px';
		document.getElementById('s_extra_nav_padding').style.display='block';
	} else {
		scrollButtonsInside.style.display = 'none';
	}
	
}

/* SCROLLING */
function scrollContent(upordown ) {
	if (scrolling == 1) {
		objDiv = document.getElementById("s_left_col");
		divHeight = objDiv.clientHeight;
		if ( (objDiv.scrollTop+divHeight < objDiv.scrollHeight && upordown == 1) || (objDiv.scrollTop > 0 && upordown == -1) ) {
			objDiv.scrollTop = objDiv.scrollTop + upordown;
			setTimeout('scrollContent('+(upordown).toString()+','+divHeight.toString()+')',5);
		} else {
			scrolling = 0;
		}
	}
}
function scrollContentUp() {
	scrolling = 1; scrollContent(-1);
}
function scrollContentDown() { 
	scrolling = 1; scrollContent(1);
}
function scrollToTop() {
	var s_left_col_div = document.getElementById('s_left_col');
	scrolling = 0;
	s_left_col_div.scrollTop = 0;
}
function scrollToBottom() {
	var s_left_col_div = document.getElementById('s_left_col');	
	scrolling = 0;
	s_left_col_div.scrollTop = s_left_col_div.scrollHeight;
}
function stopScrolling() {	scrolling = 0; }

window.onresize = function() { scrollToTop(); updatePageLayout(); }
window.onload = function() { updatePageLayout(); }
window.onpageshow = function (evt) {
	if (evt.persisted) window.onload();
}