﻿var larghezza = 316;
var currentitem = 3;
var currentpos = 0;
var incorso = false;
var altezza = 185;
var currentitem2 = 1;
var currentitem3 = 1;
var altezza2 = 155;


function goavanti() {
    if (incorso == false) {
        if (currentitem < parseInt($("#numimg").val())) {
            incorso = true;
            currentpos = ((-parseInt(larghezza)) - 12) * (currentitem - 3)
            $('#conteiner').animate({
                left: currentpos - larghezza - 12
            }, 1000, function () {
                currentitem += 1;
                //alert(currentpos);
                incorso = false;
            });
        }
    }
}

function goindietro() {
    if (incorso == false) {
        if (currentitem > 3) {
            incorso = true;
            currentpos = ((-parseInt(larghezza)) - 12) * (currentitem - 3)
            $('#conteiner').animate({
                left: currentpos + larghezza + 12
            }, 1000, function () {
                currentitem -= 1;
                //alert(currentpos);
                incorso = false;
            });
        }
    }
}

function reset() {
    if (incorso == false) {
        incorso = true;
        $('#conteiner').animate({
            left: 0
        }, 1000, function () {
            currentitem = 3;
            //alert(currentpos);
            incorso = false;
        });
    }
}

var times = 1000;
$(document).everyTime(4500, function (i) {
    if (incorso == false) {
        if (currentitem < parseInt($("#numimg").val())) {
            goavanti();
        } else {
            reset();
        }
    }

}, times);

$(document).everyTime(3000, function (i) {
    scrollaofferte();
}, times);

$(document).everyTime(5000, function (i) {
    scrollanews();
}, times);



function scrollaofferte() {

    var contenitore = "cnt2";


    if ($("#numerofferte").val() == currentitem2) {
        $('#' + contenitore).animate({
            top: 0
        }, 1000, function () {
            currentitem2 = 1;
        });
    } else {
        $('#' + contenitore).animate({
            top: (-parseInt(altezza) - 0) * currentitem2
        }, 1000, function () {
            currentitem2 += 1;
        });
    }
}

function scrollanews() {

    var contenitore = "cnt3";


    if ($("#numnews").val() == currentitem3) {
        $('#' + contenitore).animate({
            top: 0
        }, 1000, function () {
            currentitem3 = 1;
        });
    } else {
        $('#' + contenitore).animate({
            top: (-parseInt(altezza2) - 0) * currentitem3
        }, 1000, function () {
            currentitem3 += 1;
        });
    }
}
