﻿var startItemId = 0;
var noOfItemsToShow = 0;
var totalItems = 0;
var currentStartingItem = 0;
var baseLiName = "liLatestItem";
var noOfCats = 1;

function setStartingVars(id, no, tot, noOfCategories) {
    startItemId = id;
    currentStartingItem = id;
    noOfItemsToShow = no;
    totalItems = tot;
    noOfCats = noOfCategories;
}

function setCatDropDownHeight(theDivName) {
    var divHeight = 3 + 5 + (19 * noOfCats);
    document.getElementById(theDivName + "_container").style.height = divHeight.toString() + "px";
}

function setLiName(liName) {
    baseLiName = liName.toString().replace("_ctl01_liLatestItem", "_ctlxy_liLatestItem");
}

function scrollLatestDealsLeft(theButton, numberOfDeals) {
    if (currentStartingItem > 1) {
        var j = 0;
        for (j = 0; j < numberOfDeals; j++) {
            doScrollLeft(theButton);
        } 
    }
}

function doScrollLeft(theButton) {
    var i = 1;
    for (i = 1; i < totalItems + 1; i++) {
        if (i == currentStartingItem) {
            if (i == 1) {
                //Do Nothing
            } else {
                var strShowInt = "0";
                var showInt = i - 1;
                if (showInt < 10) {
                    strShowInt = "0" + showInt.toString();
                } else {
                    strShowInt = showInt.toString();
                }

                var strHideInt = "0";
                var hideInt = i + noOfItemsToShow - 1;
                if (hideInt < 10) {
                    strHideInt = "0" + hideInt.toString();
                } else {
                    strHideInt = hideInt.toString();
                }

                var liHide = document.getElementById(baseLiName.replace("ctlxy", "ctl" + strHideInt));
                $liHide = $(liHide);
                $liHide.animate({ 'marginLeft': 143 }, 500);

                var liShow = document.getElementById(baseLiName.replace("ctlxy", "ctl" + strShowInt));
                $liShow = $(liShow);
                $liShow.animate({ 'marginLeft': -143 }, 1);
                $liShow.show(1);
                $liShow.animate({ 'marginLeft': 0 }, 500);                    

                currentStartingItem -= 1;

                var theOtherButton = document.getElementById(theButton.id.replace("btnLeft", "btnRight"));
                if (theOtherButton) {
                    theOtherButton.className = "scrollRight";
                }

                if (currentStartingItem == 1) {
                    theButton.className = "scrollLeftBlank";
                }
            }
            break;
        }
    }
}

function scrollLatestDealsRight(theButton, numberOfDeals) {
    if (currentStartingItem <  (totalItems - noOfItemsToShow + 1)) {
        var x = 0;
        for (x = 0; x < numberOfDeals; x++) {
            doScrollRight(theButton);
        } 
    }
}

function doScrollRight(theButton) {
    var k = 1;
    for (k = 1; k < totalItems + 1; k++) {
        if (k == currentStartingItem) {
            if (k == totalItems - noOfItemsToShow + 1) {
                //Do Nothing
            } else {
                var strShowInt = "0";
                var showInt = k + noOfItemsToShow;
                if (showInt < 10) {
                    strShowInt = "0" + showInt.toString();
                } else {
                    strShowInt = showInt.toString();
                }

                var strHideInt = "0";
                var hideInt = k;
                if (hideInt < 10) {
                    strHideInt = "0" + hideInt.toString();
                } else {
                    strHideInt = hideInt.toString();
                }

                var liHide = document.getElementById(baseLiName.replace("ctlxy", "ctl" + strHideInt));
                $liHide = $(liHide);
                $liHide.animate({ 'marginLeft': -143 }, 500);

                var liShow = document.getElementById(baseLiName.replace("ctlxy", "ctl" + strShowInt));
                $liShow = $(liShow);
                $liShow.animate({ 'marginLeft': 143 }, 1);      
                $liShow.show(1);
                $liShow.animate({ 'marginLeft': 0 }, 500);               

                currentStartingItem += 1;

                var theOtherButton = document.getElementById(theButton.id.replace("btnRight", "btnLeft"));
                if (theOtherButton) {
                    theOtherButton.className = "scrollLeft";
                }

                if (currentStartingItem == totalItems - noOfItemsToShow + 1) {
                    theButton.className = "scrollRightBlank";
                }
            }
            break;
        }
    }
}

