// JavaScript Document

var optionBgResize =0;
var optionBgChooser =1;


	function bg(){
	if(optionBgChooser == 1){	
		chooseBg();
	}

	function chooseBg() {
		randomNum = Math.floor((Math.random() * bgPic.length));
		document.getElementById("bgImg").src = bgPic[randomNum];
	}


	if(optionBgResize == 1){ 
	document.getElementById('bgImg').onload = bgResize; 
	}
	
	function bgResize() {
			// The current aspect ratio of the window
		var browserHeight, browserWidth;
		window.innerHeight ?( browserHeight = window.innerHeight) : (browserHeight = document.body.offsetHeight);
		window.innerWidth ? (browserWidth = window.innerWidth) : (browserWidth = document.body.offsetWidth);
		
//		alert(browserHeight +" || "+ browserWidth);

		var winAR = browserWidth / browserHeight;
		var imgRatio = document.getElementById("bgImg").width / document.getElementById("bgImg").height;
		if (winAR >= imgRatio){
			document.getElementById("bgContainer").className = "wide";
			var imgHeight = document.getElementById("bgImg").height;
			var topM = -((imgHeight - browserHeight)/2);
			document.getElementById("bgImg").style.margin=topM + "px 0px 0px 0px";
		}
		
		else if (winAR < imgRatio){
			document.getElementById("bgContainer").className = "tall";
			var imgWidth = document.getElementById("bgImg").width;
			var leftM = -((imgWidth - browserWidth)/2);
			document.getElementById("bgImg").style.margin= "0px 0px 0px " + leftM + "px";
		}
	window.onresize = bgResize;
	}
};