// JavaScript Document

$(document).ready(function(){	
	var leftHTML = $('#lgnContainer').html()+'';
	$(leftHTML).appendTo('#gridLeft');
	$('#gridRight #lgnContainer').remove();
	if($('#btmContents')){	
		var btmHTML = $('#btmContents').html()+'';
		$(btmHTML).appendTo('#pageFooter');
		}
	
	var footerImg="<p class='footerLogo'><a class='internal' target='_blank' href='https://smarticon.geotrust.com/smarticonprofile?Referer=http://www.aigbank.com'><img src='/BNK/internet/en/files/aigb_logo_geotrust_tcm1153-248385.gif' alt='GeoTrust' width='55' height='21' border='0'/></a><a target='_blank' href='http://www.fdic.gov/'><img src='/BNK/internet/en/files/aigb_logo_fdic_tcm1153-248384.gif' alt='FDIC Insured' width='47' height='21' border='0'/></a><a target='_blank' href='http://portal.hud.gov/portal/page/portal/HUD'><img src='/BNK/internet/en/files/aigb_logo_equalhousing_tcm1153-248383.gif' alt='Equal Housing Lender' width='29' height='21' border='0'/></a></p>"+'';
	$(footerImg).appendTo('#siteFooter');

	if($('#gridRight .rightModule').html()==null)
	//$('#gridCenter').css('padding-right','48px');
	$('#gridCenter').addClass("noRightcol");
	var bodyHTML ='<div id="bg"></div><div id="content"></div>';
	$(bodyHTML).prependTo('body');	
	$("div.adaptiveCol").insertAfter("#siteFooter");
	$('#gridRight a[href$="pdf"]').addClass('pdfIcon');
	
	$('a').each(function(){
		$(this).click(function(e){e.preventDefault();
			var links = $(this).attr('href');
			var linkClass = $(this).attr('class');
			var docDomain = "www.aigbank.com";
			//var stageDomain = "ebpstaging.aig.com";	
			var stageDomain = window.location.hostname;
			if(linkClass == 'internal' || linkClass == 'internal normal'){window.open(links);return true;}
			if(linkClass.search('popWin') != '-1'){
				writeCookie('popPDF',$(this).attr('href'));
				window.open("/pdfpopup_1153_252876.html",'newWinow','location=0,status=0,scrollbars=0,resizable=1,width=540,height=275');
				return false
			}
			if(linkClass.search('newWin') != '-1'){
				writeCookie('outPDF',$(this).attr('href'));
				window.open("/pageRedirect_1153_252895.html");
				return false
			}	

			if(links.search('http') == '0'){
				var linkDomain = links.match(/:\/\/(.[^/]+)/)[1];
				if(linkDomain.search('ebp') != "-1"){docDomain = stageDomain;};
				if(linkDomain != docDomain){
					writeCookie('outLink',$(this).attr('href'));
					window.open("/pageRedirect_1153_251886.html");
					return false;
				}
				else{
					window.location.href = links;return true;
					}
			}
			if(links.search('http') == '-1'){window.location.href = links;return true;};
		})
	})
	$('<div id="gridCWrap2"></div>').insertBefore('#pageFooter');
	//$('#gridCenter').append('<div id="gridCWrap2"></div>');
	$('#gridCenter').prepend('<div id="gridCWrap1"></div>');
	if($('#appletgrid').length !=0){
		//$('#gridCenter').css('background','none');		
		$('#pageTitle').insertBefore('#appletgrid');
		$('.centerModule').addClass('calcApps');
		}
	/*else{
		$('#gridCenter').wrap('<div id="gcFtr" />');
		$('#gridCenter').wrap('<div id="gcHdr" />');
		}*/
   $('#gridCenter a').children("img").parent().addClass("normal");	
   $('#gridRight a').children("img").parent().addClass("normal");
});

function showDiv(url){
	$('#bg').show().css('opacity',0).fadeTo('slow', 0.4); 
	$('#content').show();
	resize();
	$('#content').load(url);
}
function hideDiv(){
	$('#bg').hide(); 
	document.getElementById('content').innerHTML='';
	$('#content').hide();	
}
function resize(){
	if($('#bg').css('display')=='block')
	{
		var bgHght=Math.max($('#body_wrapper').height(), $(document).height())+13+'px';
		$('#bg').css('height',bgHght);
	}
}