var resizeTimer = null;

$(document).ready(function()
{
	processBGimage();
});

window.load = function ()
{
	processBGimage();
}

$(window).bind('resize', function()
{
    if (resizeTimer)
    	clearTimeout(resizeTimer);
    resizeTimer = setTimeout(processBGimage, 100);
});

$(window).resize(function() {
	processBGimage();
});

function processBGimage()
{
	var winwidth = $(window).width();
	var winheight = $(window).height();
	
	var imgwidth = $('#fullBG').width();
	var imgheight = $('#fullBG').height();
	
	// if any case, image can't come with width and height
	if(imgwidth == 0 || imgheight == 0)
	{
		$('#fullBG').css({
			width: winwidth + 'px',
			height: winheight + 'px'
		});    	
	
		imgwidth = $('#fullBG').width();
		imgheight = $('#fullBG').height();    	
	}
	
	var widthratio = (winwidth / imgwidth);
	var heightratio = (winheight / imgheight);
	
	var widthdiff = (heightratio * imgwidth);
	var heightdiff = (widthratio * imgheight);
	
	if(heightdiff>winheight) 
	{
		$('#fullBG').css({
			width: winwidth + 'px',
			height: heightdiff + 'px'
		});
	} 
	else 
	{
		$('#fullBG').css({
			width: widthdiff + 'px',
			height: winheight + 'px'
		});		
	}
}
