$(function(){
	$('#main').mousewheel(function(event, delta){
		if (delta > 0){
			if (moving == false){
				moving = true;
				scrollUp();
			}
		} else if (delta < 0) {
			if (moving == false){
				moving = true;
				scrollDown();
			}
		}
	});
	$(".up").mousedown(function(){
		if (moving == false){
			moving = true;
			scrollUp();
			clearInterval(timeout);
			timeout = setInterval(scrollUp, 400);
		}
		return false;
	});
	$(".up").mouseup(function(){
		clearInterval(timeout);
	});
	$(".down").mousedown(function(){
		if (moving == false){
			moving = true;
			scrollDown();
			clearInterval(timeout);
			timeout = setInterval(scrollDown, 400);
		}
		return false;
	});
	$(".down").mouseup(function(){
		clearInterval(timeout);
	});
	$(".up2").mousedown(function(){
		if (moving2 == false){
			moving2= true;
			scrollUp2();
			clearInterval(timeout2);
			timeout2 = setInterval(scrollUp2, 400);
		}
		return false;
	});
	$(".up2").mouseup(function(){
		clearInterval(timeout2);
	});
	$(".down2").mousedown(function(){
		if (moving2 == false){
			moving2 = true;
			scrollDown2();
			clearInterval(timeout2);
			timeout2 = setInterval(scrollDown2, 400);
		}
		return false;
	});
	$(".down2").mouseup(function(){
		clearInterval(timeout2);
	});
	//[AJAX] First Picture
	$("#scroll_photo").find("li:first a").each(function(){
		var img = $('#loading');
		$.ajax({
		  type:"GET",
		  url: $(this).attr('href'),
		  success:function(data){
			$('#pressMainImage').empty().html(data);
		  },
		  complete: function(){
		  	img.hide();
		  },
		  beforeSend: function(){
		  	img.show();
		  }
		});
		return false;
	});
	//Change Info and Picture [AJAX]
	$("#scroll_photo li a").click(function(){
		var img = $('#loading');
		$.ajax({
		  type:"GET",
		  url: $(this).attr('href'),
		  success:function(data){
			$('#pressMainImage').empty().html(data);
		  },
		  complete: function(){
		  	img.hide();
		  },
		  beforeSend: function(){
		  	img.show();
		  }
		});
		return false;
	});
});
//Scroll
var timeout;
var moving = false;

function scrollUp(){
	var topActual = ($("#scroll_photo ul").offset().top-$("#thumbScroll_photo").offset().top);
	if ($("#scroll_photo ul").offset().top-$("#thumbScroll_photo").offset().top < 0) {
		$("#scroll_photo ul").animate({top: (topActual+111)}, 300, null, function(){moving = false;});
	}else{
		moving = false;
	}
}

function scrollDown(){
	var topActual = ($("#scroll_photo ul").offset().top-$("#thumbScroll_photo").offset().top);
	var lastLi = 328-($("#scroll_photo ul").find("li:last").offset().top);
	if ($("#scroll_photo ul").height() > $("#thumbScroll_photo").height() && lastLi <= -198) {
		$("#scroll_photo ul").animate({top: (topActual-111)}, 300, null, function(){moving = false;});
	}else{
		moving = false;
	}
}
//Scroll2
var timeout2;
var moving2 = false;

function scrollUp2(){
	var topActual2 = ($("#scrollPressRelated ul").offset().top-$("#thumbScroll").offset().top);
	if ($("#scrollPressRelated ul").offset().top-$("#thumbScroll").offset().top < 0) {
		$("#scrollPressRelated ul").animate({top: (topActual2+115)}, 300, null, function(){moving2 = false;});
	}else{
		moving2 = false;
	}
}

function scrollDown2(){
	var topActual2 = ($("#scrollPressRelated ul").offset().top-$("#thumbScroll").offset().top);
	var lastLi2 = 570-($("#scrollPressRelated ul").find("li:last").offset().top);
	if ($("#scrollPressRelated ul").height() > $("#thumbScroll").height() && lastLi2 <= 0) {
		$("#scrollPressRelated ul").animate({top: (topActual2-115)}, 300, null, function(){moving2 = false;});
	}else{
		moving2 = false;
	}
}