$(document).ready(function() {
	$lenta_cur = $(".lenta > DIV.cur");
	$arrow_next = $(".lentaBlock > .next");
	$arrow_prev = $(".lentaBlock > .prev");	
	
	$arrow_next.click(function() {
		if($(".lenta > DIV.cur").next().html() != null){
			console.log($lenta_cur.next().html());
			$(".lenta > DIV.cur").removeClass('cur').css('display','none').next().addClass('cur').css('display','block');
			change_arrows($lenta_cur);
		}
	});
	
	$(".lentaBlock > .prev").click(function() {
		if($(".lenta > DIV.cur").prev().html() != null){
			$(".lenta > DIV.cur").removeClass('cur').css('display','none').prev().addClass('cur').css('display','block');
			change_arrows($(".lenta > DIV.cur"));
		}		
	});	
	
	function change_arrows(element_selector){
		if(element_selector.parent().find('.cur').next('div').html() == null){
			$arrow_next.fadeOut();
		}else{
			$arrow_next.fadeIn();			
		}
		if(element_selector.parent().find('.cur').prev('div').html() == null){
			$arrow_prev.fadeOut();
		}else{
			$arrow_prev.fadeIn();			
		}		
	}
	$('.preview IMG').click(function() {
		img_id = $(this).parent().attr('id').split('_')[2];
		$img_selected = $("#big_img_" + img_id);
		$(".lenta > div").removeClass('cur').css('display','none');
		$img_selected.addClass('cur').css('display','block');
		change_arrows($img_selected);	
	});
	
	$('input, textarea').not('input[type="radio"], input[type="select"], input[type="img"]').focus(function() {
			if ($(this).val().trim() == ''){
				$(this).parent('div').find('label').css('display','none');
			}		
	}).blur(function(){
		if ($(this).val().trim() == ''){
			$(this).parent('div').find('label').css('display','');
		}		
	});
});

