/**
 * Suwak poziomy o ustalonych pozycjach
 */
$(document).ready(function() {
	var items = $('#gallery-in li').length;
	var width = 414;
	var itemWidth = Math.floor(width/items);
	var sliderWidth = $('#scroll-slider').width();
	var slideWidth = width-sliderWidth;
	var currentItem = 0;
	
	check(currentItem);
	
	function check(currentItem) {
		switch (currentItem) {
			case 0:
				$('#slide-left').css({
					'background-image' : 'none',
					'background-color' : '#c7baa7',
					'cursor' : 'default'
				});
				break;
			case (items - 2):
				$('#slide-right').css({
					'background-image' : 'none',
					'background-color' : '#c7baa7',
					'cursor' : 'default'
				});
				break;
			default:
				$('#slide-left').css({
					'background-color' : 'transparent',
					'cursor' : 'pointer'
				});
				$('#slide-right').css({
					'background-color' : 'transparent',
					'cursor' : 'pointer'
				});
		}
	}
	
	function slideTo(item) {
		$('#gallery-in').stop().animate({'margin-left': -width*item + 'px'});
	}
	
	$('#slide-left').mouseenter(function(){
		if(currentItem > 0) {
			$(this).css('background',"url('public/style/slide-left-h.gif') no-repeat");
		}
	});
	
	$('#slide-left').mouseleave(function(){
		if(currentItem > 0) {
			$(this).css('background','none');
		}
	});
	
	$('#slide-right').mouseenter(function(){
		if(currentItem < items - 2) {
			$(this).css('background',"url('public/style/slide-right-h.gif') no-repeat");
		}
	});
	
	$('#slide-right').mouseleave(function(){
		if(currentItem < items - 2) {
			$(this).css('background','none');
		}
	});
	
	$('#slide-left').click(function(){
		if(currentItem > 0) {
			currentItem = currentItem - 1;
			check(currentItem);
			slideTo(currentItem);
		}
	});
	
	$('#slide-right').click(function(){
		if(currentItem < items - 2) {
			currentItem = currentItem + 1;
			check(currentItem);
			slideTo(currentItem);
			
		}
	});
	
	setInterval(function() {
		if(currentItem < items - 2) {
			currentItem = currentItem + 1;
			check(currentItem);
			slideTo(currentItem);
			
		} else {
			currentItem = 0;
			check(currentItem);
			slideTo(currentItem);
		}
	}, 5000);
});

