﻿
var blueColorTopic = "#ee120d";
var grayColorService = "#cccccc";
var isRunning = false;

function nextTopic(dataListTopicId, nextTopicId, previousTopicId, totalToDisplay) {

    // alert("1");
    if (isRunning) {
        return;
    }

    var datalistTopic = document.getElementById(dataListTopicId),
        nextTopic = document.getElementById(nextTopicId),
        previousTopic = document.getElementById(previousTopicId),
        widthTopic = datalistTopic.rows[0].cells[0].offsetWidth,// + 6; //184
        numberOfTopics = datalistTopic.rows[0].cells.length;

    if (parseInt(datalistTopic.style.left) > -((numberOfTopics - totalToDisplay) * widthTopic)) {
        if ((parseInt(datalistTopic.style.left) - widthTopic) <= -(numberOfTopics - totalToDisplay) * widthTopic) {
            nextTopic.style.color = grayColorService;
            nextTopic.style.cursor = "text";
        }
        moveTopic(0, -44, dataListTopicId);
        previousTopic.style.color = blueColorTopic;
        previousTopic.style.cursor = "pointer";
    }
    else {
        nextTopic.style.color = grayColorService;
        nextTopic.style.cursor = "text";
    }
}

function previousTopic(dataListTopicId, nextTopicId, previousTopicId) {

    if (isRunning)
        return;
    var datalistTopic = document.getElementById(dataListTopicId),
        nextTopic = document.getElementById(nextTopicId),
        previousTopic = document.getElementById(previousTopicId),
        pixelTopic = datalistTopic.rows[0].cells[0].offsetWidth; // + 6;

    if (parseInt(datalistTopic.style.left) < 0) {
        if (parseInt(datalistTopic.style.left) + pixelTopic == 0) {
            previousTopic.style.color = grayColorService;
            previousTopic.style.cursor = "text";
        }
        moveTopic(0, 44, dataListTopicId);
        nextTopic.style.color = blueColorTopic;
        nextTopic.style.cursor = "pointer";
    }
    else {
        previousTopic.style.color = grayColorService;
        previousTopic.style.cursor = "text";
    }
}

function moveTopic(eval1, eval2, dataListTopicId) {
    var datalistTopic = document.getElementById(dataListTopicId),
        widthTopic = datalistTopic.rows[0].cells[0].offsetWidth; //+ 6; //184
    if (eval1 < widthTopic) {
        isRunning = true;
        eval1 = eval1 + Math.abs(eval2);
        window.setTimeout('moveTopic(' + eval1 + ',' + eval2 + ',\'' + dataListTopicId + '\');', 100);
        datalistTopic.style.left = parseInt(datalistTopic.style.left) + eval2 + "px";
    }
    else
        isRunning = false;
}



var isOfferRunning = false;

function nextOffer(dataListTopicId, nextTopicId, previousTopicId, totalToDisplay) {

    // alert("1");
    if (isOfferRunning) {
        return;
    }

    var datalistTopic = document.getElementById(dataListTopicId),
        nextTopic = document.getElementById(nextTopicId),
        previousTopic = document.getElementById(previousTopicId),
        widthTopic = datalistTopic.rows[0].cells[0].offsetWidth, // + 6; //184
        numberOfTopics = datalistTopic.rows[0].cells.length;

    if (parseInt(datalistTopic.style.left) > -((numberOfTopics - totalToDisplay) * widthTopic)) {
        if ((parseInt(datalistTopic.style.left) - widthTopic) <= -(numberOfTopics - totalToDisplay) * widthTopic) {
            nextTopic.className = 'TyreOfferArrowRightGray';
        }
        moveOffer(0, -44, dataListTopicId);
        previousTopic.className = 'TyreOfferArrowLeft';
    }
    else {
        nextTopic.className = 'TyreOfferArrowRightGray';
    }
}

function previousOffer(dataListTopicId, nextTopicId, previousTopicId) {

    if (isOfferRunning)
        return;
    var datalistTopic = document.getElementById(dataListTopicId),
        nextTopic = document.getElementById(nextTopicId),
        previousTopic = document.getElementById(previousTopicId),
        pixelTopic = datalistTopic.rows[0].cells[0].offsetWidth; // + 6;

    if (parseInt(datalistTopic.style.left) < 0) {
        if (parseInt(datalistTopic.style.left) + pixelTopic > -3) {
            previousTopic.className = 'TyreOfferArrowLeftGray';
        }
        moveOffer(0, 44, dataListTopicId);
        nextTopic.className = 'TyreOfferArrowRight';
    }
    else {
        previousTopic.className = 'TyreOfferArrowLeftGray';
    }
}

function moveOffer(eval1, eval2, dataListTopicId) {
    var datalistTopic = document.getElementById(dataListTopicId),
        widthTopic = datalistTopic.rows[0].cells[0].offsetWidth; //+ 6; //184
    if (eval1 < widthTopic) {
        isOfferRunning = true;
        eval1 = eval1 + Math.abs(eval2);
        window.setTimeout('moveOffer(' + eval1 + ',' + eval2 + ',\'' + dataListTopicId + '\');', 100);
        datalistTopic.style.left = parseInt(datalistTopic.style.left) + eval2 + "px";
    }
    else
        isOfferRunning = false;
}
