// JavaScript Document
$(document).ready(function(){
	// *** Tooltips
	toolTips = new Array;
	$('#bsagCountries ul li a').each(function(arr) 
	{
		toolTips[arr] = new toolTip(this);
		toolTips[arr].init(arr);
	});
	// *** scrollpanel
	$('#pane1').jScrollPane({scrollbarWidth: 19, dragMaxHeight: 12, maintainPosition: false});/*for some inexplicable reason this line is requiredtwice;  both here and in the HTML-code.*/
  $('#activityLinks a').bind('click', swapAct);
});

function toolTip( element ) 
{
	this.aElement = element;
	this.animating = false;
	this.divId = '';
	this.titleTxt = $(element).attr("title");
	
	this.init = function(arr)
	{
		this.divId = 'toolTip_'+ arr;
		$(this.aElement).removeAttr('title');
		$(this.aElement).bind('mouseover', {thisObj: this}, this.show);
		$(this.aElement).bind('mouseout', {thisObj: this}, this.hide);
	}
	this.show = function(event)
	{
		object = event.data.thisObj;
		if ( object.animating == false )
		{
			if ( !document.getElementById(object.divId) )
				$("body").append('<div id="'+ object.divId +'" class="toolTip"><p>'+ object.titleTxt +'</p></div>');
			position = $(object.aElement).offset();
			$('#'+ object.divId).css('top', (position.top + $(object.aElement).outerHeight()) +'px');
			$('#'+ object.divId).css('left', position.left +'px');
			object.animating = true;
			$('#'+ object.divId).fadeIn("medium", function() { object.afterFadeIn(event); });
		}
		else
		{
			$('#'+ object.divId).stop(true, true);
			object.animating = false;
			object.show(event);
		}
	}
	this.hide = function(event)
	{
		object = event.data.thisObj;
		if ( object.animating == true )
		{
			$('#'+ object.divId).stop(true);
		}
		object.animating = true;
		$('#'+ object.divId).fadeOut("medium", function() { object.afterFadeOut(event); });
	}
	this.afterFadeIn = function(event)
	{
		object = event.data.thisObj;
		object.animating = false;
	}
	this.afterFadeOut = function(event)
	{
		object = event.data.thisObj;
		object.animating = false;
		$('#'+ object.divId).remove();
	}
}

function swapAct(){
	$('#pane1 > div').hide();
	$('#pane1 #' + $(this).html()).show();
	$('#pane1').jScrollPane({scrollbarWidth: 19, dragMaxHeight: 12, maintainPosition: false});
  $('#activityLinks a').removeClass('pageActive');
  $(this).addClass('pageActive');
 	return false;
  /*
  switch($(this).html()){	//dummy content swap for etusivu.html's preview
    case 'Commitments': $('#pane1').html($('#Commitments').html());
    break;
    case 'News': $('#pane1').html($('#News').html());
    break;
    case 'All': $('#pane1').html($('#All').html());
    break;
  }
  */
}