var UPDATESCROLLBARStimeout = 0;
var _animTimer = 500;

$(document).ready(function(){
	$('#popup').hide();
	$('#overlay').hide();
	
	$('a#btnClose, #overlay').bind('click', function(){
		$(this).blur();
		unloadPopupSpeekseltest();
		return false;
	});
	$('a#firepopup').bind('click', function(){
		$(this).blur();
		loadPopupSpeekseltest();
		return false;
	});
});
function unloadPopupSpeekseltest()
{
	$('#popup').fadeOut(_animTimer, function(){
		$('#overlay').fadeOut(_animTimer, function(){
			$('.jspPane').html('loading...');
			$('.jspPane').css('top', '0px');
			//$('object').css("visibility", "visible");
		});	
	});
}
function loadPopupSpeekseltest(lang)
{
	//$('object').css("visibility", "hidden");
	$('#overlay').hide().fadeIn(_animTimer, function(){
		if($('.jspPane').length == 0)
		{
			$('#popup .content').html($('#' + lang).html());
		}
		else
		{
			$('#popup .jspPane').html($('#' + lang).html());
		}
		update_scrollbars();
		
		$('#popup').hide().fadeIn(_animTimer);
	});

}

function update_scrollbars() 
{
    this.api = null;
    this.el = null;
	clearTimeout(UPDATESCROLLBARStimeout);
	UPDATESCROLLBARStimeout = setTimeout(function()
	{
		this.el = $("#popup .content");
		this.api = this.el.data('jsp');
		
		if (this.api && this.api.getIsScrollableV()) 
		{
			this.api.reinitialise();
		}
		else 
		{
			this.el.jScrollPane({
				showArrows : false,
				scrollbarWidth:24,
				scrollbarMargin:24,
				verticalDragMinHeight: 24,
				verticalDragMaxHeight: 24,
				hijackInternalLinks: true,
				maintainPosition: false
			});
		}

	}, 250);
	
}
