var handleMouse = null;

$(document).ready(function() {					   
	$("a.bookadd").css("cursor", "pointer");
	
	$("a.bookadd").bind('click', function() {
		var id = $(this).attr("id");
		var p = $(this).position();
		$("div#adding-" + id).css("left", p.left - 15);
		$("div#adding-" + id).css("top", p.top-30);		
		$("div#adding-" + id).css("display", "block");
		$("div#adding-" + id).bind('mouseover', function(){
			if (handleMouse != null) {
				clearTimeout(handleMouse);
				handleMouse = null;
			}
			$("div#adding-" + id).css("display", "block");
		});
		$("div#adding-" + id).bind('mouseleave', function(){
			handleMouse = setTimeout("hideForm("+id+")",1000);
		});
		$("div#adding-" + id).bind('mousemove', function(){
			if (handleMouse != null) {
				clearTimeout(handleMouse);
				handleMouse = null;
			}
		});

	});
});

function getTopPos(inputObj) {
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue - 10;
}

function getLeftPos(inputObj) {
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;  
  return returnValue - 38;
}

function positionDiv(id, inputObj) {	
	document.getElementById(id).style.left = getLeftPos(inputObj) + 'px';
	document.getElementById(id).style.top = getTopPos(inputObj) + 'px';
	document.getElementById(id).style.width = "110px";
}

function showForm(id, inputObj) {
	positionDiv(id, inputObj);
	$("#" + id).toggle();
}

function showForm(id, inputObj, x, y) {	
	document.getElementById(id).style.left = (getLeftPos(inputObj) - x) + 'px';
	document.getElementById(id).style.top = (getTopPos(inputObj) - y) + 'px';
	document.getElementById(id).style.width = "110px";
	
	$("#" + id).toggle();
}

function hideFormEvent(id){
	$("div#adding-" + id).bind('mouseout', function(){
		hideForm(id);
	});	
}

function hideForm(id){
	$("div#adding-" + id).css("display", "none");
	clearTimeout(handleMouse);
	handleMouse = null;
}

$(function(){
	$('.view_num').mouseover(function(){
		$(this).parent().find('.book_rating_num').css("left",$(this).offset().left-20);
		$(this).parent().find('.book_rating_num').css("top",$(this).offset().top-5);
	});
	$('.book_rating_num').bind('mouseout',function(){
		$(this).css("left",-2000);
		$(this).css("top",0);
	})
});

function hideMe(){
	$("#book_rating_num").css("left",-2000);
	$("#book_rating_num").css("top",0);
}
