﻿var panIncrement = 15;

var direction = 0;

var homeContainer;
var panLeft;
var panRight;

$(document).ready(function() {
    homeImagePan();
});

function homeImagePan() {
    homeContainer = $("#homeImage");
    if (homeContainer.length > 0) {
        setInterval("checkDirection()", 50);
        panLeft = $("#outerHomeContainer a#panLeft");
        panRight = $("#outerHomeContainer a#panRight");
        panLeft.mousedown(function() {
            direction = 1;
            return false;
        });
        panLeft.mouseup(function() {
            direction = 0;
        });
        panRight.mousedown(function() {
            direction = -1;
            return false;
        });
        panRight.mouseup(function() {
            direction = 0;
        });
    }
}

function checkDirection() {
    if (direction != 0) {
        var currentMarginLeft = homeContainer.css("margin-left");
        var newMarginLeft = (parseInt(currentMarginLeft)) + (panIncrement*direction);
        homeContainer.css("margin-left", newMarginLeft + "px");
        checkPosition();
    }
}

function checkPosition() {
    var homeContainerLeft = homeContainer.css("margin-left");
    if (parseInt(homeContainerLeft) <= -360) {
        panRight.css("display", "none");
        direction = 0;
    } else if (parseInt(homeContainerLeft) >= -0) {
        panLeft.css("display", "none");
        direction = 0;
    } else {
        panRight.css("display", "block");
        panLeft.css("display", "block");
    }
}

function setScore(score) {
    $("input.hfScore").val(score);
}


