﻿$(document).ready(function () {
    //######### HOMEPAGE CAROUSEL #############//
    $('#viewport').carousel('#simple-previous', '#simple-next');
});

//The auto-scrolling function
function slide() {
    $('#simple-next').click();
}
//Launch the scroll every 2 seconds
var intervalId = window.setInterval(slide, 3000);

//On user click deactivate auto-scrolling
$('#simple-previous, #simple-next').click(
 function (event) {
     if (event.originalEvent) {
         window.clearInterval(intervalId);
     }
 }
);

//######### HOMEPAGE QUOTES #############//   
function divSwitch() {
    //get the active div
    var $active = $('#panels div.active');
    //if not set, set it to the last div
    if ($active.length == 0) $active = $('#panels div:last');

    var $next = $active.next().length ? $active.next()
            : $('#panels div:first');

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
            .addClass('active')
            .animate({ opacity: 1.0 }, 1000, function () {
                $active.removeClass('active last-active');
            });
}

$(function () {
    var numQuotes = $('#panels div').length;
    //on load
    //add active class to first div
    if (numQuotes > 1) {
        $('#panels div:first').addClass('active');
        setInterval("divSwitch()", 5000);
    }
    else {
        $('#panels div:first').addClass('active');
    }
});


//######### HOMEPAGE BANNERS #############//   
function bannerSwitch() {
    var $active = $('#mainBannerHome IMG.active');

    if ($active.length == 0) $active = $('#mainBannerHome IMG:last');

    var $next = $active.next().length ? $active.next()
        : $('#mainBannerHome IMG:first');

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function () {
            $active.removeClass('active last-active');
        });
}

$(function () {
    $('#mainBannerHome IMG:first').addClass('active');
    setInterval("bannerSwitch()", 5000);
});

//######### SSB EQUAL HEIGHT COLUMNS #############//
function equalHeight(group) {
    var tallest = 0;
    group.each(function () {
        var thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}
