var Site = function() {
	
	var imgRatio; /* width/height */
	
	$background = $('#background img');
	
	function resetSizes(){
		windowWidth = $(window).width();
		windowHeight = $(window).height();
	}
	
	function scaleBackground(){
		if(imgRatio == null){
			imgRatio = $background.width() / $background.height();
		}
		var windowRatio = windowWidth/windowHeight;
		$background.css('height',Math.floor(windowWidth/imgRatio));
	}
		
	function resizeElements(trigger){
		resetSizes();
		scaleBackground();
	}

	function refigure(trigger){
		resizeElements(trigger);
		if($.browser.mozilla){
			setTimeout(function() {
				resizeElements(trigger);
			}, 50);
		}
	}	
	
	function init() {
		windowWidth = $(window).width();
		windowHeight = $(window).height();
		
		if($.browser.msie){
			$('#loader').append('<div class="loader_ani"></div>');
		}
		
		$(window).resize(function(){
			refigure('resize');
		});

		// Once initial background image is loaded, show content
		$('#background img').onImagesLoad({ selectorCallback: function(){
			$('#page_loader').hide();
			refigure();
			// loadBackgroundImage(i);
		}});		
		
	}
	
	// PUBLIC API
	return {
		init: init
	};
	
}();	
	
	
$(function() {
	Site.init();
});

// JW Player init callback
var jwPlayerInstance = null;
function playerReady(thePlayer) {
	jwPlayerInstance = document.getElementById(thePlayer.id);
	addJwPlayerListeners();	
}

function addJwPlayerListeners() {
	if (jwPlayerInstance) {
		jwPlayerInstance.addModelListener("STATE", "jwPlayerStateListener");
	} else {
		setTimeout("addJwPlayerListeners", 100);
	}
}

function jwPlayerStateListener(obj) {
	currentState = obj.newstate; 
	previousState = obj.oldstate; 

	var url = document.location.href;
	
	url = url.substring(0, url.indexOf('/', 9));

	if (currentState == "COMPLETED") {
		document.location.href=url + '/enter-site.php'; 
	}
}


