/*
 * Copyright 2011 1fb.net Financial Services. This document may not be reproduced, distributed or used in any manner
 * whatsoever without the expressed written permission of 1st Financial Bank USA.
 */

/**
 * @fileOverview Align the horizontal scroll bar to show the bank ads.
 * 
 * @author Rokgy Luo 
 * @version 1.0, 2011-10-18
 * @since 7.05
 */

$j(document).ready(function(){
	alignScrollBar();
}); 

/**
 * The method focus on the low resolution scenario, Or the scenario when browser window width is narrower than core page content
 * The method shows and move the horizontal scroll bar to proper position after page loaded, in order to always show the left bank ads
 * The method calculate and set minimal width for Blue and Gray header bar, in order to make the header bar always stretch full screen
 * The method calculate and set margin left space, in order to align page into center with horizontal scroll bar
 */
var alignScrollBar = function()
{ 
	var iMove = document.documentElement.scrollWidth-document.body.offsetWidth;
	if(iMove>0){
		var screenWidth = $j(window).width();
		var rightGutterWidth;
		var adjustWidth;
		//Adjusted width for solving vertical scroll space at most right of the screen
		var cutoffAdjustWidth = 22;
		var corePageWidth = $j(".main_wrap").width();
		
		//Adjusted width for reserving space of left bank advertisement
		var leftAdWidth = 206;
		var rightGutterWidth = (screenWidth - corePageWidth)/2;
		
		if(screenWidth < corePageWidth){
			adjustWidth = cutoffAdjustWidth - rightGutterWidth + leftAdWidth + corePageWidth;
		}
		else{
			adjustWidth = cutoffAdjustWidth + rightGutterWidth + leftAdWidth + corePageWidth;
		}
		var scrollMoveWidth = leftAdWidth - rightGutterWidth;
		$j(".scroll_wrap").css({"width": adjustWidth });
		$j(".gray_bar").css({"min-width": adjustWidth });
		$j(".blue_bar").css({"min-width": adjustWidth });
		$j(".main_wrap").css({"margin-left": leftAdWidth});
		$j(".head").css({"margin-left": leftAdWidth});
		$j(".ads_top").css({"margin-left": leftAdWidth});
		$j(".foot").css({"margin-left": leftAdWidth});
		$j(".scorllwidth").css({ "width": adjustWidth }); 
		window.scrollTo(scrollMoveWidth,0);
	}
};
