jQuery(document).ready(function() {
				
		var interval_id = 0;
		var brand_show = 0;
		var map_show = 0;
		var width_all = 0;
		
		if(jQuery('#promocje a').length > 1)
			lock = 1;
		else 
			lock = 0;
		
		if(jQuery('#promocje a').length == 2) {
				var first = jQuery('#promocje a:first');
				var next = first.next('a');
				
				jQuery('#promocje').append(first.clone());
				jQuery('#promocje').append(next.clone());
		}
		
		jQuery('#promocje a').each(function() {
			width_all += jQuery(this).width();
		});
		
		if(jQuery('#promocje a').length > 1) {
			jQuery('#promocje').css('width',width_all+10);
			jQuery('#promocje a:first').before(jQuery('#promocje a:last'));
			jQuery('#promocje').css('marginLeft',-jQuery('#promocje a:first').width());
		}
		
		/* Obsługa górnego menu promocji */
		jQuery('.left_arrow img').click(function() {
			if(lock == 1) {
				lock = 0;
				clearInterval(interval_id);			
				
				var move = jQuery('#promocje a:first').width();
				var margin = jQuery('#promocje a:last').width();
						
				jQuery('#promocje').animate({'marginLeft': '+='+move},500,function(){
						jQuery('#promocje a:first').before(jQuery('#promocje a:last'));
						jQuery('#promocje').css('marginLeft',-margin);
						interval_id = setInterval('slide()',5000);
						lock = 1;
					});				
			}
		});
				
		jQuery('.right_arrow img').click(function() {
			if(lock == 1) {
				lock = 0;
				clearInterval(interval_id);
			
				var move = jQuery('#promocje a:first').next().width();
					
					jQuery('#promocje').animate({'marginLeft': '-='+move},500,function(){
						jQuery('#promocje a:last').after(jQuery('#promocje a:first'));
						jQuery('#promocje').css('marginLeft',-move);
						interval_id = setInterval('slide()',5000);
						lock = 1;
					});
			}
		});
		
		/* Koniec obsługi górnego menu promocji */
		
		/* Obsługa galerii w boxach */
		
		jQuery('.box_right_arrow').click(function() {
			var photos = jQuery(this).prev('.content_box_gallery').children('.content_box_photos');
			var count = photos.children('a').length;
			var width = count * 100;
			var position = (count - 3) * (-90);
			
			photos.css('width', width);
			
			var cur_pos = parseInt(photos.css('marginLeft').replace('px',''));
			
			if(cur_pos > position)
				photos.animate({'marginLeft': '-=90'});
		});
		
		jQuery('.box_left_arrow').click(function() {
			var photos = jQuery(this).next('.content_box_gallery').children('.content_box_photos');
			var position = photos.css('marginLeft').replace('px','');
			if(parseInt(position) < 0)
				photos.animate({'marginLeft': '+=90'});
			
		});
		
		/* Koniec obsługi galerii w boxach */
		
		/* Obsługa aktualności w boxach */
		
		jQuery('.box_news_right_arrow').click(function() {
			var newsy = jQuery(this).prev('.content_box_newsy').children('.content_box_news');
			var count = newsy.children('.aktualnosc').length;
			var width = count * 260;
			var position = (-1) * width + 260;
			
			newsy.css('width', width);
			
			var cur_pos = parseInt(newsy.css('marginLeft').replace('px',''));
			
			if(cur_pos > position)
				newsy.animate({'marginLeft': '-=260'});
		});
		
		jQuery('.box_news_left_arrow').click(function() {
			var newsy = jQuery(this).next('.content_box_newsy').children('.content_box_news');
			var position = newsy.css('marginLeft').replace('px','');
			if(parseInt(position) < 0)
				newsy.animate({'marginLeft': '+=260'});
			
		});
		
		/* Koniec obsługi galerii w boxach */
		
		/* Rozwijanie paska wszystkich marek */
			
		jQuery('#more_brands').click(function() {
			if (brand_show == 0) {
				jQuery('#top_brands').slideDown('slow');
				brand_show = 1;
			} else {
				jQuery('#top_brands').slideUp('slow');
				brand_show = 0;
			}
		});
		
		/* Koniec rozwijania paska wszystkich marek */
		
		/* Rozwijanie mapy strony */
		
		jQuery('#more_map_site').click(function() {
			if (map_show == 0) {
				jQuery('#footer_map_site').slideDown('slow');
				map_show = 1;
			} else {
				jQuery('#footer_map_site').slideUp('slow');
				map_show = 0;
			}
		});
		
		/* Koniec rozwijania mapy strony */
		interval_id = setInterval('slide()',5000);
});

function slide() {
	if(lock == 1) {
		lock = 0;
							
		var move = jQuery('#promocje a:first').next().width();
					
		jQuery('#promocje').animate({'marginLeft': '-='+move},500,function(){
			jQuery('#promocje a:last').after(jQuery('#promocje a:first'));
			jQuery('#promocje').css('marginLeft',-move);
			interval_id = setInterval('slides()',5000);
			lock = 1;
		});
	}
}


