var jsr = false;

$(document).ready(function() {
	//$.fn.fullscreenr({ width: 2847, height: 1944, bgID: '#bg-img' });
	$.fn.fullscreenr({ width: 1700, height: 1275, bgID: '#bg-img' });
	
	initMenu();
});

var tMenu, menuHideDelay = 300;

function initMenu() {
	$("div#menu > ul > li > a:first-child").hover(function() {
		hideAllMenus();
	
		$(this).addClass('active');
		if ($(this).next('ul').css('display') != 'block') $(this).next('ul').fadeIn('fast');
		
		$(this).next('ul').hover(function() {
			clearTimeout(tMenu);
		}, function() {
			clearTimeout(tMenu);
			tMenu = setTimeout(hideAllMenus, menuHideDelay);
		});
	}, function() {
		clearTimeout(tMenu);
		tMenu = setTimeout(hideAllMenus, menuHideDelay);
	});
	
	jsr = true;
}

function hideAllMenus() {
	clearTimeout(tMenu);
	
	$("div#menu > ul > li > a:first-child").each(function(index) {
		if ($(this).hasClass('active')) {
			$(this).removeClass('active');
			$(this).next('ul').fadeOut('fast');
		}
	});
}

function isReady() {
	return jsr;
}

function updateBackground() {
	$("img#bg-img").delay(2000).fadeOut('slow', function() {
		$("img#bg-img").attr('src', 'assets/images/background.jpg').fadeIn('slow');
	});
}
