// <!--
var movetimer;
var galery_height = 0;
var galery_parent_height = 0
var galery_small_length = 0;
var slideshowTimer;
var slideshow_delay = 4000;
var slideshowStopped = false;

$(document).ready(function () {
    $(".home-box").mouseover(function () {
        old_src = $($(this).children()[0]).attr("src");
        tmp = old_src.substr(0, old_src.length - 4);
        new_img = (old_src.substr(0, old_src.length - 4) + "-hover" + old_src.substr(old_src.length - 4, 4))
        $($(this).children()[0]).attr("src", new_img);

    });

    $(".home-box").mouseout(function () {
        old_src = $($(this).children()[0]).attr("src");
        tmp = old_src.substr(0, old_src.length - 4);
        new_img = (tmp.substr(0, tmp.length - 6) + "" + old_src.substr(old_src.length - 4, 4))
        $($(this).children()[0]).attr("src", new_img);
    });

    $("#galerieUp").mousedown(function () {
        moveUp();
    })

    $("#galerieUp").mouseup(function () {
        $("#galerie-list-in").stop();
        var top;
        top = $("#galerie-list-in").css("top");
        top = top.substr(0, top.length - 2);
        setCookie("last_galery", top + "px", 1);
        if (top == 0) {
            $("#galerieUp").removeClass("possible");
            $("#galerieUp").attr("src", "./images/galery-top.gif");
        }
    })


    $("#galerieDown").mousedown(function () {
        if ($(this).hasClass("possible")) {
            moveDown();
        }
    })

    $("#galerieDown").mouseup(function () {

        $("#galerie-list-in").stop();


        var top;
        top = $("#galerie-list-in").css("top");
        top = top.substr(0, top.length - 2);
        var height;
        height = $("#galerie-list-in").height();
        move = (height - galery_parent_height)

        setCookie("last_galery", top + "px", 1)

        if (top * (-1) == move) {
            $("#galerieDown").removeClass("possible");
            $("#galerieDown").attr("src", "./images/galery-down.gif");
        }
    })

    $("#galerie-list-in").ready(function () {

        try {
            if (getCookie("last_galery") + "" != "undefined") {
                $("#galerie-list-in").css("top", getCookie("last_galery"));
            }
            var top;
            top = $("#galerie-list-in").css("top");
            top = top.substr(0, top.length - 2);
            var height;
            height = $("#galerie-list-in").height();
            height2 = $("#galerie-list").height();

            if (top == 0) {
                $("#galerieUp").attr("src", "./images/galery-top.gif")
                $("#galerieUp").removeClass("possible")
            }
            if ((-1 * top) == height || height < height2) {
                $("#galerieDown").attr("src", "./images/galery-down.gif")
                $("#galerieDown").removeClass("possible")
            }

        } catch (e) { }
    });

    $(".galerie-item").mouseover(function () {
        $(this).addClass("active2");
    });

    $(".galerie-item").mouseout(function () {
        $(this).removeClass("active2");
    });

    $("#galerieUp").mouseover(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-top-active.gif")
        } else {
            $(this).attr("src", "./images/galery-top.gif")
        }
    });

    $("#galerieUp").mouseout(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-top-possible.gif")
        } else {
            $(this).attr("src", "./images/galery-top.gif")
        }
    });

    $("#galerieDown").mouseover(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-down-active.gif")
        } else {
            $(this).attr("src", "./images/galery-down.gif")
        }
    });

    $("#galerieDown").mouseout(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-down-possible.gif")
        } else {
            $(this).attr("src", "./images/galery-down.gif")
        }
    });

    $("#slideshow").ready(function () {
        slideshowTimer = setTimeout('doNextSlideshow()', slideshow_delay)
    });

    $("#slideshow-posuvnik a").click(function () {
        clearTimeout(slideshowTimer);
        slideshowTimer = setTimeout('doNextSlideshow()', slideshow_delay);
        //$(".tlacitko").removeClass("active");
        $(".tlacitko").each(function () {
            if ($(this).hasClass("active")) {
                $(this).removeClass("active");
                $(this).animate({
                    backgroundColor: '#FCEFD2'
                }, 1000, function () {

                });
            }
        });
        id = $(this).attr("rel")
        $(".item.active").fadeOut(1000, function () {
            $(".item").removeClass("active")
            $("#slideshow_" + id).addClass("active")
            $("#slideshow_" + id).fadeIn(1000);
        });
        $(this).addClass("active");
        $(this).css("background-color", "#FCEFD2");
        $(this).animate({
            backgroundColor: '#FFA415'
        }, 1000, function () {

        });
    });

    $("#slideshow-dw").click(function () {
        if (document.getElementById("slideshow_button_" + ((($(".tlacitko.active").attr("rel")) * 1) + 1))) {
            newId = ((($(".tlacitko.active").attr("rel")) * 1) + 1);
        } else {
            newId = 0;
        }
        $("#slideshow_button_" + newId).trigger('click');
        $(this).trigger("mouseover");
    });

    $("#slideshow-up").click(function () {
        if (document.getElementById("slideshow_button_" + ((($(".tlacitko.active").attr("rel")) * 1) - 1))) {
            newId = ((($(".tlacitko.active").attr("rel")) * 1) - 1);
        } else {
            newId = ($($("#slideshow-posuvnik a").last()).attr("rel"))
        }
        $("#slideshow_button_" + newId).trigger('click');
        $(this).trigger("mouseover");
    });

    $("#slideshow-up").mouseover(function () {
        slideshowStopped = true;
        $(this).attr("src", "./images/slideshow-top-active.gif")
        $(".small_image").removeClass("active");
        if (document.getElementById("slideshow_button_" + ((($(".tlacitko.active").attr("rel")) * 1) - 1))) {
            newId = ((($(".tlacitko.active").attr("rel")) * 1) + 1);
        } else {
            newId = ($($("#slideshow-posuvnik a").last()).attr("rel"))
        }
        /*
        $("#small_image_" + newId).addClass("active");
        $(this).mousemove(function (event) {
        $(".small_image").css("top", event.pageY - 110 + "px");
        $(".small_image").css("left", event.pageX - $("#right").position().left - $("#website").position().left + "px");
        });
        */
    });

    $("#slideshow-up").mouseout(function () {
        slideshowStopped = false;
        $(this).attr("src", "./images/slideshow-top.gif")
        //$(".small_image").removeClass("active");

    });

    $("#slideshow-dw").mouseover(function () {
        slideshowStopped = true;
        $(this).attr("src", "./images/slideshow-bottom-active.gif")
        $(".small_image").removeClass("active");
        if (document.getElementById("slideshow_button_" + ((($(".tlacitko.active").attr("rel")) * 1) + 1))) {
            newId = ((($(".tlacitko.active").attr("rel")) * 1) + 1);
        } else {
            newId = 0;
        }
        /*
        $("#small_image_" + newId).addClass("active");
        $(this).mousemove(function (event) {
        $(".small_image").css("top", event.pageY - 110 + "px");
        $(".small_image").css("left", event.pageX - $("#right").position().left - $("#website").position().left + "px");
        });
        */
    });

    $("#slideshow-posuvnik").mouseout(function () {
        slideshowStopped = false;

    });

    $("#slideshow-posuvnik").mouseover(function () {
        slideshowStopped = true;
    });

    $("#slideshow-dw").mouseout(function () {
        slideshowStopped = false;
        $(this).attr("src", "./images/slideshow-bottom.gif");
        //$(".small_image").removeClass("active");
    });

    $("#slideshow .items").mouseover(function () {
        slideshowStopped = true;
    });

    $("#slideshow .items").mouseout(function () {
        slideshowStopped = false;
    });

    $("#galerySmallLeft").mousedown(function () {
        moveLeft();
    });

    $("#galerySmallRight").mousedown(function () {
        moveRight();
    });

    $("#galerySmallRight").mouseup(function () {
        /*var left;
        left = $("#posuvnik-thumbnails").css("left");
        left = left.substr(0, left.length - 2);
        if (left < 0) {
        $("#posuvnik-thumbnails").css("left", ((left * 1) + 5) + "px");
        movetimer = setTimeout('moveLeft()', 1);
        $("#galerySmallRight").attr("src", "./images/galery-right-small-possible.gif");
        $("#galerySmallRight").addClass("possible");
        } else {
        $("#galerySmallLeft").attr("src", "./images/galery-left-small.gif")
        $("#galerySmallLeft").removeClass("possible");
        }*/
        $("#posuvnik-thumbnails").stop();
    })

    $("#galerySmallLeft").mouseup(function () {
        var left;
        left = $("#posuvnik-thumbnails").css("left");
        left = left.substr(0, left.length - 2);
        if (left < 0) {
            $("#galerySmallRight").attr("src", "./images/galery-right-small-possible.gif");
            $("#galerySmallRight").addClass("possible");
        } else {
            $("#galerySmallLeft").attr("src", "./images/galery-left-small.gif")
            $("#galerySmallLeft").removeClass("possible");
        }
        $("#posuvnik-thumbnails").stop();
    })

    $("#galerySmallRight").mouseout(function () {
        clearTimeout(movetimer);
    })

    $("#galerySmallLeft").mouseout(function () {
        clearTimeout(movetimer);
    })

    $("#galerySmallRight").mouseover(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-right-small-active.gif");
        }
    })

    $("#galerySmallLeft").mouseover(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-left-small-active.gif");
        }
    })

    $("#galerySmallRight").mouseout(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-right-small-possible.gif");
        }
    })

    $("#galerySmallLeft").mouseout(function () {
        if ($(this).hasClass("possible")) {
            $(this).attr("src", "./images/galery-left-small-possible.gif");
        }
    })

    $("#posuvnik-thumbnails .thumbnail").click(function () {
        $("#posuvnik-thumbnails .thumbnail").removeClass("active");
        $(this).addClass("active");
        var rel;
        rel = $(this).attr("rel")
        $(".galery-image.active").fadeOut(500, function () {
            $(".galery-image.active").removeClass("active")
            $("#galery-image-" + rel).addClass("active");
            $("#galery-image-" + rel).fadeIn(500);
        })
    });

    galery_parent_height = $("#galerie-list-in").parent().height();
    galery_height = $("#galerie-list-in").height();
    galery_small_length = (($("#posuvnik-thumbnails").children().length - 4) * -116);

});

