var bosFItems = 0;
var bosFCItem = 0;
var bosFPItem = 0;
var bosFTimerOn = 0;

function bosFShow(a_id)
{
    if (bosFCItem != a_id)
    {
        bosFPItem = bosFCItem;
        bosFCItem = a_id;

        document.getElementById('bosFThumb' + bosFPItem).className = "bosFItem";
        document.getElementById('bosFThumb' + bosFCItem).className = "bosFActiveItem";

        document.getElementById('bosFItem' + bosFCItem).style.zIndex = 3;
        document.getElementById('bosFItem' + bosFPItem).style.zIndex = 2;        
        $("#bosFItem" + bosFPItem).show();

        //bosFTransition = Math.floor(Math.random() * (6) + 1);
        bosFTransition = 2;

        if (bosFTransition == 1)
        {//1 = slide down
            $("#bosFItem" + bosFCItem).slideDown("slow");
        }
        else if (bosFTransition == 2)
        {//2 = fade
            $("#bosFItem" + a_id).fadeIn("slow");
        }
        else if (bosFTransition == 3)
        {//3 = center slide
            $("#bosFItem" + a_id).width("0");
            document.getElementById('bosFItem' + bosFCItem).style.marginLeft = "50%";
            document.getElementById('bosFItem' + bosFCItem).style.opacity = "0";
            document.getElementById('bosFItem' + bosFCItem).style.filter = "alpha (opacity = 0)";
            $("#bosFItem" + a_id).animate({ opacity: "1", width: "100%", marginLeft: "0%" }, "slow");
        }
        else if (bosFTransition == 4)
        {//4 = middle slide
            $("#bosFItem" + a_id).height("-=150");
            document.getElementById('bosFItem' + bosFCItem).style.marginTop = "75px";
            document.getElementById('bosFItem' + bosFCItem).style.opacity = "0";
            document.getElementById('bosFItem' + bosFCItem).style.filter = "alpha (opacity = 0)";
            $("#bosFItem" + a_id).animate({ opacity: "1", height: "+=150", marginTop: "0" }, "slow");
        }
        else if (bosFTransition == 5)
        {//5 = slide from left
            $("#bosFItem" + a_id).width("-=400");
            document.getElementById('bosFItem' + bosFCItem).style.opacity = "0";
            document.getElementById('bosFItem' + bosFCItem).style.filter = "alpha (opacity = 0)";
            $("#bosFItem" + a_id).animate({ opacity: "1", width: "+=400" }, "slow");
        }
        else
        {//6 = slide from right
            $("#bosFItem" + a_id).width("-=400");
            document.getElementById('bosFItem' + bosFCItem).style.marginLeft = "+400px";
            document.getElementById('bosFItem' + bosFCItem).style.opacity = "0";
            document.getElementById('bosFItem' + bosFCItem).style.filter = "alpha (opacity = 0)";
            $("#bosFItem" + a_id).animate({ opacity: "1", width: "+=400", marginLeft: "-=400" }, "slow");
        }
        
        $("#bosFItem" + a_id).show();
        bosFHide();
    }
}

function bosFInitiate()
{
    for (l_i = 0; l_i < 20; l_i++)
    {
        if (document.getElementById('bosFThumb' + l_i) && document.getElementById('bosFItem' + l_i))
        {
            bosFItems++;
        }
        else
        {
            break;
        }
    }

    if (bosFItems > 0)
    {
        bosFCItem = bosFItems - 1;
        bosFShow(0);
        bosFTimerToggle();
    }
}

function bosFHide()
{
    for (l_i = 0; l_i < bosFItems; l_i++)
    {
        if (l_i != bosFPItem && l_i != bosFCItem)
        {
            document.getElementById('bosFThumb' + l_i).className = "bosFItem";
            document.getElementById('bosFItem' + l_i).className = "bosFItem";
            $("#bosFItem" + l_i).hide();
        }
    }
}

function bosFTimerToggle()
{
    if (bosFTimerOn == 0)
    {
        bosFTimerInterval = setInterval("bosFNext()", 4000);
        bosFTimerOn = 1;
    }
    else
    {
        clearInterval(bosFTimerInterval);
        bosFTimerOn = 0;
    }
}

function bosFNext()
{
    if (bosFCItem == bosFItems - 1)
    {//start at first
        bosFShow(0);
    }
    else
    {//show the next one
        bosFShow(bosFCItem + 1);
    }
}

$(document).ready(bosFInitiate());
