function add (var_id,foto,nazwa,cena)
{
	$('body').append('<div id="light" class="white_content"><img src="'+foto+'" /><p>Dodales do koszyka:</p> <strong>'+nazwa+'</strong> <b> Cena: '+cena+' zl </b><div class="buttons"><a href="javascript:void(0);" class="box_close button">Kontynuuj zakupy</a></div></div><div id="fade" class="black_overlay"></div>');
	$('#fade')
	.css('display','none')
	.css('position','fixed')
	.css('top','0%')
	.css('left','0%')
	.css('width','100%')
	.css('height','100%')
	.css('background-color','black')
	.css('z-index','1001')
	.css('opacity','.8')
	.css('filter','alpha(opacity=80)');
	
	$('#light')
	.css('display','none')
	.css('position','fixed')
	.css('top','50%')
	.css('left','50%')
	.css('width','600px')
	.css('height','260px')
	.css('margin','-100px 0 0 -130px')
	.css('z-index','1002')
	.css('overflow','hidden');
	
	
	
	$('.white_content').livequery(function(){
		$('.white_content').load("/ajax.dodaj_opakowanie.php",{"id":var_id,"foto":foto,"nazwa":nazwa,"cena":cena},function(){
			$('#fade').fadeIn('slow');
			$('#light').fadeIn('slow');
			
		});
	});
	
}

function dodaj(var_id,foto,nazwa,cena,opakowanie,opakowanie_id)
{
			//$('#light').remove();
			//$('#fade').remove();
	
	
	$('body').append('<div id="light" class="white_content"><img src="/foto/mini/'+foto+'" /><p>Dodales do koszyka:</p> <strong>'+nazwa+'</strong> <b> Cena: '+cena+' zl </b><div class="buttons"><a href="javascript:void(0);" class="box_close button">Kontynuuj zakupy</a><a href="javascript:void(0);" class="button" onclick="document.location=\'/koszyk_pokaz.html\'">Finalizuj zamowienie</a></div></div><div id="fade" class="black_overlay"></div>');
	$('#fade')
	.css('display','none')
	.css('position','fixed')
	.css('top','0%')
	.css('left','0%')
	.css('width','100%')
	.css('height','100%')
	.css('background-color','black')
	.css('z-index','1001')
	.css('opacity','.7')
	.css('filter','alpha(opacity=70)');
	
	$('#light')
	.css('display','none')
	.css('position','fixed')
	.css('top','50%')
	.css('left','50%')
	.css('width','400px')
	.css('height','350px')
	.css('margin','-175px 0 0 -200px')
	.css('z-index','1002')
	.css('overflow','hidden')
	.css('background-color','black');
	
	$('#fade').fadeIn('slow');
	$('#light').fadeIn('slow');
	
	 
	//$('.white_content').livequery(function(){
		$('.white_content').load("/ajax.dodaj_opakowanie2.php",{"id":var_id,"foto":foto,"nazwa":nazwa,"cena":cena,"opakowanie_id":opakowanie_id},function(){
			$('#fade').fadeIn('slow');
			$('#light').fadeIn('slow');
			
		});	
	//});	
			
	$('.koszyk').html('<p>&nbsp;<br /><strong>&nbsp;</strong></p>');
	$('.koszyk').css('background-image','url(/img/ajax-loader.gif)')
	.css('background-position','center')
	.css('background-repeat','no-repeat');
	
	$('#koszyk').load("/ajax.basket.add.item.php",{"id":var_id,"opakowanie":opakowanie},function(){
		$(this).hide();
		$(this).fadeIn();
	});
}


function simple_tooltip(target_items, name){
	 $(target_items).each(function(i){
		 
			$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
			var my_tooltip = $("#"+name+i);
			
			$(this).removeAttr("title").mouseover(function(){
					//my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
					my_tooltip.css({opacity:0.8, display:"none"}).show();
			}).mousemove(function(kmouse){
					if(kmouse.pageX+300 < window.innerWidth) {
						my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
					} else {
						my_tooltip.css({left:kmouse.pageX-270, top:kmouse.pageY+15});
					}
			}).mouseout(function(){
					//my_tooltip.fadeOut(400);				  
					my_tooltip.hide();
			});
			
		});
	}


