$(document).ready(function(){
  
  // setup help dialog
  $("#helpBox").dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		buttons: {
			OK: function() {
				$(this).dialog('close');
			}
		}
	});
	
  // setup help links
  $('span.helpLink').each(function(){
    
    // get help_slug
    var help_link_text = $(this).html();
    var help_slug = $(this).attr('id');
    
    $(this).html('<a class="helpLink" href="javascript:showHelp(\'' + help_slug + '\');">' + help_link_text + '</a>');
    
  });
  
  // set up table listing help
  $('th > img').click(function(){
    
    $("#helpBox").html($(this).attr('alt'));
    
    $("#helpBox").dialog('open');
    
  });
  
});

/*
  gets the help text, inserts it into the
  help dialog and shows the dialog
*/
function showHelp(help_slug)
{
  // get help via ajax
  $('#helpBox').load(
    '/help/getHelp',
    {slug: help_slug},
    function(){
      $("#helpBox").dialog('open');
    }
  );
}

/**
 * FAQ stuffs:
 * 
 * dialog functionality
 * 
 */
$(function(){

 $('#faqDialog').dialog({
   autoOpen: false,
   width: 600,
   bgiframe: true,
   modal: true,
   buttons: {
     Ok: function() {
       $(this).dialog('close');
     }
   }
 });

});

function showFaq(article_id)
{
 $.get(
   '/article/getFaqPopup',
   {
     id: article_id
   },
   function(data){

     // load data into dialog
     $('#faqDialog').html(data);

     // open dialog
     $('#faqDialog').dialog('open');
   },
   'html'
 );
}
