﻿
var open = false;

$(document).ready(function() {


    $(".Block").hover(
        function() {
            $(this).children('div.BlockText').animate({ top: '0px' }, 250);
        },
        function() {
            $(this).children('div.BlockText').animate({ top: '-400px' }, 250);
        });

    $(".Block span.LightGreen").click(
        function() {
    window.location = $('#BlockLightGreen').attr('href');
    });

    $("#DivLightGreen").click(
        function() {
            window.location = $('#BlockLightGreen').attr('href');
        });

        $(".Block span.Green").click(
        function() {
            window.location = $('#BlockGreen').attr('href');
        });

        $("#DivGreen").click(
        function() {
            window.location = $('#BlockGreen').attr('href');
        });

        $(".Block span.DarkGreen").click(
        function() {
        window.location = $('#BlockDarkGreen').attr('href');
        });

        $("#DivDarkGreen").click(
        function() {
        window.location = $('#BlockDarkGreen').attr('href');
        });
});


var shownindex = 0;

function scrollToPhoto(index) {
    clearInterval(intBanner);
    var distance = 0;

    if (shownindex < index) {
        distance = (index - shownindex) * 950;
        Scroll('scrollContainer', -distance);
    }
    else {
        distance = (shownindex - index) * 950;
        Scroll('scrollContainer', distance);
    }

    $(".NumberActive").each(function() {
        $(this).removeClass();
        $(this).addClass("Number");
    });
    

    
    var nmb = document.getElementById("number-" + (index));
    if (nmb != null) {
        nmb.className = "NumberActive";
    }
    
    shownindex = index;
}


var m = 0;
function Scroll(controlId, distance) {
    $("#" + controlId).stop(true,true);
    calculateMargin(controlId);
    $("#" + controlId).animate({ marginLeft: (m + distance) + "px" }, 1250);
}

function calculateMargin(controlId) {
    m = Number($("#" + controlId).css("margin-left").replace('px', ''));
    if (isNaN(m)) {
        m = 0;
    }
    return true
}

var intBanner = setInterval("showNextBanner()", 7500);

function showNextBanner() {
    var max = document.getElementById("hfMax");
    if (max != null) {
        if (shownindex < max.value)
            scrollToPhoto(shownindex + 1);
        else
            scrollToPhoto(0);
        intBanner = setInterval("showNextBanner()", 7500);
    }
}

