$(document).ready(function () {
initialize_help_icons();
});

function initialize_help_icons ()
  {
$('div.help').each(function() 
  {
  if ($(this).hasClass('alfred_init_complete')) { return; }
  else { $(this).addClass('alfred_init_complete'); }

  var topic = $(this).attr('content');
  
  var dimension;
  if ($(this).hasClass('small'))
    { dimension = 16; }
  else if ($(this).hasClass('large'))
    { dimension = 32; }
  else
    { dimension = 24; }
  
  
  $(this).css(
	{'width': dimension + 'px',
     'height': dimension + 'px'
	}).hover(
		function () 
		  {
		  load_alfred_tooltip(topic); 
		  
		  if ($(this).hasClass('small'))
            { $(this).css('background-image', 'url(/img/help_green_16.png)'); }
          else if ($(this).hasClass('large'))
            { $(this).css('background-image', 'url(/img/help_green_32.png)'); }
          else
            { $(this).css('background-image', 'url(/img/help_green_24.png)'); }
		  },
		function () 
		  {
     	  if ($(this).hasClass('small'))
            { $(this).css('background-image', 'url(/img/help_blue_16.png)'); }
          else if ($(this).hasClass('large'))
            { $(this).css('background-image', 'url(/img/help_blue_32.png)'); }
          else
            { $(this).css('background-image', 'url(/img/help_blue_24.png)'); }
		  }
         );

  
  
  if ($(this).hasClass('small'))
    { $(this).css('background-image', 'url(/img/help_blue_16.png)'); }
  else if ($(this).hasClass('large'))
    { $(this).css('background-image', 'url(/img/help_blue_32.png)'); }
  else
    { $(this).css('background-image', 'url(/img/help_blue_24.png)'); }
	
  
  if ($(this).hasClass('alfred'))
    {
    $(this).overlay({
		'target': 'div#alfred',
		'expose': {
                	  'color': '#001', 
                	  'loadSpeed': 200, 
                	  'opacity': 0.9 
	        	  },
		'onBeforeLoad': function (event) { load_alfred(topic); }
         });
    }
  if ($(this).hasClass('tooltip'))
    {
    $(this).tooltip({
		'tip': '#alfred_tip',
		'predelay': 10,
		'delay': 30,
		//'effect': 'fade',
		'position': 'top right',
		'relative': false
	 }).dynamic(
		{ 'classNames': 'tooltip_top tooltip_right tooltip_bottom tooltip_left'}
		   );
    }

  });

$('span.help').each(function ()
  {
  var topic = $(this).attr('content');
  $(this).hover( function () { load_alfred_tooltip(topic); });

  if ($(this).hasClass('alfred'))
    {
    $(this).overlay({
		'target': 'div#alfred',
		'expose': {
                	  'color': '#001', 
                	  'loadSpeed': 200, 
                	  'opacity': 0.9 
	        	  },
		'onBeforeLoad': function (event) { load_alfred(topic); }
         });
    }
  if ($(this).hasClass('tooltip'))
    {
    $(this).tooltip({
		'tip': '#alfred_tip',
		'predelay': 10,
		'delay': 30,
		//'effect': 'fade',
		'position': 'top right',
		'relative': false
	 }).dynamic(
		{ 'classNames': 'tooltip_top tooltip_right tooltip_bottom tooltip_left'}
		   );
    }
  });


  }

function load_alfred (topic)
  {
  var title = topic;
  var body = topic;
  $('div#alfred .header span').empty().append(title);
  $('div#alfred .body').empty();
  var page_url = 'page.pl';
  $.get(page_url, { 'alfred': topic }, function (data) 
    {
    var message = data.alfred_body;
    $('div#alfred div.body').empty().append(message);
    //flowplayer("player", "flash/flowplayer-3.1.5.swf");
    },
    'json');
}

function load_alfred_tooltip (topic)
  {
  $('div#alfred_tip div.tip_header').empty().append(topic);
  $('div#alfred_tip div.tip_body').empty();
  var page_url = 'page.pl';
  $.get(page_url, { 'alfred_tip': topic }, function (data) 
    {
    var tip = data.alfred_tip_body;
    $('div#alfred_tip div.tip_body').empty().append(tip);
    },
    'json');
  }

