// rychlost animace vlastnosti
var speedAnimate = 4000;
var indexProperty = 0;

// animace fotek
var property_animate;
var property_hover = false;

$(document).ready(function() {
    // tooltip
    if (document.getElementById("properties-list")) {
        $("#properties-list li span").cluetip({splitTitle: ' | '});
    }
    
    // tooltip
    if (document.getElementById("properties")) {
        $("#properties ul li a").cluetip({splitTitle: ' | '});
    }

    if (document.getElementById("promo")) {
        // animace vlastnosti
        property_animate = setTimeout(function() { runAnimate(); }, speedAnimate);

        // stop / start animace vlastnosti
        $("#promo div").hover(
            function() {
                // zastaveni animace, pokud na ni uzivatel najel mysi
                clearTimeout(property_animate);
                property_hover = true;
            },
            function() {
                // znovuspusteni animace, pokud na ni uzivatel uz neni mysi
                property_animate = setTimeout(function() { runAnimate(); }, speedAnimate);
                property_hover = false;
            }
        );
    }
});

function runAnimate()
{
    $("#promo #property-"+indexProperty).fadeOut("slow", function () {
        indexProperty = indexProperty + 1;

        $("#promo div").addClass("non-visible");

        if (!document.getElementById("property-"+indexProperty)) {
            indexProperty = 0;
        }

        $("#promo #property-"+indexProperty).removeClass("non-visible");
        $("#promo #property-"+indexProperty).fadeIn("normal");

        if (!property_hover) {
            property_animate = setTimeout(function() { runAnimate(); }, speedAnimate);
        }
    });
}

