var pyramid = {
	showDetails: function(id) {
		$("pyramidContribInfo").update("hello");
		$("pyramidContribInfo").show();
		console.log($("contrib_"+id).cumulativeOffset());
	}
}

var pyramidInit = function() {
    /*$$(".advert").invoke("observe","click",function(e) {
		pyramid.showDetails(e.element().up("a").id.replace(/(.*_)(.*)/,"$2"));
	});*/
	
	var contid;
	var contCache=new Array();
	
	var offset = $("pyramid").up().cumulativeOffset();
		var docOffset = document.body.viewportOffset()[1];
	   
		var x = offset[0];
		var y = offset[1]-docOffset;
		//console.log(x+"x"+y);
	
	$$(".topCont, .contImage, .blockName").invoke("observe","mouseover",function(e) {
	   //console.log(e.element());
	   
	   
	   
	   if(e.element().up("span")) {
		   var el = e.element().up("span");
	   } else {
		   var el = e.element();
	   }
       var contid = el.id.replace(/(contributor_id_)(\d+)/,"$2");
	   var extra = el.getAttribute("ret");
	   
	   if(!contCache[contid]) {
		   $('pyramidContribInfo').show();
		   $('pyramidContribInfo').update('<img src="../images/load.gif" style="display:block;margin:5px auto 0 auto;border:none"/><div style="display:block;margin:5px auto 0 auto;border:none;font-size:18px;text-align:center">Loading</div>');
		   new Ajax.Request('../site_includes/xhr_pyramid.php', {
				method:     'POST',
				parameters: 'id='+contid+'&mode=getContInfo&extra='+extra,
				onSuccess: function(t) {
					var contContent = t.responseText;
					contCache[contid] = contContent;
					
					$('pyramidContribInfo').update(contContent);
					if($("noImage")) {
						
					} else {
						
					}
					$('pyramidContribInfo').show();
	
				}
			});
	   } else {
			$('pyramidContribInfo').update(contCache[contid]);
			if($("noImage")) {
				
			} else {
				
			}
			$('pyramidContribInfo').show();  
	   }
	   
//       console.log('mouseover fired');

       e.element().stopObserving("mousemove");
       e.element().observe("mousemove", function(e) {
		   
		   //console.log(yOffset);
		   
           var mx = (e.pointerX() + 20)- x;
           var my = (e.pointerY() + 10)- y - 30;
          
           //$('pyramidContribInfo').setStyle({left:mx+'px',top:my+'px'});
       });
    });

	$$(".topCont, .contImage, .blockName").invoke("observe","mouseout",function(e) {
//        console.log('mouseout fired');
//           if(e.relatedTarget.id == "tooltip") {
//               return;
//           }
           
           $('pyramidContribInfo').hide();

           e.element().stopObserving("mousemove");
       
    });
};

//document.observe( "dom:loaded", pyramidInit);