$(document).ready(function() {
	var count = $(".sel_image:checked").length;

	calc(count);

	$(".sel_image").click(function(){		var ncount = $(".sel_image:checked").length;		calc(ncount);	});

	$(".toggle_photos_menu").click(function(e){		e.preventDefault();		$("#menu_sel li").removeClass("active");
		$(this).parent("li").addClass("active");
		$(".layer_photos").hide();
		var id = $(this).parent().children("#id_container").val();
		$("#cont_photos"+id).show();
		$(".big_image img").fadeOut(300,function(){			var src = $(".fst_img"+id).val();
			var replaced = '<img src="'+src+'" alt="" />';

			$(".big_image").empty().append(replaced);
			/*if ($.browser.opera){
				$(".big_image").empty().append(replaced);
			}else{
				$(replaced).load(function(){
					$(".big_image").empty().append(replaced);
					$("#big_image").fadeIn(600);
				});
			}*/
		});	});

	$(".toggler_small_img").click(function(){		var obj = $(this);
		var src = obj.parent().children("input").val();
		var replaced = '<img src="'+src+'" alt="" />';

		$(".big_image img").fadeOut(300,function(){			$(".big_image").empty().append(replaced);
			/*if ($.browser.opera){				$(".big_image").empty().append(replaced);
			}else{				$(replaced).load(function(){
					$(".big_image").empty().append('<div>'+replaced+'</div>');
					$(".big_image img").show();
				});
			}*/
		});
	});
});

function calc(c){	if (c && c > 0){
		$("#results_list").show();
		$("#no_results").hide();

		var s_id = '';
		var s_price = 0;
		var s_time = 0;
		var s_all_photos = 0;
		var s_verif_photos = 0;
		var s_comment = $("#hidden_text").val()+'<br />';

		$(".sel_image:checked").each(function(){			var id = $(this).val();
			var sort = $("#por_sort"+id).val();
			s_id += sort+', ';
			var price = parseFloat($("#por_price"+id).val());
			if (!isNaN(price)){s_price += price;}
			var time = parseFloat($("#por_time"+id).val());
			if (!isNaN(time)){s_time += time;}
			var all_photos = parseInt($("#all_photos"+id).val());
			if (!isNaN(all_photos)){s_all_photos += all_photos;}
			var verif_photos = parseInt($("#verif_photos"+id).val());
			if (!isNaN(verif_photos)){s_verif_photos += verif_photos;}
			var comment = $("#comment"+id).val();
			if (comment !== ""){s_comment += '<br />'+comment+'<br />';}		});

		$("#por_sel_ids").empty().append(s_id);
		$("#por_sel_time").empty().append(s_time);
		$("#por_sel_price").empty().append(s_price);
		$("#por_sel_allphotos").empty().append(s_all_photos);
		$("#por_sel_verif").empty().append(s_verif_photos);
		$("#por_sel_comment").empty().append(s_comment);
	}else{
		$("#results_list").hide();
		$("#no_results").show();
	}
}
