jQuery(document).ready(function() {
	
	var position = 0;
	var interval_id = 0;
	var width = 0;
	lock = 1;
	
	jQuery('#nagrody_all .nagroda_photo').each(function() {
		width += jQuery(this).width();
	});
	
	jQuery('#nagrody_all').css('width',width+10);
	
	jQuery('#top_left img').click(function() {
		if(lock ==1) {
			clearInterval(interval_id);
			
			lock = 0;
			
			jQuery('#top_content_text .prod_info:first').before(jQuery('#top_content_text .prod_info:last'));
			jQuery('#top_content_img div:first').before(jQuery('#top_content_img div:last'));
		
			var cur  = jQuery('#top_content_text .vis');
			var prev = cur.prev();
		
			var cur_img  = jQuery('#top_content_img .vis');
			var prev_img = cur_img.prev();
				
			cur.fadeOut('slow',function(){
				cur.removeClass('vis');
				prev.addClass('vis');
				prev.fadeIn('slow');
			});
								
			cur_img.fadeOut('slow',function(){
				cur_img.removeClass('vis');
				prev_img.addClass('vis');
				prev_img.fadeIn('slow',function() {
					lock = 1;
				});
				
			});
			
			interval_id = setInterval('slides()',7000);
		}	
	});
	
	jQuery('#top_right img').click(function() {
		if(lock ==1) {
			clearInterval(interval_id);
			
			lock = 0;
			
			var cur  = jQuery('#top_content_text .vis');
			var next = cur.next();
		
			var cur_img  = jQuery('#top_content_img .vis');
			var next_img = cur_img.next();
		
			cur.fadeOut('slow',function(){
				cur.removeClass('vis');
				next.addClass('vis');
				next.fadeIn('slow');
			});
		
			jQuery('#top_content_text .prod_info:last').after(jQuery('#top_content_text .prod_info:first'));
		
			cur_img.fadeOut('slow',function(){
				cur_img.removeClass('vis');
				next_img.addClass('vis');
				next_img.fadeIn('slow',function(){
					lock = 1;
				});
			});
			
			jQuery('#top_content_img div:last').after(jQuery('#top_content_img div:first'));
			
			interval_id = setInterval('slides()',7000);
		}
	});
	
	jQuery('.arrow_left').click(function() {
						
		if(position < 0) {
			position += 210;
			jQuery('#nagrody_all').animate({'marginLeft':position});
		}
	});
	
	jQuery('.arrow_right').click(function() {
				
		position -= 210;
		
		if(position <= (-1)*width) {
			jQuery('#nagrody_all').animate({'marginLeft':'0'});
			position = 0;
		}
		else
			jQuery('#nagrody_all').animate({'marginLeft':position});
												
	});
	
	interval_id = setInterval('slides()',7000);
	
});

function slides() {
	
	if(lock ==1) {
		lock = 0;
			
		var cur  = jQuery('#top_content_text .vis');
		var next = cur.next();
		
		var cur_img  = jQuery('#top_content_img .vis');
		var next_img = cur_img.next();
		
		cur.fadeOut('slow',function(){
			cur.removeClass('vis');
			next.addClass('vis');
			next.fadeIn('slow');
		});
	
		jQuery('#top_content_text .prod_info:last').after(jQuery('#top_content_text .prod_info:first'));
	
		cur_img.fadeOut('slow',function(){
			cur_img.removeClass('vis');
			next_img.addClass('vis');
			next_img.fadeIn('slow',function(){
				lock = 1;
			});
		});
			
		jQuery('#top_content_img div:last').after(jQuery('#top_content_img div:first'));
	}
}
