
$(document).ready(function() {

    var cont1 = 1;
    var cont2 = 2;
    var numbrOfSlides = $("div[id^='v-fade-']").length;

 //   alert(numbrOfSlides);

    function automat() {
        $('#v-fade-' + cont2).fadeIn("slow");
        $('#v-fade-' + cont1).fadeOut("slow");

        cont1++;
        cont2++;
        if (cont1 == (numbrOfSlides+1)) cont1 = 1;
        if (cont2 == (numbrOfSlides + 1)) cont2 = 1;
    }

    var id = setInterval(automat, 10000);

    $("a[id^='home-']").mouseover(function() {
        var title = $(this).attr("id");
        var itemNumber = title.charAt(title.length - 1);

        if ($(this).hasClass('this-seg') == false) {
            id = window.clearInterval(id);

            //  alert(itemNumber + " - " + title + " - " + title.charAt(title.length - 1));
            var temp = ""
            for (i = 1; i < (numbrOfSlides + 1); i++) {
                if (i != itemNumber)
                    temp += "#v-fade-" + i + ",";

            }
            temp = temp.substring(0, temp.length - 1);
            //    alert(temp);
            $(temp).fadeOut("slow");
            $('#v-fade-' + itemNumber).fadeIn("slow");

            $(this).toggleClass('this-seg');
            if (itemNumber == numbrOfSlides)
                $(this).css("width", "auto")

            var temp = ""
            for (i = 1; i < (numbrOfSlides + 1); i++) {
                if (i != itemNumber)
                    temp += "#home-" + i + ",";
            }
            temp = temp.substring(0, temp.length - 1);
            //    alert(temp);
            $(temp).removeClass('this-seg');
        }
    });
});
