$(document).ready(function(){

		$('#prev').click(function(){	
			var arr_photo = $('#photos').children('div');
			for(i=0,n=arr_photo.length;i<n;i++){
				if ($(arr_photo[i]).css('display') == 'block'){
					$(arr_photo[i]).hide();
					if($(arr_photo[i]).prev().length){
						$(arr_photo[i]).prev().fadeIn();
						$('.head').text($(arr_photo[i]).prev().children('table').children('tbody').children('tr').children('td').children('img').attr('alt'));
					}else{
						$(arr_photo[n-1]).fadeIn();
						$('.head').text($(arr_photo[n-1])().children('table').children('tbody').children('tr').children('td').children('img').attr('alt'));
					}
					break;
				}
			}
			return false;
		});
		
		$('#next').click(function(){	
			var arr_photo = $('#photos').children('div');
			for(i=0,n=arr_photo.length;i<n;i++){
				if ($(arr_photo[i]).css('display') == 'block'){
					$(arr_photo[i]).hide();
					if($(arr_photo[i]).next().length){
						$(arr_photo[i]).next().fadeIn();
						$('.head').text($(arr_photo[i]).next().children('table').children('tbody').children('tr').children('td').children('img').attr('alt'));
					}else{
						$(arr_photo[0]).fadeIn();
						$('.head').text($(arr_photo[0]).children('table').children('tbody').children('tr').children('td').children('img').attr('alt'));
					}
					break;
				}
			}
			return false;
		});
		
		$('#cat1').change(function(){
			$('select[name=cat2]').children('optgroup').hide();
			$('#cat2_'+$(this).val()).show();
		});
		
		$(".add_comm").fancybox({
			'speedOut' : 100
		});

});

function SetStar(id,vote){
	$.post('/ajax/setStar.php','id='+id+'&vote='+vote,function(result){
		$('#total_'+id).text(result.vote);
		$('#count_'+id).text(result.count);
	},'json');
}
function OpenBlockVote(id){
	$('#arh_vote_'+id).slideToggle();
}

function canVoting(parent){

	id = $('input[name=item]:checked').val();
	$.post('/ajax/canVoting.php','id='+id+'&parent='+parent,function(result){
	
		// добавляем id в куки
		var arr = new Array();
		if($.cookie("vote")){
			arr = eval('(' + $.cookie("vote") + ')');
		}
		arr[arr.length]=result.id;
		var jarr = JSON.stringify(arr);
		$.cookie("vote",jarr,{expires: 360});
		//
	
		$('#left_vote').html(result.text);
	},'json');
}

function addcomment(id,module){
	jQuery.post('/ajax/addcomment.php', 'comment_text='+jQuery('#comment_text_'+id).val() + '&id='+id +'&module='+module, function(result){
		jQuery('#block_comm_'+id).html(result);
	});
}

function comment_len(id){
	var len = $(id).val().length;
	var lentxt = len + ' символов ('+ ($('input[name=comm_len_max]').val() - len)  +' осталось)';
	$('#comm_len').text(lentxt);
}











