$(document).ready(function(){
	var _x = 0;
	var _y = 0;
	$('.table #select input, a.tooltip').mousemove(function(e){
		var offset = $(this).parents('body').offset();
		_x = e.pageX - offset.left + 16;
		_y = e.pageY - offset.top + 30;
		if ($('#tooltip:visible').get(0)) {
			$('#tooltip:visible').css({left:_x,top:_y})
		}
	});
	$('.table #select input').hover(function(){
		var _tooltip = $('#tooltip');
		__val = $(this).attr('value');
		__title = $(this).attr('alt');
		_tooltip.html("<img src='" + __val + "' alt=''/><div class='title'>" + __title + "</div>")
		.css({'position':'absolute','top':'-9999px','left':'-9999px','border':'1px solid #000','padding':'20px','background':'#fff'}).show();
		$('#tooltip .title').css({'text-align':'center','font-size':'22px','line-height':'26px','padding':'10px 30px'});
		$('#tooltip img').bind("load", function(e){
			_tooltip.css({
				'width':$('#tooltip img').width() + 'px'
			});
		});
	},function(){
		$('#tooltip').hide();
	});
	$('a.tooltip').hover(function(){
		var _tooltip = $('#tooltip');
		__val = $(this).attr('rel');
		__title = $(this).attr('title');
		if(__title!=null) {
			_tooltip.html("<img src='" + __val + "' alt=''/><div class='title'>" + __title + "</div>")
		}else{
			_tooltip.html("<img src='" + __val + "' alt=''/>")
		}
		_tooltip.css({'position':'absolute','top':'-9999px','left':'-9999px','border':'1px solid #000','padding':'20px','background':'#fff'}).show();
		$('#tooltip .title').css({'text-align':'center','font-size':'22px','line-height':'26px','padding':'10px 30px'});
		$('#tooltip img').bind("load", function(e){
			_tooltip.css({
				'width':$('#tooltip img').width() + 'px'
			});
		});
	},function(){
		$('#tooltip').hide();
	});
	$('a.tooltip').click(function(){
		var __val = $(this).attr('rel');
		var __title = $(this).attr('title');
		$(this).parent().parent().find('a').each(function(){
			$(this).removeClass('selected');
		});
		$(this).addClass('selected');
		if(__title!=null && __title!='') {
			$(this).parents('.side-grey').find('div.frame').html('<img src="' + __val + '" alt=""/><span id="select-image-title" class="caption">' + __title + '</span>');
		}else{
			$(this).parents('.side-grey').find('div.frame').html('<img src="' + __val + '" alt=""/>');
		}
		if(!$(this).is('.pht') && !$(this).is('.prc')){
			return false;
		}		
	});
});