﻿var autoSwitch = 'on';

$(document).ready(function () {
    $('.video-nav li a').click(function () {
        var thisNavID = $(this).attr('id');
        var thisNavNo = thisNavID.replace('video-nav-', '');
        if (document.getElementById('panel-' + thisNavNo).className != 'active') {
            autoSwitch = 'off';
            slideSwitcher(thisNavNo);
        }
        return false;
    });
	$('#panel-1').addClass('active').fadeIn('normal');
    setTimeout("autoSwitcher()", 3000);
});

var slideSwitcher = function (slideNo) {
    $('.video-frame .player div.active').removeClass('active').fadeOut('normal', function () {
        $('#panel-' + slideNo).addClass('active').fadeIn('normal');
        $('.video-nav').children().removeClass('active');
        $('#video-nav-holder-' + slideNo).addClass('active');
    });
}

var autoSwitcher = function () {
    if (autoSwitch == 'on') {
        var activeSlideID = $('.video-frame .player div.active').attr('id');
        var activeSlideNo = activeSlideID.replace('panel-', '');
        var nextActiveSlideNo = parseInt(activeSlideNo) + 1;
        if (nextActiveSlideNo > $('.video-frame .player div').children().length) {
            nextActiveSlideNo = 1;
        }
        slideSwitcher(nextActiveSlideNo);
        setTimeout("autoSwitcher()", 3000);
    }
}
