﻿jQuery(function($){

var scrollSpeed = 500;
var scrollOffset = -30;
var picNum = 0; 
if($("#pic_thumbs").get(0) != null)
{
    picNum = $("#pic_thumbs").get(0).rows[0].cells.length;
    //$("#pic_thumbs").get(0).rows[0].cells[0].style.backgroundColor = "#222222";
}

var currentPic = 0;

$('#nav_rst').click(function(){scrollToStart()})
$('#nav_lft').click(function(){scrollLeft()})
$('#nav_rgt').click(function(){scrollRight()})

//scroll to first
$.scrollTo(0);


function scrollLeft()
{
    if(currentPic != 0)
    {
        currentPic--;
    }
    if(currentPic == 0)
    {
        $.scrollTo(0,scrollSpeed)
        //clearSelectedTdBackground();
        //$("#pic_thumbs").get(0).rows[0].cells[0].style.backgroundColor = "#222222";
    }
    else
    {
        $.scrollTo($("#pic_thumbs").get(0).rows[0].cells[currentPic - 1],scrollSpeed,{offset:scrollOffset});
        if(picNum > 0)
        {
            //clearSelectedTdBackground();
            //$("#pic_thumbs").get(0).rows[0].cells[currentPic - 1].style.backgroundColor = "#222222";
        }
    }
};

function scrollRight()
{
    if(currentPic < picNum)
    {
        currentPic++;
        $.scrollTo( $("#pic_thumbs").get(0).rows[0].cells[currentPic - 1],scrollSpeed,{offset:scrollOffset});
        if(picNum > 0)
        {
            //clearSelectedTdBackground();
            //$("#pic_thumbs").get(0).rows[0].cells[currentPic - 1].style.backgroundColor = "#222222";
        }
    }
};

function scrollToStart()
{

    $.scrollTo(0,scrollSpeed);
    currentPic = 0;
    if(picNum > 0)
    {
        //clearSelectedTdBackground();
        //$("#pic_thumbs").get(0).rows[0].cells[0].style.backgroundColor = "#222222";
    }

};

//function clearSelectedTdBackground()
//{
//    for( var i = 0 ; i < picNum; i++)
//    {
//        $("#pic_thumbs").get(0).rows[0].cells[i].style.backgroundColor = "";
//    }
//};

});
