$(document).ready(function(){
	$("a.type,a.native,a.function,a.constant,a.variable").hoverintent(
	  function(){
	    hovered=this
	    $(this).append('<div class="description">Loading ...</div>');
	    $.get('/w/api.php',
	      { 'action': 'parse'
              , 'page': $(this).attr("href").slice(26)
	      , 'prop': 'text'
	      , 'format': 'xml'
              },
              function(xml){
		pagehtml=$($("text",xml).text());
		infotext=$(".description",pagehtml).html();
		jasscode=$("code.jass:first",pagehtml).html();
		if (infotext==null)
		{
			documentation='<p>No documentation available.</p><a href="' + $(hovered).attr("href") + '">Add it</a>';
		}
		else
		{
			documentation='';
			if (jasscode!=null)
			{
				firstline=jasscode.split("\n")[0];
				firstline=firstline.replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/\s\s*/g, ' ');
				documentation+='<code class="jass">' + firstline + '</code>';
			} 
			documentation+='<p>' + infotext + '</p>';
			documentation+='<a href="' + $(hovered).attr("href") +'">Read more</a>';
		}
		$("div:last",hovered).html(documentation);
              }
            );
	  }, function() {
	    $(this).find(".description").remove();
	  }
        );
});



