﻿/* Javascript Version 1.0 */
/* www.ukonlinemarket.co.uk */

var arr1 = new Array("product1", "product2", "product3", "product4", "product5");
var arr2 = new Array("a23","a2","a3","a4","a5");
var lastDiv = null;
var lastA = null;

function show(cntrl, aLink)
{
    aTag = document.getElementById(aLink);
    if(cntrl != null)
    {
        if(aTag != null)
        {
            aTag.style.backgroundColor = "#1054A6";
            aTag.style.color = "#ffffff";            
        }
        cntrl.style.display = "block";
    }
    if((lastDiv != null) && (lastDiv != cntrl))
    {
        lastDiv.style.display = "none";
    }
    if((lastA != null) && (lastA != aLink))
    {
        document.getElementById(lastA).style.backgroundColor = "";
        document.getElementById(lastA).style.color = "#000000";   
    }    
    lastDiv = cntrl;
    lastA = aLink;
}

function goNext()
{
    if(lastDiv != null)
    {
        id = lastDiv.id;
        nextIndex = 0;
        for(i=0; i<arr1.length; i++)
        {
            if(arr1[i] == id)
            {
                if(i == ((arr1.length)-1))
                {
                    nextIndex = 0;
                    break;
                }
                nextIndex = (i+1);
                break;
            }
        }
        nextA = 0;
        for(i=0; i<arr2.length; i++)
        {
            if(arr2[i] == lastA)
            {
                if(i == ((arr2.length)-1))
                {
                    nextA = 0;
                    break;
                }
                nextA = (i+1);
                break;
            }
        }
        show(document.getElementById(arr1[nextIndex]),arr2[nextA]);
    }
}

function goBack()
{
    if(lastDiv != null)
    {
        id = lastDiv.id;
        nextIndex = 0;
        for(i=0; i<arr1.length; i++)
        {
            if(arr1[i] == id)
            {
                if(i==0)
                {
                    nextIndex = (arr1.length-1);
                    break;
                }
                nextIndex = (i-1);
                break;
            }
        }
        nextA = 0;
        for(i=0; i<arr2.length; i++)
        {
            if(arr2[i] == lastA)
            {
                if(i == 0)
                {
                    nextA = (arr2.length-1);
                    break;
                }
                nextA = (i-1);
                break;
            }
        }
        show(document.getElementById(arr1[nextIndex]),arr2[nextA]);
    }
}

var divContent = document.getElementById("allMerchants");
var divContainer = document.getElementById("divContainer");
var timerIdBack = null;
var timerIdFore = null;
var WhichPaused = null;

function scroll() //From left to right
{
    if(divContent != null && divContainer != null)
    {    
        var visibleWidth = parseInt(divContainer.offsetWidth);
        var actualWidth = parseInt(divContent.offsetWidth);
        var invisibleWidth = actualWidth - visibleWidth;      
        if(parseInt(divContent.style.left).toString() == "NaN")
        {
            divContent.style.left = "0px";            
        }
        var left = Math.abs(parseInt(divContent.style.left));
        if(left == 0)
        {
            timerIdBack = setInterval("scrollbackward()",20);            
        }
        if (left == invisibleWidth)
        {
            timerIdFore = setInterval("scrollforward()",20);            
        }
    }
}

function onmousesoverstop()
{
    if(timerIdFore != null)
    {
        WhichPaused = true; // set to true in order to start forward scrolling
        clearInterval(timerIdFore);
        timerIdFore = null;
        clearInterval(timerIdBack);
        timerIdBack = null        
    }
    if(timerIdBack != null)
    {
        WhichPaused = false; // set to false in order start backwardward scrolling
        clearInterval(timerIdBack);
        timerIdBack = null;
        clearInterval(timerIdFore);
        timerIdFore = null;
    }
}

