﻿//Written by: Damaris Zarco 2/8/2010
//Last Modified by: Damaris Zarco 2/19/2010

//public vars
var counter;
var a = 'home';

//window.onload = showButtons;

//funcs
function showButtons() {
    document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value = 0;

    var items = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfItems").value;
    if (items > 3) {
        var left = document.getElementById("leftArrow").style.visibility = "visible";
        var right = document.getElementById("rightArrow").style.visibility = "visible";
    }

    if (items > 3) {
        for (var i = 0; i < Math.ceil(items / 3); i++) {
            var cssClass
            if (i == 0) {
                cssClass = "Active_Button";
            } else {
                cssClass = "Button";
            }

            var btn = $('<div></div>')
                    .attr("id", "btn-" + i)
                    .addClass(cssClass)
                    .appendTo("#buttons");

            btn.click(function() {
                var counter = parseInt(document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value);
                var id = this.id.split("-")[1];
                var left = -(215 * id * 3)

                var btns = $('#buttons div').removeClass('Active_Button').addClass('Button');
                this.className = 'Active_Button';

                var scroller = $('#ctl00_ctl00_cphBody_cphHomeBody_pnlWidgets')
                        .css("left", left);

                var hfLeft = $('#ctl00_ctl00_cphBody_cphHomeBody_hfLeft')
                        .attr("value", left);

                counter = (id * 3) / 3;
                document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value = counter;
            });
        }
    }
}

function deleteClass(objDivID) {
    //document.getElementById(objDivID).className = 'hoverNav';
}

function moveRight() {

    counter = parseInt(document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value);
    var items = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfItems").value;
    if (counter < Math.ceil(items / 3) - 1) {
        counter = counter + 1;

        var scroller = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_pnlWidgets");
        var stringLeft = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_pnlWidgets").style.left;
        var currLeft = stringLeft.substring(0, stringLeft.length - 2);
        var newLeft = (currLeft - 645) + "px";
        scroller.style.left = newLeft;

        var hfLeft = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfLeft");
        hfLeft.value = newLeft;

        document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value = counter;
        var btns = $('#buttons div').removeClass('Active_Button').addClass('Button');
        var activeBtn = document.getElementById(btns[parseInt(counter)].id);
        activeBtn.className = 'Active_Button';
    }
}
function moveLeft() {
    counter = parseInt(document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value);
    if (!counter == 0) {
        counter = counter - 1;

        var scroller = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_pnlWidgets");
        var stringLeft = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_pnlWidgets").style.left;
        var currLeft = stringLeft.substring(0, stringLeft.length - 2);
        var newLeft = (parseInt(currLeft) + 645) + "px";
        scroller.style.left = newLeft;

        var hfLeft = document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfLeft");
        hfLeft.value = newLeft;
        document.getElementById("ctl00_ctl00_cphBody_cphHomeBody_hfCounter").value = counter;

        var btns = $('#buttons div').removeClass('Active_Button').addClass('Button');
        var activeBtn = document.getElementById(btns[parseInt(counter)].id);
        activeBtn.className = 'Active_Button';
    }
}
