$(document).ready(function(){
	opacityLayer.init();
});

opacityLayer = function(){
	var o = {};
	function init(){
		buildMask();
		runTicker();
	}
	function buildMask(){
		$('body').prepend('<div id="Mask"></div>');
		o.mask = $('#Mask');
		o.mask.css({height: $(document).height(), width: '100%', background: '#FFFFFF', position: 'absolute', zIndex: '0', top: '0', left: '0',display: 'none'});
	}
	function runTicker(){
		var int = window.setInterval(function(){ resizer(); }, 100);
		function resizer(){
			var newHeight = $(document).height();
			o.mask.css({ height: newHeight });
		}
	}
	function backgroundStageOne(id){
		if(id === undefined) { id = 1; }
		o.productID = id;
		o.mask.animate({opacity: 'show'}, 500, function() {																							
			backgroundStageTwo();
		});
	}
	function backgroundStageTwo(){
		$('body').css('background', imagePath());
		backgroundStageThree();
	}
	function backgroundStageThree(){
		o.mask.animate({opacity: 'hide'}, 1000);
	}
	function imagePath(){
		var path = "url(../img/backgrounds/" + o.productID + ".jpg) scroll center top no-repeat";
		return path;
	}
	return { init: init, changeBackground: backgroundStageOne }
}();

