// JavaScript Document
$(function(){
	var moving = false;
	var val = {};
	$('.blockup').draggable({
		'handle'	: '.title'
	}).find('div.title').css('cursor','move')
	.find('a.closer').click(function(){
		$(this).parents('.blockup').hide();
		$("div#markA").remove();
		return false;
	}).parents('.blockup').find('.scroll .handle').draggable({
		'containment'	: 'parent',
		start			: function(event,ui){
										val	=	{
	'maxHeight'	: (parseInt($(this).parent().css('height'))-17-parseInt($(this).height())),
	'areaHeight': (parseInt($(this).parent().prev('.select_area').height())-parseInt($(this).parent().prev('.select_area').children('ul').height()))
												};
									},
		drag			: function(event,ui){
										val.topPx = parseInt(ui.position.top)*parseInt(val.areaHeight)/parseInt(val.maxHeight);
										$(this).parent('.scroll').prev('.select_area').find('ul').css('top',val.topPx);
									}
	}).parent('.scroll').find('a.up').click(function(){
		var top1 = parseInt($(this).next('.handle').css('top'));
		val	= {
			'maxHeight'	: (parseInt($(this).parent().css('height'))-17-parseInt($(this).height())),
			'areaHeight': (parseInt($(this).parent().prev('.select_area').height())-
							parseInt($(this).parent().prev('.select_area').children('ul').height()))
		};
		if((top1-10)<0){return false;}
		val.topPx = parseInt(top1-10)*parseInt(val.areaHeight)/parseInt(val.maxHeight);
		$(this).next('.handle').animate({'top':(top1-10)},100);
		$(this).parent('.scroll').prev('.select_area').find('ul').animate({'top':val.topPx},100);
		return false;
	}).end().find('a.down').click(function(){
		var top1 = parseInt($(this).prev('.handle').css('top'));
		val	= {
			'maxHeight'	: (parseInt($(this).parent().css('height'))-17-parseInt($(this).height())),
			'areaHeight': (parseInt($(this).parent().prev('.select_area').height())-
							parseInt($(this).parent().prev('.select_area').children('ul').height()))
		};
		if((top1+10)>val.maxHeight){return false;}
		val.topPx = parseInt(top1+10)*parseInt(val.areaHeight)/parseInt(val.maxHeight);
		$(this).prev('.handle').animate({'top':(top1+10)},100);
		$(this).parent('.scroll').prev('.select_area').find('ul').animate({'top':val.topPx},100);
		return false;
	});
});
