hv.unOverEle= 0;
hv.unOverTime= 0;
hv.unOverPos = [];
hv.unEnricherCall = function(id){
	if(hv.unOverEle && id == hv.unOverEle.hvEri){
		var date = new Date();
		if(date.getTime() - hv.unOverTime > 470){
			var user = $(hv.unOverEle).attr('hvUserId');
			$('<div class="unBox" id="unBox'+user+'"></div').appendTo('body').
					css({left:hv.unOverPos[0] + 5 + 'px',top:hv.unOverPos[1] + 5 + 'px'}).show()
			$.post('/aid/user/box/'+user,'',function(json){
				var cmp = [];
				var pic = json.pid;
				pic = pic ? '<img src="/uf/'+user+'/0/'+pic+'.img.sq100" class="unBoxPic"/>' : '';
				var firstName = json.first_name;
				var lastName = json.last_name;
				if(firstName || lastName){
					cmp[cmp.length] = '<dt>Name</dt><dd>'+firstName+' '+lastName+'</dd>';
				}
				var un = json.name;
				if(un){
					cmp[cmp.length] = '<dt>User Name</dt><dd>'+un+'</dd>';
				}
				var gender = json.gender;
				if(gender){
					cmp[cmp.length] = '<dt>Gender</dt><dd>'+(gender==1?'Male':(gender==2?'Female':'Not Provided'))+'</dd>';
				}
				var dob = json.dob;
				if(dob){
					cmp[cmp.length] = '<dt>DOB</dt><dd>'+dob+'</dd>';
					var age = json.age;
					cmp[cmp.length] = '<dt>Age</dt><dd>'+age+'</dd>';
				}
				var weight = json.weight;
				if(weight){
					weight = weight/10;
					cmp[cmp.length] = '<dt>Weight</dt><dd>'+weight+' kg ('+(parseInt(weight*2.204))+' lb)</dd>';
				}
				var height = json.height;
				if(height){
					var inches = height/2.54;
					var feet = Math.floor(inches/12);
					inches = Math.round(inches % 12);
					cmp[cmp.length] = '<dt>Height</dt><dd>'+height+' cm ('+feet+'\''+inches+'")</dd>';
				}
				var loc = json.loc;
				if(loc){
					loc = loc.split('|').join(',<br/>');
					cmp[cmp.length] = '<dt>Location</dt><dd>'+loc+'</dd>';
				}
				$('#unBox'+user+'').html(pic+'<dl>'+cmp.join('<br/>')+'</dl>');
			},'json');
		}
	}
}
hv.unEnricher = function (){
	if(hv.uid){
		$('.u'+hv.uid).addClass('self');
	}
	$('.un[hvUnParsed!=1]').each(function(){
		this.hvUnParsed = 1;
	}).mouseover(function(e){
		hv.getEri(this);
		hv.unOverEle = this;
		var date = new Date()
		hv.unOverTime = date.getTime();
		hv.unOverPos = hv.eventPos(e);
		var user = $(this).attr('hvUserId');
		var unBox = $('#unBox'+user);
		$('.u'+user).addClass('u-in')
		if(!unBox.size()){
			setTimeout('hv.unEnricherCall('+this.hvEri+')',500);
		}else{
			unBox.css({left:hv.unOverPos[0] + 5 + 'px',top:hv.unOverPos[1] + 5 + 'px'}).show();
		}
	}).mouseout(function(){
		hv.unOverEle= '';
		var user = $(this).attr('hvUserId');
		$('.u'+user).removeClass('u-in')
		var unBox = $('#unBox'+user);
		if(unBox.size()){
			unBox.hide();
		}else{
			setTimeout("$('#unBox'+"+user+").hide()",200);
		}
	}).click(function(e){
		pos = hv.eventPos(e);
		var user = $(this).attr('hvUserId');
		var unActions = $('#unActions'+user);
		if(!unActions.size()){
			var html = '<div class="ln" style="text-align:right" onclick="$(this).parent().hide()">X</div>';
			html += '<div><a href="/profile/view/user/'+user+'">View Profile</a></div>';
			html += '<div><a href="/msg/write/?to='+user+'">Send Message</a></div>';
			html += '<div><a href="/picture/user/'+user+'">View Pictures</a></div>';
			html += '<div><span class="ln" onclick="if(hv.reqLogin()){$.get(\'/user/contact\',{a:\'add\',user:'+user+'});$(this).parent().remove();}">Add contact</span></div>';
			html += '<div><span class="ln" onclick="if(hv.reqLogin()){$.get(\'/user/block\',{a:\'add\',user:'+user+'});$(this).parent().remove();}">Block</span></div>';
			html += '<div><a href="/user/interact/'+user+'">More</a></div>';
			$('<div class="unActions" id="unActions'+user+'">'+html+'</div').appendTo('body').
						css({left:pos[0] + 5 + 'px',top:pos[1] + 5 + 'px'}).show();
		} else {
			unActions.css({left:pos[0] + 5 + 'px',top:pos[1] + 5 + 'px'}).show();
		}
	});
}
hv.locOverEle= 0;
hv.locOverTime= 0;
hv.locOverPos= [];
hv.locEnricherCall = function(id){
	if(hv.locOverEle && id == hv.locOverEle.hvEri){
		var date = new Date();
		if(date.getTime() - hv.locOverTime > 470){
			var loc = $(hv.locOverEle).attr('hvLocId');
			$('<div class="locBox" id="locBox'+loc+'"></div').appendTo('body').css({left:hv.locOverPos[0] + 5 + 'px',top:hv.locOverPos[1] + 5 + 'px'}).show()
					$.post('/aid/loc/box/'+loc,'',function(json){
						if(json.loc){
							json.loc = json.loc.split('|').join(',<br/>');
							$('#locBox'+loc+'').html(json.loc);
						}else{
							$('#locBox'+loc+'').html('Location Not Found');
						}
					},'json');
		}
	}
}
hv.locEnricher = function (){
	$('.loc[hvLocParsed!=1]').mouseover(function(e){
		this.hvLocParsed = 1;
		hv.locOverPos = hv.eventPos(e);
		hv.getEri(this);
		hv.locOverEle = this;
		var date = new Date()
		hv.locOverTime = date.getTime();
		var loc = $(this).attr('hvLocId');
		$('..'+loc).addClass('l-in')
		var locBox = $('#locBox'+loc);
		if(!locBox.size()){
			setTimeout('hv.locEnricherCall('+this.hvEri+')',500);
		}else{
			locBox.css({left:hv.locOverPos[0] + 5 + 'px',top:hv.locOverPos[1] + 5 + 'px'}).show();
		}
	}).mouseout(function(){
		var loc = $(this).attr('hvLocId');
		$('.l'+loc).removeClass('l-in')
		var locBox = $('#locBox'+loc);
		if(locBox.size()){
			locBox.hide();
		}else{
			setTimeout("$('#locBox'+"+loc+").hide()",200);
		}
	});
}
hv.timeEnricher = function (){
	$('.ts[hvTimeParsed!=1]').each(function(){
		this.hvTimeParsed = 1;
		var TS = $(this).html().split(' ');
		var time = parseInt(TS[0]);
		var date = new Date()
		date.setTime(time*1000);
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate();
		var hours = date.getHours();
		if(TS[1]=='age'){
			date = new Date;
			var age = date.getFullYear() - year;
			var cmonth = date.getMonth();
			if(cmonth < month){
				age-=1;
			}else if(cmonth == month && date.getDate() < day){
				age-=1;
			}
			$(this).html(age);
		}else{
			hours = hours < 10 ? '0'+hours : hours;
			var mins = date.getMinutes();
			mins = mins < 10 ? '0'+mins : mins;
			this.hvTimeFormatted = year+'-'+month+'-'+day+' '+hours+':'+mins;
			$(this).html(this.hvTimeFormatted);
			date = new Date();
			date = parseInt(date.getTime()/1000);
			var gap = date - time;
			var ago = [];
			if(ago >= 31536000){
				var years = Math.floor(gap/31536000);
				gap = gap % 31536000;
				ago[ago.length] = years+'y'
			}
			if(gap >= 86400){
				var days = Math.floor(gap/86400);
				gap = gap % 86400;
				ago[ago.length] = days+'d'
			}
			if(gap >= 3600){
				var hours = Math.floor(gap/3600);
				gap = gap % 3600;
				ago[ago.length] = hours+'h'
			}
			if(gap >= 60){
				var minutes = Math.floor(gap/60);
				gap = gap % 60;
				ago[ago.length] = minutes+'i'
			}
			if(gap){
				ago[ago.length] = gap+'s'
			}
			this.hvTimeAgo = ago.join(',');
			this.title = this.hvTimeAgo;
		}
	});
}

