var hovering;
var currselected;
var buttonhover;
var timer;
$(document).ready(function() {
    if($(".vertical").length > 0) {
        resize();
        $(window).resize(resize);
    }
    $(function() {
        // initialize scrollable
        $("#list").scrollable({
            vertical:true,
            size: 5,
            easing: "linear",
            speed: 500
        });
    });
    // attach to up/down buttons
//    $(".prevPage").mouseover(function (){
//        buttonhover = true;
//        scroll(this);
//    });
//    $(".prevPage").mouseout(function (){
//        buttonhover = false;
//        clearTimeout(timer);
//    });
//    $(".nextPage").mouseover(function (){
//        buttonhover = true;
//        scroll(this);
//    });
//    $(".nextPage").mouseout(function (){
//        buttonhover = false;
//        clearTimeout(timer);
//    });

    // attach to li mouseovers
    /*$("#list").find("li a").mouseover(function (){
        try
        {
                googlecartWidget.close();
        }
        catch(exception)
        {
            // dont care but stop ie breaking here
        }
        hovering = true;
        var id = this.id;
        $("#normalcontent").hide();
        $("#hovercontent").load("./services/FetchTea.php", {TeaID:id}).show();
        
    });
    $("#list").find("li a").mouseout(function (){
        hovering = false;
        setTimeout('swapBack();',1000);
    });*/
    $("#list").find("li a").click(function (){
        var id = this.id;
        $(currselected).removeClass("selected");
        currselected = this;
        $(this).addClass("selected");
        $("#normalcontent").load("./services/FetchTeaDetails.php", {TeaID:id});
        $("#hovercontent").hide();
        $("#normalcontent").show();

    });
});

function swapBack()
{
    
    if(!hovering)
    {
        $("#hovercontent").hide();
        $("#normalcontent").show();
    }
}

function scroll(button)
{
    if(buttonhover){
        $(button).click();
        timer = setTimeout(function() {scroll(button);}, 500);
    }
}

function resize()
{
    if($(".vertical").length > 0) {
        var height = document.body.clientHeight - 460;
        $(".vertical")[0].style.height = height + "px";
    }
}

