//$("#hindSSPanel > TABLE").animate({ left : "+="+"130px" }, animateDuration);     -PREV
//$("#hindSSPanel > TABLE").animate({ left : "-="+130 }, animateDuration)      - NEXT
$(window).load(runSlideShow);
var loop =0;
var hindSSIndex = 0;
var hindMenuIndex = 0;
var reachedFirst = true;
var reachedLast = false;
var firstShownImgNumber = 0;
var lastShownImgNumber = 3;
var hindSSMax = 0;
var animateDuration = 300;
var shiftLeft = 165;

function runSlideShow() {
    hindSSMax = $("TABLE.hindTabsTable > TBODY > TR > TD").addClass("Tabs").each(Init).click(TabEvent).size();
    $("TABLE.hindTabsTable").css("width",shiftLeft*hindSSMax); 
    
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV > TABLE > TBODY > TR > TD:last-child").addClass("BlueBg").children("DIV").hide();
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV > TABLE > TBODY > TR > TD").css("vertical-align","top");
    
    $("TABLE.hindSStab > TBODY > TR:eq(0) > TD:eq(2)").addClass("HindNavIcon").click(NextEvent);
    $("TABLE.hindSStab > TBODY > TR:eq(0) > TD:eq(0)").addClass("HindNavIcon").click(PrevEvent);
    
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV > TABLE > TBODY > TR > TD:first-child > DIV").addClass("LeftHeading").click(MenuEvent);
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV > TABLE > TBODY > TR > TD:last-child > DIV").addClass("Description");
    
    MoveIndex(0);    
}

function Init (){
  var img = $(this).attr("hindsrc");
  $(this).append('<img src="'+img+'" />');        
}

function NextEvent(){
  if (!reachedLast)
  {
    MoveIndex(1);
    //msg("lastShownImgNumber ="+lastShownImgNumber + "  hindSSIndex = "+hindSSIndex);
    if(lastShownImgNumber < hindSSIndex)
    {
        //var l_left = $("TABLE.hindTabsTable").parent().scrollLeft();
        //$("TABLE.hindTabsTable").parent().scrollLeft(l_left+shiftLeft);//without animation
        $("TABLE.hindTabsTable").animate({ left : "-="+shiftLeft }, animateDuration);
        firstShownImgNumber = hindSSIndex-3;
        lastShownImgNumber = hindSSIndex;
    }
  }
}

function PrevEvent()
{
  if (!reachedFirst)
  {
    MoveIndex(-1);
    if (firstShownImgNumber > hindSSIndex)
    {
      //var l_left = $("TABLE.hindTabsTable").parent().scrollLeft();
      //$("TABLE.hindTabsTable").parent().scrollLeft(l_left-shiftLeft);//without animation
      $("TABLE.hindTabsTable").animate({ left : "+="+shiftLeft }, animateDuration);
      firstShownImgNumber = hindSSIndex;
      lastShownImgNumber = hindSSIndex+3;
    }
  }
}

function MenuEvent()
{
  $(this).parent().children("*").removeClass("BlueHover");
  var hindMenuIndex = $(this).addClass("BlueHover").attr("hindmenuindex");

  $(this).parent().parent().children(":last-child").children("*").fadeOut("fast");
  $(this).parent().parent().children(":last-child").children(":eq("+hindMenuIndex+")").slideDown();
}

function TabEvent()
{
  var changeIndex = parseInt($(this).attr("hindTabIndex")) - hindSSIndex;
  if (changeIndex != 0) MoveIndex(changeIndex);
}
function MoveIndex(i)
{
    var currentOld = hindSSIndex;
    hindSSIndex = hindSSIndex+i;
    if (hindSSIndex == hindSSMax-1)
    {
        reachedLast = true;
        reachedFirst = false;
    }
    else if (hindSSIndex == 0)
    {
        reachedFirst = true;
        reachedLast = false;
    }
    else if (hindSSIndex > -1 && hindSSIndex < hindSSMax)
    {
        reachedFirst = false;
        reachedLast = false;
    }
    if (hindSSIndex > (hindSSMax-1) || hindSSIndex < 0)
    {
        hindSSIndex = hindSSIndex-i;
    }
    
    
    var title = $("TABLE.hindTabsTable > TBODY > TR > TD:eq("+hindSSIndex+")").attr("hindtitle");
    //$("TABLE.hindTabsTable").animate({ backgroundPosition: "+" + shiftLeft * hindSSIndex + " 0"  }, Math.abs(animateDuration * i));

    $("TABLE.hindTabsTable > TBODY > TR > TD").removeClass("hindTabs");
    $("TABLE.hindTabsTable > TBODY > TR > TD:eq(" + hindSSIndex + ")").html('<div class="hindTabTxt">' + title + '</div>').addClass("hindTabs");
    
    if (currentOld != hindSSIndex)
    {
      var img = $("TABLE.hindTabsTable > TBODY > TR > TD:eq("+currentOld+")").attr("hindsrc");
      $("TABLE.hindTabsTable > TBODY > TR > TD:eq("+currentOld+")").html("").append('<img src="'+img+'" />');
    }
    
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV").slideUp(animateDuration).parent().children(":eq("+hindSSIndex+")").slideDown(animateDuration);;
    
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV:eq("+hindSSIndex+") > TABLE > TBODY > TR > TD:eq(0) > DIV").show().removeClass("BlueHover").parent().children(":first-child").addClass("BlueHover");
    $("TABLE.hindSStab > TBODY > TR:eq(1) > TD:eq(1) > DIV:eq("+hindSSIndex+") > TABLE > TBODY > TR > TD:eq(1) > DIV").hide().parent().children(":eq(0)").show();
}

function msg(t)
{
$("#msg").html($("#msg").text()+"<br />"+t);
}                                 
