	jQuery.fn.generate_item = function( item, div_class, append ) {	
		var html = 
			'<div class="'+div_class+'">'
				+'<a href="'+item.link+'"><img src="'+item.image+'" class="item_img" width="80" height="80" alt="'+item.product_name_alt+'" /></a>'
				+'<div>'
					+'<h2><a href="'+item.link+'">'+item.product_name+'</a></h2>'
					+item.description
					+'<span class="more"><a href="'+item.link+'"><img src="public/images/more-box.png" width="62" height="16" alt="więcej" /></a></span>'
				+'</div>'
				+'<span class="date hidden">'+item.modified+'</span>'
				+'<span class="id hidden '+item.id_product+'">'+item.id_product+'</span>'
			+'</div>';

			if(append) {
				this.append(html);
			} else {
				this.prepend(html);
			}
	};

	jQuery.fn.start_switcher = function( ) {
		var news_box = this;
		var no_prev_db = false;
		var no_next_db = false;
		
		var show = 'new';

		$('#next_product').live( 'click', function() {
			if(!no_next_db) {
				$.ajax({
					type: "POST",
					url: base_url+"pl/ajax/products/main/"+show+"/next.html",		
					dataType: "json",
					async: false,
					data: ({id : $('.boxBorder_'+show).children('div:last').children('.id').html(), date : $('.boxBorder_'+show).children('div:last').children('.date').html()}),
					success: function(data){
						no_next_db = true;
				    	$.each(data, function(i,item){
				    		if(!$('span.'+item.id_product).hasClass('hidden')) {
					    		var div_class = 'hidden';				    		
					    		$('.boxBorder_'+show).generate_item( item, div_class, true );
								no_next_db = false;
				    		}
						});
				    	$('.boxBorder_'+show+' .boxLeft').addClass('hidden').removeClass('boxLeft');
				    	$('.boxBorder_'+show+' .boxRight').addClass('boxLeft');
				    	$('.boxBorder_'+show+' .boxRight').next('div').removeClass('hidden').addClass('boxRight');
				    	$('.boxBorder_'+show+' .boxLeft').removeClass('boxRight');
					}
				});
			} else {
				if($('.boxBorder_'+show+' .boxRight').next('div').hasClass('hidden')) {
			    	$('.boxBorder_'+show+' .boxLeft').addClass('hidden').removeClass('boxLeft');
			    	$('.boxBorder_'+show+' .boxRight').addClass('boxLeft');
			    	$('.boxBorder_'+show+' .boxRight').next('div').removeClass('hidden').addClass('boxRight');
			    	$('.boxBorder_'+show+' .boxLeft').removeClass('boxRight');
				} else {
					$('.boxBorder_'+show+' .boxLeft').addClass('hidden').removeClass('boxLeft');
					$('.boxBorder_'+show+' .boxRight').removeClass('boxRight').addClass('boxLeft');
					
					$('.boxBorder_'+show+'').children('div:first').removeClass('hidden').addClass('boxRight');
				}
			}
		});
		$('#prev_product').live( 'click', function() {
			if(!no_prev_db) {
				$.ajax({
					type: "POST",
					url: base_url+"pl/ajax/products/main/"+show+"/prev.html",		
					dataType: "json",
					async: false,
					data: ({id : $('.boxBorder_'+show).children('div:first').children('.id').html(), date : $('.boxBorder_'+show).children('div:first').children('.date').html()}),
					success: function(data){
						no_prev_db = true;
				    	$.each(data, function(i,item){
				    		if(!$('span.'+item.id_product).hasClass('hidden')) {
				    			var div_class = 'hidden';
					    		$('.boxBorder_'+show).generate_item( item, div_class, false );
				    			no_prev_db = false;
				    		}

						});
						
				    	$('.boxBorder_'+show+' .boxRight').addClass('hidden').removeClass('boxRight');
				    	$('.boxBorder_'+show+' .boxLeft').addClass('boxRight');
				    	$('.boxBorder_'+show+' .boxLeft').prev('div').removeClass('hidden').addClass('boxLeft');
				    	$('.boxBorder_'+show+' .boxRight').removeClass('boxLeft');
					}
				});
			} else {
				if($('.boxBorder_'+show+' .boxLeft').prev('div').hasClass('hidden')) {
				 	$('.boxBorder_'+show+' .boxRight').addClass('hidden').removeClass('boxRight');
			    	$('.boxBorder_'+show+' .boxLeft').addClass('boxRight');
			    	$('.boxBorder_'+show+' .boxLeft').prev('div').removeClass('hidden').addClass('boxLeft');
			    	$('.boxBorder_'+show+' .boxRight').removeClass('boxLeft');
				} else {
					$('.boxBorder_'+show+' .boxRight').addClass('hidden').removeClass('boxRight');
					$('.boxBorder_'+show+' .boxLeft').removeClass('boxLeft').addClass('boxRight');
					
					$('.boxBorder_'+show+'').children('div:last').removeClass('hidden').addClass('boxLeft');
				}
			}
		});

		$('.tab a').live( 'click', function() {
			if($(this).parent('li').attr('id') == 'Nowosci') {
				show = 'new';
				$('.tab').removeClass('on'); 
				$(this).parent('li').addClass('on'); 
				
				$('.boxBorder').addClass('hidden');
				$('.boxBorder_'+show).removeClass('hidden');
			} else {
				show = 'promo';
				$('.tab').removeClass('on'); 
				$(this).parent('li').addClass('on');

				$('.boxBorder').addClass('hidden');
				$('.boxBorder_'+show).removeClass('hidden');
			}
			
			if($('.boxBorder_'+show).html() == '') {
				$.ajax({
					type: "POST",
					url: base_url+"pl/ajax/products/main/"+show+".html",		
					dataType: "json",
					success: function(data){
						$(news_box).removeClass('hidden');
						$('.boxBorder_'+show).removeClass('hidden');
				    	$.each(data, function(i,item){
							var div_class = 'hidden';
					    		if(i == 1) { div_class = 'boxLeft';  }
						    	if(i == 2) { div_class = 'boxRight'; }
				    		$('.boxBorder_'+show+'').generate_item( item, div_class, true );	
						});
					}
				});
			}
		});
	};