this.tooltip = function()
{	
    /*
   * Tooltip script 
   * powered by jQuery (http://www.jquery.com)
   * 
   * written by Alen Grakalic (http://cssglobe.com)
   * 
   * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
   */
  
	/* CONFIG */		
		xOffset = 2;
		yOffset = 16;
		
	/* END CONFIG */		
	$(".tooltip").hover(
	  function(e)
	  {											  
  		this.t = this.title;
  		this.title = "";									  
  		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		
		
  		$("#tooltip")
  			.css("top", (e.pageY - yOffset) + "px")
  			.css("left",(e.pageX + xOffset) + "px")
  			.fadeIn("fast");		
    },   
  	function() 
  	{
  		this.title = this.t;		
  		$("#tooltip").remove();
    }
  );	    
	$("a.tooltip").mousemove(
  	function(e)
  	{
  		$("#tooltip")
  			.css("top", (e.pageY - yOffset) + "px")
  			.css("left",(e.pageX + xOffset) + "px");
  	}
  );
  
}


function downloadThumbnails()
{
  var yresults = $('.result-list');

  yresults.each( function()
  {
    // check if the thumbnail has already been loaded and if it is on the page.
    var result_thumb = $('.result-thumb', this);
    
    // THE CODE FOR TELLING IF THE ITEM IS ON THE PAGE NEEDS TO BE FIGURED OUT.
    
    var is_on_screen = true;
    //alert( $(result_thumb).offsetY );
    if ($(result_thumb).offsetTop > 0 && $(result_thumb).offsetTop < $(window).height())
    {
      is_on_screen = true;
    }
    
    if ($(result_thumb).attr("thumb_loaded") == "false" && is_on_screen == true)
    {
      var result_url = $(this).attr("result_url");
  
      // download the thumbnail and set it as the html!
      var query = '/GetAlbumArt.php?uri=' + result_url + ' .albumInfoPicHolder';
      //result_thumb.hide();
      result_thumb.load(query, null, function(response_text, status_code, xhr_instance)
        {
          //$(this).show("slow");
          //alert(status_code);
          if (status_code == "success")
          {
            $(result_thumb).attr("thumb_loaded", "true");
          }
          $(this).show();
        });
    }
  });
}
function downloadInformation()
{
  var yresults = $('.result-list');

  yresults.each( function()
  {
    var result_url = $(this).attr("url");


    // check if the thumbnail has already been loaded and if it is on the page.
    var result_thumb = $('.result-thumb', this);
    var result_meta = $('.result-meta', this);
    
    // Download the thumbnail  
    
    var is_on_screen = true;
    
    if ($(result_thumb).attr("thumb_loaded") == "false" && is_on_screen == true)
    {      
      var rhap_thumb_query = '/GetAlbumArt.php?url=' + result_url + ' .albumInfoPicHolder';
      
      //result_thumb.hide();
      result_thumb.load(rhap_thumb_query, null, function(response_text, status_code, xhr_instance)
        {
          //$(result_thumb).fadeIn("slow");
          //alert(status_code);
          if (status_code == "success")
          {
            $(result_thumb).attr("thumb_loaded", "true");
          }
          $(this).show();
        }); 
    } // end if

    // Download the meta information
    //result_meta.hide();
    if ($(result_meta).attr("meta_loaded") == "false")
    {      
      var rhap_meta_query = buildMetaQuery(this);
      
      result_meta.load(rhap_meta_query, null, function(response_text, status_code, xhr_instance)
        {
          //$(result_meta).show("slow");
          //alert(status_code);
          if (status_code == "success")
          {
            $(result_meta).attr("meta_loaded", "true");
          }
          $(this).show();
        });      
    } // end if
    
  });
}

function buildMetaQuery(th)
{
  var abstract = $(th).attr("abstract");
  var clickurl = $(th).attr("clickurl");
  var date = $(th).attr("date");
  var dispurl = $(th).attr("dispurl");
  var size = $(th).attr("size");      
  var title = $(th).attr("title");     
  var url = $(th).attr("url");
    
  var query = "/GetSingleResultMeta.php?";
  query += "abstract=" + escape(abstract);
  query += "&clickurl=" + escape(clickurl);
  query += "&date=" + escape(date);
  query += "&dispurl=" + escape(dispurl);
  query += "&size=" + escape(size);
  query += "&title=" + escape(title);
  query += "&url=" + escape(url);
  
  return query;    
}


function ga()
{
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

  try 
  {
    var pageTracker = _gat._getTracker("UA-1066422-7");
    pageTracker._trackPageview();
  } catch(err) {}
}

$(document).ready(function()
{
  tooltip();
  downloadInformation();
});
// $(window).scroll(function() {
//   downloadThumbnails();
//   });

