var backgroundImageObject = null;
var backgroundDivObject = null;

function backgroundInit()
{
	backgroundImageObject = $("#background-image");
	backgroundDivObject = $("#web-parent-background");
	backgroundComprobarDimensionesDivPrincipal();
}

var backgroundAnchoDivPrincipal = 0;
var backgroundAltoDivPrincipal = 0;	


function backgroundComprobarDimensionesDivPrincipal()
{
	var nuevoAncho = 0;
	var nuevoAlto = 0;

	nuevoAncho = $('#web-parent')[0].offsetWidth;
	nuevoAlto = $('#web-parent')[0].offsetHeight;

	if(backgroundAnchoDivPrincipal != nuevoAncho || backgroundAltoDivPrincipal != nuevoAlto)
	{
		backgroundAnchoDivPrincipal = nuevoAncho;
		backgroundAltoDivPrincipal = nuevoAlto;
		
		var altoImagen;
		var anchoImagen;
			
		if(backgroundAnchoDivPrincipal * backgroundImageHeight / backgroundImageWidth > backgroundAltoDivPrincipal)
		{
			altoImagen = backgroundAnchoDivPrincipal * backgroundImageHeight / backgroundImageWidth;
			anchoImagen = backgroundAnchoDivPrincipal;
		}
		else
		{
			anchoImagen = backgroundAltoDivPrincipal * backgroundImageWidth / backgroundImageHeight;
			altoImagen = backgroundAltoDivPrincipal;
		}

		backgroundImageObject.css('height', altoImagen);
		backgroundImageObject.css('width', anchoImagen);

		backgroundImageObject.css('left', -(anchoImagen - backgroundAnchoDivPrincipal) / 2 );
		backgroundImageObject.css('top', -(altoImagen - backgroundAltoDivPrincipal) / 2 );

		backgroundDivObject.css('height', altoImagen);
		backgroundDivObject.css('top', -(altoImagen - backgroundAltoDivPrincipal) / 2 );
	}
	
	setTimeout('backgroundComprobarDimensionesDivPrincipal()',500);
}