function doNextSlideshow() {
    if (!slideshowStopped) {
        if (document.getElementById("slideshow_button_" + ((($(".tlacitko.active").attr("rel")) * 1) + 1))) {
            newId = ((($(".tlacitko.active").attr("rel")) * 1) + 1);
        } else {
            newId = 0;
        }
        $("#slideshow_button_" + newId).trigger('click');
    }
    clearTimeout(slideshowTimer);
    slideshowTimer = setTimeout("doNextSlideshow()", slideshow_delay)
}

function moveRight() {

    var left;
    left = $("#posuvnik-thumbnails").css("left");
    left = left.substr(0, left.length - 2);
    move = (left - galery_small_length)
    speed = (1300 - ((left / galery_small_length)) * 1300);
    $("#galerySmallLeft").attr("src", "./images/galery-left-small-possible.gif");
    $("#galerySmallLeft").addClass("possible");
    $("#posuvnik-thumbnails").animate({
        left: "" + galery_small_length + "px"
    }, speed, function () {
        $("#galerySmallRight").attr("src", "./images/galery-right-small.gif");
        $("#galerySmallRight").removeClass("possible");
    });
}

function moveLeft() {


    var left;
    left = $("#posuvnik-thumbnails").css("left");
    left = left.substr(0, left.length - 2);
    move = (left - galery_small_length)
    speed = (((left / galery_small_length)) * 1300);
    $("#galerySmallRight").attr("src", "./images/galery-right-small-possible.gif");
    $("#galerySmallRight").addClass("possible");
    $("#posuvnik-thumbnails").animate({
        left: "0px"
    }, speed, function () {
        $("#galerySmallLeft").attr("src", "./images/galery-left-small.gif");
        $("#galerySmallLeft").removeClass("possible");
    });
}


function moveUp() {


    var top;
    top = $("#galerie-list-in").css("top");
    top = top.substr(0, top.length - 2);
    var height;
    height = $("#galerie-list-in").height();
    move = (height - galery_parent_height)
    speed = ((-1 * (top / move)) * 1300);
    $("#galerieDown").addClass("possible");
    $("#galerieDown").attr("src", "./images/galery-down-possible.gif")
    $("#galerie-list-in").animate({
        top: "0px"
    }, speed, function () {
        $("#galerieUp").attr("src", "./images/galery-top.gif");
        $("#galerieUp").removeClass("possible");
    });
    
}

function moveDown() {
    var top;
    top = $("#galerie-list-in").css("top");
    top = top.substr(0, top.length - 2);
    var height;
    height = $("#galerie-list-in").height();
    move = (height - galery_parent_height)
    speed = 1300 - ((-1 * (top / move)) * 1300);
    $("#galerieUp").addClass("possible");
    $("#galerieUp").attr("src", "./images/galery-top-possible.gif")
    $("#galerie-list-in").animate({
        top: "-" + move + "px"
    }, speed, function () {
        $("#galerieDown").attr("src", "./images/galery-down.gif");
        $("#galerieDown").removeClass("possible");
    });

    
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}



// -->
