// JavaScript Document
$(document).ready(function()
{
	if($("#latest_box").html() != undefined){
		apply_hover();
	}
});

function apply_hover(){
	$("#latest_box .latest img").bind("mouseenter", function(e){
		show_ajax_div($("#special_popup"), $(this).parent().parent().children('p').html(), e);
	});
	$("#latest_box .latest img").mousemove(function(e){
		move_ajax_div($("#special_popup"), e);
	});
	$("#latest_box .latest img").mouseout(function(e){
		hide_div($("#special_popup"));
	});
}

function show_ajax_div(popup, link, pos){
	popup.html('<img src="/images/loading.gif" width="16" height="16" alt="loading..." />');
	
	var w = $(window).width();
	if(pos.pageX >= w/2) {
		popup.css('left', pos.pageX-370+'px');
		popup.css('top', pos.pageY-203+'px');
	} else {
		popup.css('left', pos.pageX+11+'px');
		popup.css('top', pos.pageY-203+'px');
	}
	
	$.ajax({
		type:'POST',
		url: link,
		data:'type=home',
		success:function(html){
			popup.html(html);
		}
	});
}

function move_ajax_div(popup, pos){
	var w = $(window).width();
	if(pos.pageX >= w/2) {
		popup.css('left', pos.pageX-370+'px');
		popup.css('top', pos.pageY-203+'px');
	} else {
		popup.css('left', pos.pageX+11+'px');
		popup.css('top', pos.pageY-203+'px');
	}
}

function hide_div(popup){
	popup.css('left', '-1000px');
}
