function initCustomerWidget() {
    if(hasCSS()) {
        $('#customer-widget .content').append('<a href="#" id="customer-prev"><img src="/media/22958/prev.jpg" alt="Vorige" /></a><a href="#" id="customer-next"><img src="/media/22952/next.jpg" alt="Volgende" /></a>');
        initHomeCustomers();
   }
 }

function hasCSS() {
    $('body').append('<div id="cssTest"></div>')
    $('#cssTest').css({ width: '1px' })
    var cssBoolean = ($('#cssTest').width() != 1) ? false : true
    $('#cssTest').remove()
    return cssBoolean;
}

function initHomeCustomers() {
    if ($('#customers ul li').length < 1) {
        return false;
    }
    var movepx = 155;
    var leng = $('#customers ul li').length;
    leng = (leng * movepx) - movepx;
    $('#customer-next').click(function() {
        toggleTimeout = clearTimeout(toggleTimeout);
        HomeCustomerMoveNext(leng);
        return false;
    });
    $('#customer-prev').click(function() {
        toggleTimeout = clearTimeout(toggleTimeout);
        HomeCustomerMovePrev(leng);
        return false;
    });
}

$().ready(function() {
    initCustomerWidget();
});


/* added by axendo */
var toggleTimeout = setTimeout("HomeCustomerMoveAuto()", 9000);
var way = 'left';

function HomeCustomerMoveAuto() {
    if ($('#customers ul li').length < 1) {
        return false;
    }
    toggleTimeout = clearTimeout(toggleTimeout);
    var movepx = 155;
    var leng = $('#customers ul li').length;
    leng = (leng * movepx) - movepx;
    var left = $('#customers ul').css('left').replace('px', '');
    if (way == 'left') {
        if (left > (1 - leng)) {
            HomeCustomerMoveNext(leng);
        } else {
            HomeCustomerMovePrev(leng);
            way = 'right';
        }
    } else {
        if (left >= 0) {
            way = 'left';
            HomeCustomerMoveNext(leng);
        } else {
            HomeCustomerMovePrev(leng);
        }
    }
}

function HomeCustomerMoveNext(leng) {
    var movepx = 155;
    var left = $('#customers ul').css('left').replace('px', '');
    if (left > (0 - leng)) {
        $('#customers ul').animate({
            left: left - movepx + "px"
        }, 1000);
    }
    toggleTimeout = setTimeout("HomeCustomerMoveAuto()", 9000);
}

function HomeCustomerMovePrev(leng) {
    var movepx = 155;
    var left = $('#customers ul').css('left').replace('px', '');
    left = Math.ceil(left);
    if (left < -movepx) {
        left = left + movepx;
    } else {
        left = 0;
    }
    $('#customers ul').animate({
        left: left + "px"
    }, 1000);
    toggleTimeout = setTimeout("HomeCustomerMoveAuto()", 9000);
}