function onmouseoutstart()
{
    if(WhichPaused != null)
    {
        if(WhichPaused) // set to true in order to start forward scrolling
        {
            timerIdFore = setInterval("scrollforward()",20);            
            WhichPaused = null;
            clearInterval(timerIdBack);
            timerIdBack = null    
        }
        else // set to false in order start backwardward scrolling
        {
            WhichPaused = null;
            clearInterval(timerIdFore);
            timerIdFore = null;
            timerIdBack = setInterval("scrollbackward()",20);            
        }
    }
}

function scrollbackward()
{
    if(divContent != null && divContainer != null)
    {
        var visibleWidth = parseInt(divContainer.offsetWidth);
        var actualWidth = parseInt(divContent.offsetWidth);
        var invisibleWidth = actualWidth - visibleWidth;       
        var left = Math.abs(parseInt(divContent.style.left));
        if(left < invisibleWidth)
        {
            divContent.style.left = (parseInt(divContent.style.left) - 1) + 'px'; 
        }
        else
        {
            clearInterval(timerIdBack);
            scroll();        
        }
    }
}

function scrollforward()
{
    if(divContent != null && divContainer != null)
    {
        var visibleWidth = parseInt(divContainer.offsetWidth);
        var actualWidth = parseInt(divContent.offsetWidth);
        var invisibleWidth = actualWidth - visibleWidth;       
        var left = Math.abs(parseInt(divContent.style.left));
        if(Math.abs(parseInt(divContent.style.left)) == 0)
        {
            clearInterval(timerIdFore);
            scroll();                
        }
        else
        {
            divContent.style.left = parseInt(divContent.style.left) + 1 + 'px'; 
        }
    }
}

function goForward(container) //From left to right
{
    if(divContent != null && divContainer != null)
    {
        var visibleWidth = parseInt(divContainer.offsetWidth);
        var actualWidth = parseInt(divContent.offsetWidth);
        var invisibleWidth = actualWidth - visibleWidth;      
        if(parseInt(divContent.style.left).toString() == "NaN")
        {
            divContent.style.left = "0px";            
        }
        var left = Math.abs(parseInt(divContent.style.left));
        if(left >= 0)
        {
            for(i=0; i<Math.ceil(visibleWidth/2); i++)
            {
                if(Math.abs(parseInt(divContent.style.left)) == 0)
                {
                    break;
                }
                //setInterval("scrollforward()",20);
                divContent.style.left = parseInt(divContent.style.left) + 1 + 'px'; 
            }
        }
    }
}

function goBackward(container) //From right to left
{
    if(divContent != null && divContainer != null)
    {
        //Need Subtraction
        var visibleWidth = parseInt(divContainer.offsetWidth);
        var actualWidth = parseInt(divContent.offsetWidth);
        var invisibleWidth = actualWidth - visibleWidth;       
        if(parseInt(divContent.style.left).toString() == "NaN")
        {
            divContent.style.left = "0px";
        }
        var left = Math.abs(parseInt(divContent.style.left));
        if(left <= invisibleWidth)
        {
            var actual = invisibleWidth - left;
            if(actual < visibleWidth)
            {
                visibleWidth = actual;                    
            }
            //setInterval("scrollbackward()",20);
            for(i=0; i<Math.ceil(visibleWidth/2); i++)
            {
                divContent.style.left = (parseInt(divContent.style.left) - 1) + 'px'; 
            }
        }
    }
}


//MODIFIED BY ARNAB ON 20.07.2007
function openPasswordDiv()
{
  document.getElementById("profileDiv").style.display = "none";
  document.getElementById("passDiv").style.display = "";
  document.getElementById("profile").style.display = "";
  document.getElementById("pass").style.display = "none";
}

function openProfileDiv()
{
  document.getElementById("profileDiv").style.display = "";
  document.getElementById("passDiv").style.display = "none";
  document.getElementById("profile").style.display = "none";
  document.getElementById("pass").style.display = "";
}

function showCategories()
{
    document.getElementById('divCats').style.display = "block";    
}

function hideCategories()
{
    document.getElementById('divCats').style.display = "none";    
}

