﻿var intVal = "";
function slideSwitch(elementIndex) {
    //Get current active photo
    var $active = $('.viewport li.active');
    var activeIndex = $active.index();

    if ($active.length == 0) $active = $('.viewport li:last');

    //Find next photo to be displayed
    if (elementIndex == undefined) {
        var $next = $active.next().length ? $active.next() : $('.viewport li:first');
    }
    else {
        var $next = $($('.viewport .overview-listitem').get(elementIndex));
    }

    //If DelayedImageLoading is active render image html
    var imageContainer = $next.find('.item-image');
    if (imageContainer.children('img').length == 0) {
        var imgSrc = imageContainer.text();
        imageContainer.text('');
        imageContainer.append(imageContainer.html() + imgSrc.trim());
        SetCorners();
    }

    var nextIndex = $next.index();
    if (!$next.hasClass('active')) {
        $active.addClass('last-active');

        $next.css({ opacity: 0.0 })
	                    .addClass('active')
	                    .animate({ opacity: 1.0 }, 1000, function () {
	                        $active.removeClass('active last-active');
	                    });

        $($('.ic_navigation a').get(activeIndex)).removeClass('selected');
        $($('.ic_navigation a').get(nextIndex)).addClass('selected');
    }
}

function RegisterRotatorEvents() {
    SetIntervalOfBanner();

    $(".ic_navigation a").click(function () {
        var index = $(this).parent().index();
        window.clearInterval(intVal);
        slideSwitch(index);
        SetIntervalOfBanner();
    });
}



