$(document).ready(function(){
var wMaly = 100;
var wMalyTop = 50;
var WDuzy = 200;
    var czas = 250;
    var gal = -1;
    var gallength;
    function dodaj_nr_id(element){
        for (var i = 0; i < element.length; i++) {
            $(element[i]).attr('id', 'g' + (i + 1));
            gallength = element.length;
            $("#g" + (i + 1)).css({
                left: '660px'
            });
            //$(element[i]).addClass('d'+i);
        }
    }
    dodaj_nr_id($("#gallery a img").get());
    
    function start(){
        gal++;
        $("#g" + (gal + 1)).animate({
            left: "0px",
			top:wMalyTop,
            width: wMaly,
            height: wMaly
        }, czas);
        $("#g" + (gal + 2)).animate({
            left: "130px",
            width: WDuzy,
            height: WDuzy
        }, czas);
        $("#g" + (gal + 3)).animate({
            left: "360px",
			top:wMalyTop,
            width: wMaly,
            height: wMaly
        }, czas);
    }
	function one(){
        $("#g" + (gal + 1)).animate({
            left: "130px",
			top: "0px",
            width: WDuzy,
            height: WDuzy
        }, czas);
       
    }
    start();
    if(gallength<2){
		one();
	}
    
    $("#br").click(function(){
        if (gal < gallength - 2) {
            gal++;
            $("#g" + (gal)).animate({
                left: "-200px",
                width: wMaly,
                height: wMaly
            }, czas);
            $("#g" + (gal + 1)).animate({
                left: "0px",
				top:wMalyTop,
                width: wMaly,
                height: wMaly
            }, czas);
            $("#g" + (gal + 2)).animate({
                left: "130px",
				top: "0px",
                width: WDuzy,
                height: WDuzy
            }, czas);
            $("#g" + (gal + 3)).animate({
                left: "360px",
				top:wMalyTop,
                width: wMaly,
                height: wMaly
            }, czas);
            var kategoria = $("#g" + (gal + 2)).attr('class');
            kateg(kategoria);
        }
    });
    
    
    $("#bl").click(function(){
        if (gal > -1) {
            gal--;
            $("#g" + (gal + 1)).animate({
                left: "0px",
				top:wMalyTop,
                width: "100px",
                height: "100px"
            }, czas);
            $("#g" + (gal + 2)).animate({
                left: "130px",
				top: "0px",
                width: "200px",
                height: "200px"
            }, czas);
            $("#g" + (gal + 3)).animate({
                left: "360px",
				top:wMalyTop,
                width: "100px",
                height: "100px"
            }, czas);
            $("#g" + (gal + 4)).animate({
                left: "500px",
                width: "100px",
                height: "100px"
            }, czas);
            var kategoria = $("#g" + (gal + 2)).attr('class');
            kateg(kategoria);
        }
    });
    
});

