﻿$(document).ready(function () {
    $(".allos-carousel-viewport .desc").show(); //Show Banner
    $(".allos-carousel-viewport .block").animate({ opacity: 1 }, 1);
    $(".allos-carousel-items ul li:first").addClass('active'); //runs function on click
    $(".allos-carousel-items ul li").click(function () {
        var imgAlt = $(this).find('img').attr("alt");
        var imgTitle = $(this).find('a').attr("xldata");
        var imgDesc = $(this).find('.desc').html();
        var imgDescHeight = $(".allos-carousel-viewport").find('.block').height();
        var imgLink = $(this).find('a').attr("href");
        if ($(this).is(".active")) {
            return false;
        } else {
        $(".allos-carousel-viewport .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 1000, function() {
        $(".allos-carousel-viewport .block").html(imgDesc).animate({ opacity: 1, marginBottom: "0" }, 1000);
                $(".allos-carousel-viewport img").attr({ src: imgTitle, alt: imgAlt });
            });
        }
        $(".allos-carousel-items ul li").removeClass('active');
        $(this).addClass('active');
        return false; $active = $(this);
        slideSwitchClick();
    })
            .hover(function () {
                $(this).addClass('hover');
                clearInterval(playSlideshow);
                playSlideshow = setInterval('slideSwitchTimed()', 8000);
            }, function () {
                $(this).removeClass('hover');
            });
    //runs function, set timer here
    $(function () {
        playSlideshow = setInterval('slideSwitchTimed()', 8000);
    });
});

function slideSwitchTimed() {
    $active = $('.allos-carousel-items ul li.active').next();
    if ($active.length == 0) $active = $('.allos-carousel-items ul li:first');
    slideSwitch();
}
function slideSwitchClick() {
    slideSwitch();
}
function slideSwitch() {
    var $prev = $('.allos-carousel-items ul li.active');
    //Show active list-item
    $prev.removeClass('active');
    $active.addClass('active');
    //Set Variables
    var imgAlt = $active.find('img').attr("alt");
    var imgTitle = $active.find('a').attr("xldata");
    var imgDesc = $active.find('.desc').html();
    var imgDescHeight = $(".allos-carousel-viewport").find('.block').height();
    var imgLink = $(this).find('a').attr("href");
    if ($(this).is(".active")) {
        return false;
    } else {
        $(".allos-carousel-viewport img").animate({ opacity: 0 }, 1000);
        $(".allos-carousel-viewport .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 1000, function() {
        $(".allos-carousel-viewport .block").html(imgDesc).animate({ opacity: 1, marginBottom: "0" }, 1000);
        $(".allos-carousel-viewport img").attr({ src: imgTitle, alt: imgAlt }).animate({ opacity: 1 }, 1000);
        });
    }
    return false;
}