$(document).ready( function(){
	
	 /* if (document.readyState != "complete"){
		    setTimeout( arguments.callee, 100 );
		    return;
	  }*/ 
	  
	 // alert ('ala');
	  
	$('.lightbox a').lightBox();
/*
	$('.images li:first-child .powieksz').fadeTo('slow', 0.4);
	$('.hide').hide();

	$('.powieksz').click(function(){
		var foto = $(this).find('span').text();
		$('.powieksz').fadeTo('slow', 1);
		$(this).fadeTo('slow', 0.4);
		$('#sredni').fadeOut('slow',function(){
			$('#sredni').find('a.zmien').attr('href','foto/big/'+foto);
			$('#sredni').find('a.zmien img').attr('src','foto/midi/'+foto);
			$(this).fadeIn('slow');
		});
	});
*/
	
	
	
	
	
	
	$('.finalizuj').livequery(function(){
		$('.finalizuj').click(function(){
			//alert ('ala');
			document.location='/koszyk_pokaz.html';
			
		});
	});
	
	// zmiana opakowania
	$('.opak').livequery(function(){
		$('.opak').click(function(){
			$('.opak').removeClass('opakWybrane');					  
			//alert($(this).find('span').text());
			$(this).addClass("opakWybrane");
			//$("#debug").text($(this).find('span').text());
			$("#kup").html('<a href="javascript:void(0);" class="but" onclick="dodaj('+$('#id').text()+',\''+$("#foto").text()+'\',\''+$('#nazwa').text()+'\',\'12.00\',\''+$(this).find('span').text()+'\',\''+$(this).find('b').text()+'\')" >KUPUJ�!</a>');
		});
	});
	
	// zmiana opakowania end
	
	
	
	$('.box_close').livequery(function(){
		$('.box_close').click(function(){
			$('#fade').fadeOut('slow',function(){
				$('#fade').remove();
			});
			$('#light').fadeOut('slow',function(){
				$('#light').remove();
			});
			//$('#light').remove();
			//$('#fade').remove();
		});
	});
	

	$("#vat_button").click(function(){
		$('#vat').slideToggle();
	});
	$("#uwagi_button").click(function(){
		$('#uwagi').slideToggle();
	});
	
		 
		 //simple_tooltip(".tol","tooltip"); 
	
	
				if ($("input[name='dostawa']:checked").val()==undefined)
				{
					$('.butDalej').hide();
				}
				else
				{
					$('.butDalej').show();
				}
				
				$("input[name='dostawa']").click(function(){
					$('.butDalej').show();
				});
				
				//alert ($("input[name='dostawa']:checked").val());
				
		
		/* Podgląd miniaturek
		**********************/
	
		imagePreview();
			
		/*    Gallery
		****************************/
		
		
		
		// preload

		var arr = $.makeArray($('#images .mini a'));

		$(arr).each(function(index) {
			var image = new Image();
			image.src = this.href;
			
			

		});

		function first_image() {
			var img1_width = $('#images .big img').width();
			var img1_height = $('#images .big img').height();
			var href1 = $('#images .big img').attr('src');
			
			$('#images .big .bg').width(img1_width).height(img1_height).css('background-image', 'url('+href1+')');
			$('#images .big img').removeAttr('width').removeAttr('height');
		}
		
		//$('#images .big .bg img').load(function() {
			first_image();
		//});

		$('#images .mini a:eq(0)').addClass('active');
				
		/* klikamy na miniaturke */

		$('#images .mini a').live('click', function(){

			if($(this).hasClass('active'))
				return false;
				

			
			$('#images .mini a').removeClass('active');
			$(this).addClass('active');
													  
			var href = $(this).attr('href');
			
			$('#images .big img').fadeOut(0, function(){
												   
				var this_big_image = $(this);
				this_big_image.attr('src', href);
				
				$(this).fadeIn('fast');
					var img_width = this_big_image.width();
					var img_height = this_big_image.height();
					
					$('#images .bg').animate({
												width: img_width,
												height: img_height
											}, 200, function(){
												first_image();
											});
			});
			
			return false;
			
		});

		/*****************************************/
		/*$('#koszty-dostaw label').hide();*/
		
		var isChecked = 0;
		
		/* onload */
		$('#koszty-dostawy input:radio').each(function(index, value){
			if ($(this).attr('checked')) {
				$(this).parent().parent().parent().addClass('active');
				isChecked = 1;
			} else {
				$(this).parent().parent().parent().removeClass('active');
			}
		});
		
		if(isChecked) {
			$('.stop').fadeTo('fast', 1).removeClass('stop');
			$('.stop-alert').fadeOut();
		}
		
		
		
		/* click */
		
		$("#koszty-dostawy label").click(function() {

			
			$('#koszty-dostawy input:radio').each(function(index, value){
				if ($(this).attr('checked')) {
					$(this).parent().parent().parent().addClass('active');
					isChecked = 1;
				} else {
					$(this).parent().parent().parent().removeClass('active');
				}
			});
			
			if(isChecked) {
				$('.stop').fadeTo('fast', 1).removeClass('stop');
				$('.stop-alert').fadeOut();
			}
		});

		$('.stop-alert').hide();
		
		if(!isChecked)
			$('.stop').fadeTo('fast', 0.5);

		$('.stop').live('click', function(){
			$(".stop-alert:visible").fadeOut('fast');
			$('.stop-alert').fadeIn('fast');
			return false;
		});
		
});