

$(function() {

	$(".menu li").hover(function() {
				$(this).addClass('ui-selecting')
			}, function() {
				$(this).removeClass('ui-selecting')
			})
	
	$(".menu li").click(function() {
		$(this).addClass("ui-selected").siblings()
				.removeClass("ui-selected");
		
		before_load_content()
		$('.target').attr('rel', $(this).attr('rel'))
		$('.target').load($(this).attr('rel'), {url: window.location}, after_load_target)		
	})
	
	index = $(".menu").attr('selected') || 1
	$(".menu li:nth-child(" + index + ")").click()
	
	$('.login-box').draggable()
});


var tmout = null;

function before_load_content() {
	//show loading message only if no response in 500ms
	if(tmout) {
		clearTimeout(tmout)
		tmout = null 
	}
	tmout = setTimeout(function() { $('.target .section').mask("Loading...")}, 500)
}

function after_load_target() {
	if(tmout) {	
		clearTimeout(tmout)
		tmout = null
	}
	$('.target .section').unmask()
	onNewContent()
}