﻿var email = '<a href=' + '"mailto:moreinfo@7simplemachines.com"' + ' class="grayBoxLink">moreinfo@7simplemachines.com</a>';
var mycarousel_itemList = [
        { url: 'images/icons/icon_Partners_glow.png', title: 'Partners' },
        { url: 'images/icons/icon_About_glow.png', title: 'AboutUs' },
        { url: 'images/icons/icon_Contact_glow.png', title: 'ContactUs' },
        { url: 'images/icons/icon_Solutions_glow.png', title: 'Solutions' },
        { url: 'images/icons/icon_Services_glow.png', title: 'Services' },
        { url: 'images/icons/icon_Clients_glow.png', title: 'Clients' }
        ];

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
    if (!($.browser.msie && $.browser.version <= "6.0")) {
        var imgItems = $('[jcarouselindex] img');
        if (imgItems.size() >= 6) {
            swapImages();
            return;
        }
    }
};

function mycarousel_getItemHTML(item) {
    return '<span style=""><a href="views/' + item.title + '.aspx"><img src="' + item.url + '" width="109" height="101" alt="' + item.title + '" /></a></span>';
};

function swapImages() {
    $('[jcarouselindex] img:eq(0)').attr('src', $('[jcarouselindex] img:eq(0)').attr('src').replace('glow', 'faded'));
    $('[jcarouselindex] img:eq(1)').attr('src', $('[jcarouselindex] img:eq(1)').attr('src').replace('faded', 'glow'));
    $('[jcarouselindex] img:eq(2)').attr('src', $('[jcarouselindex] img:eq(2)').attr('src').replace('faded', 'glow'));
    $('[jcarouselindex] img:eq(3)').attr('src', $('[jcarouselindex] img:eq(3)').attr('src').replace('faded', 'glow'));
    $('[jcarouselindex] img:eq(4)').attr('src', $('[jcarouselindex] img:eq(4)').attr('src').replace('glow', 'faded'));
    $('[jcarouselindex] img:eq(5)').attr('src', $('[jcarouselindex] img:eq(5)').attr('src').replace('glow', 'faded'));

    $('[jcarouselindex] a:eq(0)').attr('style', 'cursor:default;');
    $('[jcarouselindex] a:eq(1)').attr('style', 'cursor:pointer;');
    $('[jcarouselindex] a:eq(2)').attr('style', 'cursor:pointer;');
    $('[jcarouselindex] a:eq(3)').attr('style', 'cursor:pointer;');
    $('[jcarouselindex] a:eq(4)').attr('style', 'cursor:default;');
    $('[jcarouselindex] a:eq(5)').attr('style', 'cursor:default;');

    $('[jcarouselindex] a').click(function(event) { if ($(this).css('cursor') == 'default') { event.preventDefault(); } });
}

function updateCarousel() {
    for (i = 0; i < 6; i++) {
        $('.jcarousel-next').click();
    }
    $('.jcarousel-prev').click();
    if (!($.browser.msie && $.browser.version <= "6.0") && !($.browser.safari)) {
        swapImages();
    }
}

$(document).ready(function() {
    $('#mycarousel').jcarousel({
        vertical: true,
        scroll: 2,
        //animation: 'slow',
        wrap: 'circular',
        itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
        itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
    });
    setTimeout('updateCarousel()', 100);
});
