﻿var thumbsLine = 0;
var currentLine = 0;
var itemCount = 0;
var currentItem = 1;

function InitSlider() {
    itemCount = $('#hContainer .news').size();
    CreateButtons();
    startSlide = setInterval(StartSlide, 10000);
    $('#hContainer .news:first').css('display', 'block');
}

function CreateButtons() {

    $('#hContainer').append('<ul class="paginationUl">');
    for (var i = 0; i < itemCount; i++) {
        $('#hContainer .news:nth-child(' + (i + 1) + ')').attr('id', 'item' + i);
        $('#hContainer ul').append('<li onclick="GoToItem(' + i + ',this); return false;">&nbsp;</li>');
        $('#hContainer ul li:nth-child(' + (i + 1) + ')').attr('id', "item" + i);
    }
    $('#hContainer').append('</ul>');
    $('#hContainer ul li:first').addClass('selected');
}

function GoToItem(item, itemButton) {

    $('#hContainer ul li').removeClass('selected');
    $(itemButton).addClass('selected');
    $('#hContainer .news').css('display', 'none');
    $('#hContainer .news').animate({ opacity: 0 }, 300, function () {
        $('#hContainer div#item' + item + '').css('display', 'block');
    $(this).animate({ opacity: 1 }, 300);
    });

}

function StartSlide() {
    if (currentItem != itemCount) {
        GoToItem(currentItem, $('.paginationUl li:nth-child(' + (currentItem+1) +')'));
        currentItem += 1;
    }
    else {
        currentItem = 0;
    }
}


