﻿$(document).ready(function() {
    $(".image img").reflect({ height: 0.2, opacity: 0.3 });
    var numImgs = $(".container > div").size();
    var animate = false;
    var defLength = 103;

    $("#btn_navRight").click(function() {
        right();
    });

    function right() {
        if (!animate) {
            animate = true;
            var marginLeft = $(".container").css("marginLeft").replace("px", "");
            var newLeft = Math.floor(marginLeft - defLength);

            if (marginLeft > -(defLength * (numImgs - 8)))
                $(".container").animate({ marginLeft: "" + newLeft + "px" }, 200, function() { animate = false; });
            else
                animate = false;
        }
    }

    $("#btn_navLeft").click(function() {

        left();
    });

    function left() {

        if (!animate) {
            animate = true;
            var marginLeft = $(".container").css("marginLeft").replace("px", "");
            var newLeft = Math.floor(parseInt(defLength) + parseInt(marginLeft));

            if (marginLeft < 0)
                $(".container").animate({ marginLeft: "" + newLeft + "px" }, 200, function() { animate = false; });
            else
                animate = false;

        }

    }

    $(".image").click(function() {
        var url = $(this).attr("alt");
        window.location = url;
    });



    $(".container").mouseleave(function() {
        $(".image div").fadeTo(500, 1);
    });

    $(".image div").mouseover(function() {

        $(".image div").attr("class", "ua");
        $(this).attr("class", "aa");
        $(".image div.ua").fadeTo(20, 0.8);
        $(".image div.aa").fadeTo(20, 1);
    });

    $(".image div").mouseout(function() {
        $(this).attr("class", "ua");
    });


    $(document).keydown(function(event) {

        if (event.keyCode == 37) {
            left();
        }

        if (event.keyCode == 27) {
            if ($('.kundcase').is(':visible')) {
                $(".kundcase").hide();
            }
            else {
                $(".kundcase").show();
            }
        }

        if (event.keyCode == 39) {
            right();
        }
    });

});