hv.pagerEnricher = function(){
	$('.pager').each(function(){
		var total = $(this).attr('hvTotalPages');
		if(total > 11){
			$('.pager .skipTo').click(function(e){
				pos = hv.eventPos(e);
				var skipTo = $('#pagerSkipTo');
				if(!skipTo.size()){
					var html = '<div style="float:left">Go to page:</div><div class="ln" style="float:right" onclick="$(this).parent().hide()">X</div>';
					html += '<div><input id="skipToInput" type="text"/> / '+total+' <button onclick="hv.pageSkipTo()">Go</button></div>';
					$('<div id="pagerSkipTo">'+html+'</div').appendTo('body').
								css({left:pos[0] + 5 + 'px',top:pos[1] + 5 + 'px'}).show();
				} else {
					skipTo.css({left:pos[0] + 5 + 'px',top:pos[1] + 5 + 'px'}).show();
				}
			})
		}
	});
}
hv.pageSkipTo = function(){
	var pager = $('.pager:first');
	var url = pager.attr('hvPagerUrl');
	var total = pager.attr('hvTotalPages');
	var input = parseInt($('#skipToInput').val());
	if(input > total){
		alert('There aren\'t that many pages');
		return false;
	}
	url = url.replace(/&p=[0-9]*/,'');
	window.location = url+'&p='+input;
}
hv.startUp(hv.pagerEnricher);