var holder_width=365;
var init_move_speed = 8;
var move_speed = init_move_speed;
var speed_boost = 20;
var cur_pos = 0;
var max_cur_pos = 0;
var moving = false;
var max_cur_pos = -62*pics_cnt + holder_width;

$(document).ready(function(){
	/*max_cur_pos = -1*($("#scrollableArea").width() - holder_width);
	alert( max_cur_pos );*/
	
	$("#scrollingLeft").mouseover(function () { 
		moving = true;
		move_left();
	});
	$("#scrollingLeft").mouseleave( function () { 
		move_speed = init_move_speed;
		moving = false;
	});
	
	$("#scrollingLeft").mousedown( function () { 
		move_speed += speed_boost;
	});
	$("#scrollingLeft").mouseup( function () { 
		move_speed -= speed_boost;
	});
	
	$("#scrollingRight").mouseover(function () { 
		moving = true;
		move_right();
	});
	$("#scrollingRight").mouseleave( function () { 
		move_speed = init_move_speed;
		moving = false;
	});
	
	$("#scrollingRight").mousedown( function () { 
		move_speed += speed_boost;
	});
	$("#scrollingRight").mouseup( function () { 
		move_speed -= speed_boost;
	});
	
});

function move_left(){
	if( !moving || cur_pos >= 0 ) return ;
	cur_pos += move_speed;
	$("#scrollableArea").animate({ "marginLeft": "+="+move_speed+"px" }, 40 );
	setTimeout( "move_left()", 80 );
}

function move_right(){
	if( !moving || cur_pos <= max_cur_pos ) return ;
	cur_pos -= move_speed;
	$("#scrollableArea").animate({ "marginLeft": "-="+move_speed+"px" }, 40 );
	setTimeout( "move_right()", 80 );
}

function show_big_pict( id ){
	$.post("/ajax.php", { "action_mod": "simple_photo_gallery", "action": "get_pic_info", "id": id },
	function(data){
		$("#big_pict").fadeOut("slow", function () {
			$("#big_pict").attr("src",data.picture);
			$("#pic_desc").html(data.desc);
			$("#pic_href").attr("href", data.href);
			$("#big_pict").fadeIn("slow");
		});
	}, "json");
}