
// Track the active window
var activeBalloon = '';
var timer;
var timerId = '';

// Attach the actions onload to the map area's
$(document).ready(function()
{
	// On click, make the popup stick
	$('map area, .aniGifLink').click(function(){
		var id = '#' + $(this).attr('href');
		if (activeBalloon != '')
			hide(activeBalloon);
		show(id);
		activeBalloon = id;
		
		_gaq.push([  '_trackPageview', pageIds +'/'+ $(this).attr('href')  ]);
		
		$('[href="'+ $(this).attr('href') +'"].aniGifLink').remove();
		return false;
	});
		
	// Click anywhere to close
	$('.closeLink').click(function(){
		hide(activeBalloon);
		return false;
	});
	
	$('.ie6 .textBlock').pngFix();
});


// Show a balloon
function show(id)
{
	setBalloon(id);
	$(id).show();
	$(id+'-pointer').show();
	$('.closeLink').show();
	if (id == '#groei-feiten')
		$('.ie6 .closeLinkOuter').hide();
}

// Hide a balloon
function hide(id)
{
	$(id).hide();
	$(id+'-pointer').hide();
	$('.closeLink').hide();
}


//Set the rounded box sizes based on the container sizes
function setBalloon(id)
{
	var width  = $(id).width();
	var height = $(id).height();
	
	if ($('.win, .linux').length > 0  &&  !$(id).hasClass('adjusted'))
	{
		width = width + 40;
		$(id).width(width);
		if ($(id+'-pointer').attr('class').indexOf('right') >= 0)
		{
			var left = parseFloat( $(id).css('left') )  -  40;
			$(id).css('left', left+'px');
		}
		$(id).addClass('adjusted');
	}
	
	$(id +' .text').width(width-27).height(height-2*27-3);
	
	//Set balloons
	$(id +' .balloon').width(width).height(height);
	$(id +' .balloon-middle').width(width - 100).height(height - 100);
	
	$(id +' .balloon-top').width(width - 100);
	$(id +' .balloon-bottom').width(width - 100);
	$(id +' .balloon-left').height(height - 100);
	$(id +' .balloon-right').height(height - 100);
	
	$(id +' .balloon a').unbind().click(function(){
		hide(id);
		activeBalloon = '';
	});
}

