SocialEngineAPI.PopupFoto = new Class({
  
  initialize: function()
  {
    document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;"></div>');
  },

  trailOff : function()
  {
  	document.onmousemove='';
    $('imgtrailer').setStyle('visibility', 'hidden');
  },
  
  trailOn : function(thumbimg,imgtitle,a,b)
  {
		$('imgtrailer').setStyle('left','-500px');
		$('imgtrailer').empty();
		var div1 = new Element('div', {
                           'styles' : { 
                              'background' : '#a7a79c',
                              'background-image' : 'url(images/loading.gif)',
                              'background-repeat' : 'no-repeat',
                              'background-position' : '50% 50%',
                              'padding' : '12px'
                              }});
    var img = new Element('img', {
                          'src' : thumbimg,
                          'border' : '0' });
    var title = new Element('div', {
                            'html' : imgtitle,
                            'styles' : {
                            'background' : '#d7dcc0',
                            'padding' : '3px',
                            'text-align' : 'center'}});
		div1.inject($('imgtrailer'));
		img.inject(div1);
		title.inject(div1,'bottom');
		$('imgtrailer').setStyle('visibility','visible');

		document.onmousemove=this.followmouse;
  },
  
  followmouse : function(e)
  {
    truebody = (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
    
    var docwidth = $(document).getWidth();
    var docheight = $(document).getHeight();
    var divw = $('imgtrailer').getStyle('width').toInt();
    var divh = $('imgtrailer').getStyle('height').toInt();
    if (divw == "NaN" || divw == 0)
      divw = 80;
    if (divh == "NaN" || divh == 0)
      divh = 80;
      
    if(typeof e != "undefined")
    {
    	if(docwidth < 15+e.pageX+divw)
    		xcoord = e.pageX-divw-5;
    	else
    		xcoord = 15+e.pageX;
    		
    	if(docheight < 15+e.pageY+divh)
    		ycoord = 15+e.pageY-divh;
    	else
    		ycoord = 15+e.pageY;
    }
    else if (typeof window.event != "undefined")
    {
    	if(docwidth < 15+truebody.scrollLeft+window.event.clientX+divw)
    		xcoord = truebody.scrollLeft-5+window.event.clientX-divw;
    	else
    		xcoord = truebody.scrollLeft+15+window.event.clientX;
    
    	if(docheight < 15+truebody.scrollTop+window.event.clientY+divh)
    		ycoord = 15+truebody.scrollTop+window.event.clientY-divh;
    	else
    		ycoord = truebody.scrollTop+15+window.event.clientY;
    }
    
  	$('imgtrailer').setStyle('left',xcoord);
  	$('imgtrailer').setStyle('top',ycoord);
  }
});
