$(document).ready(function(){
	// resize the background
	$(window).wresize( function(){  	   
		resizeBackground();
	});
	loadswf();
	
	resizeBackground();
	$(document).pngFix();	
	
	if ($('#preloader_wrapper').length == 0)
	{
		$("#flash_sound_wrapper").show();
		reloadswf();
	}
		
	
});

function reloadswf() {
	resizeBackground();
}
function afterFooterLoaded() {
	resizeBackground();
}
function closeswf()
{
	if($('#preloader_wrapper'))
	{
		$('#preloader_wrapper').remove();
		$("#flash_sound_wrapper").show();
		reloadswf();
	}
}
function deletebackground()
{
	if($('#preloader_wrapper'))
	{
		$('#preloader_wrapper').css('background','none');
	}
}
function resizeBackground()
{
	setViewPort();
	reposFooter();
	
	var offsetHeight = $('#area_footer').height() + $('#top-container').height();
	var minHeight = 595 - offsetHeight; // set this automatically from the image ratio
	var minWidth  = vpWidth;
	
	// resize container
	var bgHeight = vpHeight - offsetHeight;
	var cHeight = (bgHeight < minHeight) ? minHeight : bgHeight ;
	var cWidth = (vpWidth < minWidth) ? minWidth : vpWidth;	
		
	$('#resizeable-container').css('height',cHeight + 'px');
	$('#resizeable-container').css('width', cWidth + 'px');
	
	// resize top filler
	$('#top-container img').css('width', cWidth + 'px');
		
	// resize background
	$('#resizeable-background').css('height', cHeight + 'px');
	$('#resizeable-background img').css('height', cHeight + 'px');
	
	$('#resizeable-container #imgwrapper').css('height',cHeight);
	$('#resizeable-container #imgwrapper').css('width',$('#resizeable-image').width());
	
	
	var imgX = 2053;
	var imgY = 900;
	var imgWidth = cHeight/imgY * imgX;
	$('#resizeable-container #imgwrapper').css('width',imgWidth);
	$('#resizeable-image').css('width', imgWidth);
	
	
	if(imgWidth > cWidth)
	{
		//var margin = (imgWidth - cWidth) / 2;
		//alert(cWidth);
		//$('html').css('overflow-x', 'hidden');
		//$('#resizeable-container #imgwrapper').css('margin-right', '-' + margin + 'px');
	}
	
	var left = cWidth/2 - imgWidth/2;
	left = (imgWidth < cWidth) ? 0 : left;
	$('#resizeable-background').css('left', left + 'px');
	
	// resize left-right filler
	var fillerWidth = (imgWidth < cWidth) ? (cWidth-imgWidth)/2 : 0;
	fillerwidth = Math.round(fillerWidth);
	$('#resizeable-left').css('width', fillerWidth + 'px');
	$('#resizeable-left img').css('width', fillerWidth + 'px');
	$('#resizeable-left img').css('height', cHeight + 'px');
	
	$('#resizeable-right').css('width', fillerWidth  + 'px');
	$('#resizeable-right img').css('width', fillerWidth+2  + 'px'); 
	$('#resizeable-right img').css('height', cHeight + 'px');
	

	// repos payoff
	var pTop = vpHeight/5 - 25;
	var pLeft = vpWidth/6 - 100;
	$('#text-payoff').css('top', pTop);
	$('#text-payoff').css('left', pLeft);
	
	// repos ATA
	var pTop = cHeight/4 - 15;
	var pLeft = (cWidth * 7/9) ;
	$('#ata-box').css('top', pTop);
	$('#ata-box').css('left', pLeft);

	// TEST 
	$('#resizeable-background').css('left', '0px');
	$('#resizeable-background').css('width', '100%');
	$('#resizeable-container').css('width', '100%');
	$('#resizeable-container').css('height', '100%');
	$('#resizeable-container #imgwrapper').css('width','100%');
	$('#resizeable-container #imgwrapper').css('height','100%');
	$('#resizeable-image').css('width', '100%');
	$('#resizeable-image').css('height', '100%');
	
}
