var certonaScrollVar = 0;
var certonaScrollVarTop = 0;
var certonaScrollVarMost = 0;
var certonaScrollVarHot = 0;
var certonaScrollVarAdditional = 0;

// Controls htproducts
function certonaScrollLeft()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnum = getActualNumOfElements();

    //hide the rightmost visibile item and leave it alone
    document.getElementById('certonaScroller_'+((certonaScrollVar+3)%rrnum)).style.display = 'none';
    //bring the rightmost hidden item to the left side
    var myScrollerUL = document.getElementById('certonaScroller_'+((certonaScrollVar+rrnum-1)%rrnum));
    var ul = myScrollerUL.parentNode;

    ul.insertBefore(myScrollerUL,document.getElementById('certonaScroller_'+certonaScrollVar));

    if(certonaScrollVar == 0)
    {
      certonaScrollVar = rrnum;
    }
    certonaScrollVar = (certonaScrollVar - 1);
    document.getElementById('certonaScroller_'+certonaScrollVar).style.display = 'block';
}

function certonaScrollRight()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnum = getActualNumOfElements();

    //hide the leftmost item
    document.getElementById('certonaScroller_'+certonaScrollVar).style.display = 'none';
    
    //bring it to the right side
    var myScrollerUL = document.getElementById('certonaScroller_'+certonaScrollVar);
    var ul = myScrollerUL.parentNode;

    ul.appendChild(myScrollerUL);
    if(certonaScrollVar == rrnum-1)
    {
      certonaScrollVar = -1;
    }
    certonaScrollVar = (certonaScrollVar + 1);
    document.getElementById('certonaScroller_'+((certonaScrollVar+3)%rrnum)).style.display = 'block';
}

function getActualNumOfElements()
{
   var index = parseInt(resx.rrnum) - 1;
   while(document.getElementById('certonaScroller_'+index) == null)
   {
      index--;
   }
   return index+1;
}

// Controls topsellers
function certonaScrollLeftTop()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumTop = getActualNumOfElementsTop();

    //hide the rightmost visibile item and leave it alone
    document.getElementById('certonaScrollerTop_'+((certonaScrollVarTop+3)%rrnumTop)).style.display = 'none';
    //bring the rightmost hidden item to the left side
    var myScrollerULTop = document.getElementById('certonaScrollerTop_'+((certonaScrollVarTop+rrnumTop-1)%rrnumTop));
    var ulTop = myScrollerULTop.parentNode;

    ulTop.insertBefore(myScrollerULTop,document.getElementById('certonaScrollerTop_'+certonaScrollVarTop));

    if(certonaScrollVarTop == 0)
    {
      certonaScrollVarTop = rrnumTop;
    }
    certonaScrollVarTop = (certonaScrollVarTop - 1);
    document.getElementById('certonaScrollerTop_'+certonaScrollVarTop).style.display = 'block';
}

function certonaScrollRightTop()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumTop = getActualNumOfElementsTop();

    //hide the leftmost item
    document.getElementById('certonaScrollerTop_'+certonaScrollVarTop).style.display = 'none';
    
    //bring it to the right side
    var myScrollerULTop = document.getElementById('certonaScrollerTop_'+certonaScrollVarTop);
    var ulTop = myScrollerULTop.parentNode;

    ulTop.appendChild(myScrollerULTop);
    if(certonaScrollVarTop == rrnumTop-1)
    {
      certonaScrollVarTop = -1;
    }
    certonaScrollVarTop = (certonaScrollVarTop + 1);
    document.getElementById('certonaScrollerTop_'+((certonaScrollVarTop+3)%rrnumTop)).style.display = 'block';
}

function getActualNumOfElementsTop()
{
   var indexTop = parseInt(resx.rrnum) - 1;
   while(document.getElementById('certonaScrollerTop_'+indexTop) == null)
   {
      indexTop--;
   }
   return indexTop+1;
}


// Controls mostsearched
function certonaScrollLeftMost()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumMost = getActualNumOfElementsMost();

    //hide the rightmost visibile item and leave it alone
    document.getElementById('certonaScrollerMost_'+((certonaScrollVarMost+3)%rrnumMost)).style.display = 'none';
    //bring the rightmost hidden item to the left side
    var myScrollerULMost = document.getElementById('certonaScrollerMost_'+((certonaScrollVarMost+rrnumMost-1)%rrnumMost));
    var ulMost = myScrollerULMost.parentNode;

    ulMost.insertBefore(myScrollerULMost,document.getElementById('certonaScrollerMost_'+certonaScrollVarMost));

    if(certonaScrollVarMost == 0)
    {
      certonaScrollVarMost = rrnumMost;
    }
    certonaScrollVarMost = (certonaScrollVarMost - 1);
    document.getElementById('certonaScrollerMost_'+certonaScrollVarMost).style.display = 'block';
}

