function setBackground()
{
	var BGImage = new Image();
	BGImage.src = document.getElementById('backgroundimage').src;
	var picheight = BGImage.height;
	var picwidth = BGImage.width;

	var browwidth = 0, browheight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    browwidth = window.innerWidth;
	    browheight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    browwidth = document.documentElement.clientWidth;
	    browheight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    browwidth = document.body.clientWidth;
	    browheight = document.body.clientHeight;
	  }

	var posx = 0, posy=0;

	// if picture is bigger then the entire browser
	if(picwidth>browwidth && picheight>browheight)
	{
                var widthratio = picwidth/browwidth;
		var heightratio = picheight/browheight;

		// if width is bigger
		if(widthratio > heightratio)
		{
			var newwidth= picwidth/heightratio;
			var newheight = picheight/heightratio;

			posy = 0;
			posx = (newwidth-browwidth)/2;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;

		}

		// if height is bigger
		if(widthratio < heightratio)
		{
			var newwidth= picwidth/widthratio ;
			var newheight = picheight/widthratio ;

			posy = (newheight-browheight)/2;
			posx = 0;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;
		}

		// if ratio equel
		if (widthratio == heightratio)
		{
			var newwidth= picwidth/widthratio;
			var newheight = picheight/widthratio;

			posy = 0;
			posx = 0;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;
		}
	}

	// if picture is smaller then the entire browser
	if(picwidth<browwidth && picheight<browheight)
	{
		var widthratio = browwidth/picwidth;
		var heightratio = browheight/picheight;

		// if width is bigger
		if(widthratio > heightratio)
		{
			var newwidth= picwidth*widthratio;
			var newheight = picheight*widthratio;

			posy = (newheight-browheight)/2;
			posx = 0;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;

		}

		// if height is bigger
		if(widthratio < heightratio)
		{
			var newwidth= picwidth*heightratio;
			var newheight = picheight*heightratio;

			posy = 0;
			posx = (newwidth-browwidth)/2;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;
		}

		// if ratio equel
		if (widthratio == heightratio)
		{
			var newwidth= picwidth*widthratio;
			var newheight = picheight*widthratio;

			posy = 0;
			posx = 0;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = newheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;
		}
	}

	// if browserheight is smaller then the pictureheight but the browserwidth is bigger then the picturewidth
	if(picheight>browheight && picwidth<browwidth)
	{
		var widthratio = browwidth/picwidth;
		var newheight = picheight * widthratio;

		posy = (newheight-browheight)/2;
		posx = 0;

		document.getElementById('backgroundimage').style.width = browwidth;
		document.getElementById('backgroundimage').style.height = newheight;
		document.getElementById('backgroundimage').style.left = -posx;
		document.getElementById('backgroundimage').style.top = -posy;
	}

	// if browserwidth is smaller then the picturewidth but the browserheight is bigger then the pictureheight
	if(picheight<browheight && picwidth>browwidth)
	{
			var heightratio = browheight/picheight;
			var newwidth = picwidth * heightratio;

			posx = (newwidth-browwidth)/2;
			posy = 0;

			document.getElementById('backgroundimage').style.width = newwidth;
			document.getElementById('backgroundimage').style.height = browheight;
			document.getElementById('backgroundimage').style.left = -posx;
			document.getElementById('backgroundimage').style.top = -posy;
	}

}
