$(function(){
	
	var $sumaCen = 0;
	/*
	$('#przedplata').click(function(){		
		if($(this).is(':checked')){
			$(this).next().fadeIn();
		}else $(this).next().fadeOut();
	});
	*/
	$('.wyswietl').click(function(){
		//$(this).nextAll('.medium').toggle(function(){
			pobierzDane($(this).children().val());
		//});
		
		
	});
	
	$('.pokazMedium').click(function(){
		
		//var $medium = $(this).nextAll('.medium');
		$('.typ1').hide();
		$('.typ2').hide();
		
		//alert($(this).parent().parent().children('.mediumUl').nextAll('.mediumUl').children().attr('class'));
		
		if($(this).nextAll('.medium').is(':hidden')){
			$('.medium').hide();
			$(this).nextAll('.medium').show();
			$(this).parent().parent().children('.mediumUl').children().show();
			$(this).parent().parent().children('.mediumUl').nextAll('.mediumUl').children().show();
			//alert($(this).parent().next().next().children('.medium').attr('class'));
			//$(this).next().next().children('.medium').show();
			//$(this).next('.medium').show();
		}else{
			$(this).nextAll('.medium').hide();
			$(this).parent().parent().children('.mediumUl').children().hide();
			$(this).parent().parent().children('.mediumUl').nextAll('.mediumUl').children().hide();
		}
	});
	$('.pokazTyp1').click(function(){
		$('.typ1').hide();
		$('.typ2').hide();
		$(this).parent().next('.typ1Ul').children('.typ1').show();
		$(this).parent().next().next('.typ1Ul').children('.typ1').show();
		//$(this).parent().parent().children('.typ1Ul').nextAll('.typ1Ul.').children('.typ1').show();
	});
	$('.pokazTyp2').click(function(){
		$('.typ2').hide();
		$(this).next().next().show();
	});
	
	$('.typ1').hover(function(){
		$(this).prev('.' + $(this).attr('id') + '').fadeTo(400,0.85);
	},function(){
		$('.' + $(this).attr('id') + '').fadeOut(200);
	});
	
	$('.typ2').hover(function(){
		$(this).prev('.' + $(this).attr('id') + '').fadeTo(400,0.85);
	},function(){
		$('.' + $(this).attr('id') + '').fadeOut(200);
	});
	
	
	$('.przelicz').keyup(function(){
		$cena = $(this).parent().prev().children().val();
		$ilosc = $(this).val();
		$suma = $cena * $ilosc;
		$(this).parent().next().children().val($suma);
		$(this).parent().next().children().next().html($suma);
		$('.wartosc').each(function(i){
			$sumaCen += parseFloat($(this).val());
		});
		$('#suma').val($sumaCen);
		$('#suma').next().html($sumaCen);
		$sumaCen = 0;
	});
	
	$('.daneZamowienia').bind('keyup blur', function(){
		
		$('input[name=' + $(this).attr('name') + 'Faktura]').val($(this).val());
		
	});
	
	$('.wyczyscLinie').click(function(){
		
		$(this).prev().val('');
		
	});
	
	
});
