/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var intervalId = 0;

function start() {
    intervalId = setInterval(navigate, 3000);
}

function navigateRight() {
    navigate(+1);
}

function navigateLeft() {
    navigate(-1);
}

function navigate(i) {
    if(!i) {
        i = 1;
    }
    else {
        clearInterval(intervalId);
        start();
    }
    var productToDisplay = (selectedProduct + i + productCount) % productCount;

    document.getElementById("product" + selectedProduct).style.display = 'none';
    document.getElementById("product" + productToDisplay).style.display = 'block';

    selectedProduct = productToDisplay;

}