// JavaScript Document

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ($active.length == 0) $active = $('#slideshow IMG:first');

    if ($('#slideshow IMG').length > 1) {
        var $next = $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

        $active.addClass('last-active');

        $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
    }
}

$(function() {
    setInterval("slideSwitch()", 5000);
});


$(document).ready(function() {

    $("#scroll_box a").click(function() {
        $("#scroll_box a").each(function() {

        $(this).removeClass("active");

        });
        $(this).addClass("active");
    });

    $("#navigation ul").addClass("sf-menu");

    $("#left_column").fadeIn();

    $('#scroll_box').jScrollPane({ showArrows: false, scrollbarWidth: 0, scrollbarMargin: 0, animateTo: true });

    if ($('#scroll_box').height() == $('.jScrollPaneContainer').height()) {
        $('#scroll_buttons').hide();
    }

    $('#scrollMore').click(function() {
        var current = $('#scroll_box').css("top");
        var theNumber = parseFloat(current, 10);
        theNumber = -1 * theNumber;
        theNumber = theNumber + 200;
        $('#scroll_box')[0].scrollTo(theNumber);

        $('#scrollPrevious').removeClass("inactive");
        $('#scrollPrevious').addClass("active");

        var bottom = $('#scroll_box').css("bottom");
        var numBottom = parseFloat(bottom, 10);
        numBottom = numBottom + 200;
        if (numBottom > 0) {
            $('#scrollMore').removeClass("active");
            $('#scrollMore').addClass("inactive");
        }
    });

    $('#scrollPrevious').click(function() {
        var current = $('#scroll_box').css("top");
        var theNumber = parseFloat(current, 10);
        theNumber = -1 * theNumber;
        theNumber = theNumber - 200;
        $('#scroll_box')[0].scrollTo(theNumber);

        $('#scrollMore').removeClass("inactive");
        $('#scrollMore').addClass("active");

        if (theNumber <= 0) {
            $('#scrollPrevious').removeClass("active");
            $('#scrollPrevious').addClass("inactive");
        }
    });
});

function LoadProduct(productid) {

    $("div#product").fadeOut("slow", function() {
        $("div#product_loading").fadeIn("slow");
        GetProduct(productid);
    });
}

function GetProduct(productid) {
    $("div#product").load("/Views/Products/Product.aspx", { id: productid },
        function(data) {
    $("div#product_loading").fadeOut("slow", function() { $("div#product").fadeIn("slow"); $('a.lightbox').lightBox(); });
        }
    );
}

function LoadBrand(brandid) {

    $("div#product").fadeOut("slow", function() {
        $("div#product_loading").fadeIn("slow");
        GetBrand(brandid);
    });
}

function GetBrand(brandid) {
    $("div#product").load("/Views/Brands/Brand.aspx", { id: brandid },
        function(data) {
            $("div#product_loading").fadeOut("slow", function() { $("div#product").fadeIn("slow"); });
        }
    );
}
