﻿//var timeOuts = new Array();
//var i = 1;

$(document).ready(
    function () {
        if ($('.flash img').size() > 1) {
            var $active = $('.flash img.active');
            if ($active.size() == 0) {
                $('.flash img').first().addClass('active');
            }
            //timeOuts[i] = setTimeout(function () { slideSwitch(); }, 6100);
            $('.link-prev').click(function () {
                //clearAllTimeouts();
                slideSwitch('prev');
                return false;
            });
            $('.link-next').click(function () {
                //clearAllTimeouts();
                slideSwitch('next');
                return false;
            });
        }
        else {
            $('.link-prev').css('display', 'none');
            $('.link-next').css('display', 'none');
        }
    }
);

function slideSwitch(dir) {
    var $active = $('.flash img.active');
    var $next;
    if (dir == 'prev') {
        $next = $active.prev();
        if ($next.attr('src') == null) {
            $next = $('.flash img').last();
        }
    }
    else {
        $next = $active.next();
        if ($next.attr('src') == null) {
            $next = $('.flash img').first();
        }
    }
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 }).addClass('active').animate({ opacity: 1.0 }, 1000, function () {
        $active.removeClass('active last-active');
    });
//    i += 1;
//    timeOuts[i] = setTimeout(function () { slideSwitch('next'); }, 6100);
}

//function clearAllTimeouts() {
//    for (key in timeOuts) {
//        clearTimeout(timeOuts[key]);
//    }
//}

