$(document).ready(function() {
	showBg();
});

var viewportWidth;
var viewportHeight;

if (typeof window.innerWidth != 'undefined') {
	viewportWidth = window.innerWidth;
	viewportHeight = window.innerHeight;
} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
	viewportWidth = document.documentElement.clientWidth;
	viewportHeight = document.documentElement.clientHeight;
} else {
	viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
	viewportHeight = document.getElementsByTagName('body')[0].clientHeight
}

function showBg() {
	//Position the pm_logo in the vertical center
	$("#pm_logo").css("top",((viewportHeight/2)-(44/2)));

	//Force the size of the bg_img to match the browser width
	$("#bg_img").css("width",viewportWidth);

	//Set the src of the background img
	var randNum = Math.floor(Math.random()*8)+1;
	$("#bg_img").attr("src","img/bg/splash/"+randNum+".jpg");

	$("#pm_logo").fadeIn(500);

	//When image is fully loaded,reveal the background image
	$("#bg_img").load(function() {
		$("#bg_img").fadeIn(3000);
	});
}
