$(document).ready(function()
{
    var speedSlider = 5000;
    var runSlider = setInterval('rotateSlider()', speedSlider);
    $('#slider').hover(function() { clearInterval(runSlider); }, function() { runSlider = setInterval('rotateSlider()', speedSlider); } ); 


    var item_width = $('#slides > ol > li').outerWidth(); 
    var left_value = item_width * (-1); 
    $('#slides > ol > li:first').before($('#slides > ol > li:last'));
    $('#slides ol').css({'left' : left_value});

    $('#inapoi').click(function()
    {
        var left_indent = parseInt($('#slides ol').css('left')) + item_width;
        $('#slides ol:not(:animated)').animate({'left' : left_indent}, 0,function()
        {
            $('#slides > ol > li:first').before($('#slides > ol > li:last'));
            $('#slides ol').css({'left' : left_value});
        });
        return false;
    });

    $('#inainte').click(function()
    {
        var left_indent = parseInt($('#slides ol').css('left')) - item_width;
        $('#slides ol:not(:animated)').animate({'left' : left_indent}, 0, function ()
        {
            $('#slides > ol > li:last').after($('#slides > ol > li:first'));
            $('#slides ol').css({'left' : left_value});
        });
        return false;
    });



    var item_widthTop = $('#slidesTop > ol > li').outerWidth(); 
    var left_valueTop = item_widthTop * (-1); 
    $('#slidesTop > ol > li:first').before($('#slidesTop > ol > li:last'));
    $('#slidesTop ol').css({'left' : left_valueTop});

    $('#inapoiTop').click(function()
    {
        var left_indentTop = parseInt($('#slidesTop ol').css('left')) + item_widthTop;
        $('#slidesTop ol:not(:animated)').animate({'left' : left_indentTop}, 0,function()
        {
            $('#slidesTop > ol > li:first').before($('#slidesTop > ol > li:last'));
            $('#slidesTop ol').css({'left' : left_valueTop});
        });
        return false;
    });

    $('#inainteTop').click(function()
    {
        var left_indentTop = parseInt($('#slidesTop ol').css('left')) - item_widthTop;
        $('#slidesTop ol:not(:animated)').animate({'left' : left_indentTop}, 0, function ()
        {
            $('#slidesTop > ol > li:last').after($('#slidesTop > ol > li:first'));
            $('#slidesTop ol').css({'left' : left_valueTop});
        });
        return false;
    });


    var item_widthMulti = $('#slidesMulti > ol > li').outerWidth(); 
    var left_valueMulti = item_widthMulti * (-1); 
    $('#slidesMulti > ol > li:first').before($('#slidesMulti > ol > li:last'));
    $('#slidesMulti ol').css({'left' : left_valueMulti});
    $('#inapoiMulti').click(function()
    {
        var left_indentMulti = parseInt($('#slidesMulti ol').css('left')) + item_widthMulti;
        $('#slidesMulti ol:not(:animated)').animate({'left' : left_indentMulti}, 0,function()
        {
            $('#slidesMulti > ol > li:first').before($('#slidesMulti > ol > li:last'));
            $('#slidesMulti ol').css({'left' : left_valueMulti});
        });
        return false;
    });

    $('#inainteMulti').click(function()
    {
        var left_indentMulti = parseInt($('#slidesMulti ol').css('left')) - item_widthMulti;
        $('#slidesMulti ol:not(:animated)').animate({'left' : left_indentMulti}, 0, function ()
        {
            $('#slidesMulti > ol > li:last').after($('#slidesMulti > ol > li:first'));
            $('#slidesMulti ol').css({'left' : left_valueMulti});
        });
        return false;
    });
});

function rotate(top) { $('#inainte'+top).click(); }




function redrawBullets(slide)
{
    var currentBullet = 's'+slide;
    $('#slideCtrl ul li a').each(function()
    {
        $(this).removeClass('selectat');
        if($(this).hasClass(currentBullet)){ $(this).addClass('selectat') }
    });
};

var currentslide = 1
function showSlide(nrSld)
{
    currentslide = parseInt(nrSld)
    $('#slider .slideWrapper').animate({left:-460*(parseInt(nrSld)-1)})
    redrawBullets(nrSld);
};

function showSlideZero()
{
	currentslide = 1
    $('#slider .slideWrapper').animate({left:0},1)
    redrawBullets(1);
};

function rotateSlider()
{
    var size = $("#slideCtrl ul").children('li').size();
	current_pos = currentslide+1;
	if(current_pos>size) showSlideZero();
    else showSlide(current_pos);
}

