function Mouse() {
  var isIE = document.all;
  var ns6  = document.getElementById && !document.all;
  var ieTB = (document.compatMode && document.compatMode!="BackCompat")?document.documentElement:document.body;
    
  var px = null;
  var py = null;
    
  this.setEvent = function(e) {
    px = (ns6)?e.pageX:event.clientX+ieTB.scrollLeft;
    py = (ns6)?e.pageY:event.clientY+ieTB.scrollTop;
  }
    
  this.x = function() { return px; }
    
  this.y = function() { return py; }
}

var mouse = new Mouse();

function mouseMoveManager(e) {
	mouse.setEvent(e);
	$('#tooltip').css('left' , (mouse.x()+4));
	$('#tooltip').css('top' , (mouse.y()-80));
}
function make_tool_tip(box_type , uname) {	
	document.onmousemove = mouseMoveManager;
	
	$('#tooltip').html(make_data_tip (box_type , uname));
	$('#tooltip').css('display' , 'block');
}
function end_tool_tip() {
	document.onmousemove = "";
	$('#tooltip').css('display' , 'none');
	$('#tooltip').html('');
}
function make_data_tip (type , uname) {
	
	if (type ==  'PremiumUsers') { box_type = PremiumUsers; } 
	else if ( type  ==  'JsLastUpdates' ) { box_type = JsLastUpdates; }
	else if (type ==  'JsMostVisited') { box_type = JsMostVisited; }
	
		for(var i in box_type) {
			if(box_type[i][3] == uname) {
			return('<label><b>'+format_length(box_type[i][3])+'</b></label><label>'+box_type[i][4]+'</label><label>'+format_length(box_type[i][6])+'-'+box_type[i][7]+'</label>');
			}
		}
}
function format_length (uname) {
	if (uname.length >= 13) {
		return uname.substring(0,13)+'...';
	}else  {
		return uname;
	}
}
function make_thumbs(type) {
	count_thumb =0;
	thumbs =''
	if (type ==  'PremiumUsers') { box_type = shuffle(PremiumUsers); } 
	else if ( type  ==  'JsLastUpdates' ) { box_type = shuffle(JsLastUpdates) }
	else if (type ==  'JsMostVisited') { box_type = shuffle(JsMostVisited); }

	for(var i in box_type) {
		
		if(count_thumb == 0) {
			if(type == 'JsLastUpdates') { thumbs += '<li id="medium2">'; } else { thumbs += '<li id="medium">'; }
			
			thumbs += '<a href="http://www.vibeflog.com/'+box_type[i][3]+'" onClick="OpenPopUP()" style="background:url(http://h1.vibeflog.com/images/themes/summer/bg.png)  no-repeat left top;" ><div class="clip_photo"><img src="/indexThumbImg.php?http://'+box_type[i][1]+'.vibeflog.com/'+box_type[i][2]+'/'+box_type[i][0]+'.jpg" id="'+box_type[i][3]+'" onmouseover="make_tool_tip(\''+type+'\' , \''+box_type[i][3]+'\')" onmouseout="end_tool_tip()" style=" z-index:2; margin-left:-112px;clip: rect(2px 223px 153px 0px);" /><img src="http://h1.vibeflog.com/images/themes/Vibe_Premium_2007_Promo/clip_new2.png" class="concha" /></div><div class="clip_photo_base">&nbsp;&nbsp;&nbsp;&nbsp;vibeflog.com/'+format_length(box_type[i][3])+'</div></a></li>';
		} else {
			thumbs += '<li><a href="http://www.vibeflog.com/'+box_type[i][3]+'" onClick="OpenPopUP()" title="Fotolog de '+box_type[i][3]+'"><img src="http://'+box_type[i][1]+'.vibeflog.com/'+box_type[i][2]+'/t_'+box_type[i][0]+'.jpg" id="'+box_type[i][3]+'" onmouseover="make_tool_tip(\''+type+'\' , \''+box_type[i][3]+'\')" onmouseout="end_tool_tip()" /></a></li>';
		}
		count_thumb = 1;
	}
	return thumbs;
 }
width = 0;
height = 0;
function make_dimension(obj) {
	width =380;
	height = 235;
	width_orig = obj.width;
	height_orig = obj.height;
	if ((width_orig > width) || (height_orig > height)) {
		rapporto=width_orig/width;
		if(height_orig/rapporto>height) {
			rapporto=height_orig/height;
		}
		width=Math.round(width_orig/rapporto);
		height=Math.round(height_orig/rapporto);
	} else {
		
		width=width_orig;
		height=height_orig;				
	}
	obj.width=width;
	obj.height=height;
}

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]

shuffle = function(v){
    for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
    return v;
};