function showBig(position)
{
	//alert(position);
	var thumb_array = $('.small_thumb img');
	var link_array = $('.small_thumb');
	array_position = parseInt(position) - 1;
	var thumb = thumb_array[array_position];
	var link = link_array[array_position];
	
	title = thumb.alt;
	img = link.href;
	//alert(img);
	$("#big_img").attr("src",img);
	$("#big_photo").fadeIn("normal");
	//alert(title);
	$("#big_photo #big_title").html(title);
	$("#big_photo #big_close").click(function(event)
	{
		event.preventDefault();
		$("#big_photo").fadeOut("normal");
	});
	var count = thumb_array.length;
	///manage next one
	$("#big_next").hide();
	if(position < count)
	{
		var next =  parseInt(position) + 1;
		$("#big_next").attr("rel",next);
		$('#big_next').unbind('click');
		$("#big_next").click(function(event)
		{
			event.preventDefault();
			var new_position = $(this).attr("rel");
			showBig(new_position);
		});
		$("#big_next").show();
	}
	///manage previous
	$("#big_prev").hide();
	if(position > 1)
	{
		
		var prev =  parseInt(position) - 1;
		$("#big_prev").attr("rel",prev);
		
		$('#big_prev').unbind('click');
		$("#big_prev").click(function(event)
		{
			event.preventDefault();
			var new_position = $(this).attr("rel");
			showBig(new_position);
		});
		$("#big_prev").show();
	}
	
}




$(document).ready(function(){

	$(".photo_thumb").mouseenter(function()
	{
		$(".photo_thumb_big").hide();
		$(this).children(".photo_thumb_big").show();
	});
	$(".photo_thumb").mouseleave(function()
	{
		$(this).children(".photo_thumb_big").hide();
	});
	$(".photo_thumb a").click(function(event)
	{
		event.preventDefault();
		var position = $(this).attr("rel");
		///alert(position);
		showBig(position);
	});
	$("#submit_gallfilter").hide();
	
	
	
	$("#gal_form select").change(function(){
		$("#gal_form").trigger("submit");
	});
	
	
	
	
	
	
	$(document).keypress( function(e){
		if($("#big_photo").is(':visible')) {
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
				if(key == 37 && $("#big_prev").is(':visible'))
				{
					var new_position = $("#big_prev").attr("rel");
					showBig(new_position);
				}
			   //alert(key);
				if(key == 39 && $("#big_next").is(':visible'))
				{
					var new_position = $("#big_next").attr("rel");
					showBig(new_position);
				}
				if(key == 27)
				{
					$("#big_photo").fadeOut("normal");
				}
			}
	});

	
	
});