function certonaScrollRightMost()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumMost = getActualNumOfElementsMost();

    //hide the leftmost item
    document.getElementById('certonaScrollerMost_'+certonaScrollVarMost).style.display = 'none';
    
    //bring it to the right side
    var myScrollerULMost = document.getElementById('certonaScrollerMost_'+certonaScrollVarMost);
    var ulMost = myScrollerULMost.parentNode;

    ulMost.appendChild(myScrollerULMost);
    if(certonaScrollVarMost == rrnumMost-1)
    {
      certonaScrollVarMost = -1;
    }
    certonaScrollVarMost = (certonaScrollVarMost + 1);
    document.getElementById('certonaScrollerMost_'+((certonaScrollVarMost+3)%rrnumMost)).style.display = 'block';
}

function getActualNumOfElementsMost()
{
   var indexMost = parseInt(resx.rrnum) - 1;
   while(document.getElementById('certonaScrollerMost_'+indexMost) == null)
   {
      indexMost--;
   }
   return indexMost+1;
}

	

// Controls Additional Versions
function certonaScrollLeftAdditional()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumAdditional = getActualNumOfElementsAdditional();

    //hide the rightmost visibile item and leave it alone
    document.getElementById('certonaScrollerAdditional_'+((certonaScrollVarAdditional+4)%rrnumAdditional)).style.display = 'none';
    //bring the rightmost hidden item to the left side
    var myScrollerULAdditional = document.getElementById('certonaScrollerAdditional_'+((certonaScrollVarAdditional+rrnumAdditional-1)%rrnumAdditional));
    var ulAdditional = myScrollerULAdditional.parentNode;

    ulAdditional.insertBefore(myScrollerULAdditional,document.getElementById('certonaScrollerAdditional_'+certonaScrollVarAdditional));

    if(certonaScrollVarAdditional == 0)
    {
      certonaScrollVarAdditional = rrnumAdditional;
    }
    certonaScrollVarAdditional = (certonaScrollVarAdditional - 1);
    document.getElementById('certonaScrollerAdditional_'+certonaScrollVarAdditional).style.display = 'block';
}

function certonaScrollRightAdditional()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumAdditional = getActualNumOfElementsAdditional();

    //hide the leftmost item
    document.getElementById('certonaScrollerAdditional_'+certonaScrollVarAdditional).style.display = 'none';
    
    //bring it to the right side
    var myScrollerULAdditional = document.getElementById('certonaScrollerAdditional_'+certonaScrollVarAdditional);
    var ulAdditional = myScrollerULAdditional.parentNode;

    ulAdditional.appendChild(myScrollerULAdditional);
    if(certonaScrollVarAdditional == rrnumAdditional-1)
    {
      certonaScrollVarAdditional = -1;
    }
    certonaScrollVarAdditional = (certonaScrollVarAdditional + 1);
    document.getElementById('certonaScrollerAdditional_'+((certonaScrollVarAdditional+4)%rrnumAdditional)).style.display = 'block';
}

function getActualNumOfElementsAdditional()
{
   var indexAdditional = parseInt(resx.rrnum) - 1;
   while(document.getElementById('certonaScrollerAdditional_'+indexAdditional) == null)
   {
      indexAdditional--;
   }
   return indexAdditional+1;
}


// Controls Hot Products
function certonaScrollLeftHot()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumHot = getActualNumOfElementsHot();

    //hide the rightmost visibile item and leave it alone
    document.getElementById('certonaScrollerHot_'+((certonaScrollVarHot+4)%rrnumHot)).style.display = 'none';
    //bring the rightmost hidden item to the left side
    var myScrollerULHot = document.getElementById('certonaScrollerHot_'+((certonaScrollVarHot+rrnumHot-1)%rrnumHot));
    var ulHot = myScrollerULHot.parentNode;

    ulHot.insertBefore(myScrollerULHot,document.getElementById('certonaScrollerHot_'+certonaScrollVarHot));

    if(certonaScrollVarHot == 0)
    {
      certonaScrollVarHot = rrnumHot;
    }
    certonaScrollVarHot = (certonaScrollVarHot - 1);
    document.getElementById('certonaScrollerHot_'+certonaScrollVarHot).style.display = 'block';
}

function certonaScrollRightHot()
{
    //the actual response may not contain resx.rrnum number of items, so we need to check for this.
    var rrnumHot = getActualNumOfElementsHot();

    //hide the leftmost item
    document.getElementById('certonaScrollerHot_'+certonaScrollVarHot).style.display = 'none';
    
    //bring it to the right side
    var myScrollerULHot = document.getElementById('certonaScrollerHot_'+certonaScrollVarHot);
    var ulHot = myScrollerULHot.parentNode;

    ulHot.appendChild(myScrollerULHot);
    if(certonaScrollVarHot == rrnumHot-1)
    {
      certonaScrollVarHot = -1;
    }
    certonaScrollVarHot = (certonaScrollVarHot + 1);
    document.getElementById('certonaScrollerHot_'+((certonaScrollVarHot+4)%rrnumHot)).style.display = 'block';
}

function getActualNumOfElementsHot()
{
   var indexHot = parseInt(resx.rrnum) - 1;
   while(document.getElementById('certonaScrollerHot_'+indexHot) == null)
   {
      indexHot--;
   }
   return indexHot+1;
}
