﻿var carouselIndex = 0;
var carouselLength = 0;
$(document).ready(function () {
    var items = new Array();
    $('#carousel_items li').each(function () {
        var item = new Array();
        item[0] = $('img', this).attr('src')
        item[1] = $('.title', this).html();
        item[2] = $('.description', this).html();
        item[3] = $('a', this).attr('href');
        items[items.length] = item;
    });
    carouselLength = items.length;
    for (var i = 0; i < items.length; i++) {
        $('#carousel_render').append('<span class="item"><a href="' + items[i][3] + '"><img src="' + items[i][0] + '" /></a><div class="title">' + items[i][1] + '</div><div>' + items[i][2] + '</div></span>');
    }
    $('#carousel_render').width(items.length * 160);
    $('#carousel_left').click(function (event) {
        moveLeft();
        event.preventDefault();
        checkButtons();
    });
    $('#carousel_right').click(function (event) {
        moveRight();
        event.preventDefault();
        checkButtons();
    });
    checkButtons();
});
function checkButtons() {
    if (carouselIndex == 0)
        $('#carousel_left').hide();
    else
        $('#carousel_left').show();
    if (carouselIndex == carouselLength - 1)
        $('#carousel_right').hide();
    else
        $('#carousel_right').show();
}
function moveLeft() {
    carouselIndex--;
    $('#carousel_render').animate({ marginLeft: carouselIndex * -160 });
}
function moveRight() {
    carouselIndex++;
    $('#carousel_render').animate({ marginLeft: carouselIndex * -160 });
}

