﻿$(function () {

    $("#productswitcher-browse a.backward").click(function () { clearInterval(animinterval); backwardClicked(); return false; });
    $("#productswitcher-browse a.forward").click(function () { clearInterval(animinterval); forwardClicked(); return false; });

    $(".searchfield").keypress(function (event) {
        if (event.keyCode == 13) {
            window.location.href = "search.aspx?q=" + $(this).val();

            return false;
        }
    });
});

var defbuttonsenabled = true;
var animinterval;

function forwardClicked() {
    if (defbuttonsenabled) {
        defbuttonsenabled = false;
        var id = $("input", $(".productdetails")).val();
        
        PageMethods.getProduct(id, true,
            function (result) {
                eval("var r = " + result + ";");

                $(".productdetails").fadeOut(200, function () {
                    $(".linkproduct").attr("href", "product.aspx?id=" + r.Id);
                    $(".productdetails").html(r.Html);
                    $(".productdetails").fadeIn(200);
                    defbuttonsenabled = true;
                });

            }
            );
    }
    return false;
}

function backwardClicked() {
    if (defbuttonsenabled) {
        defbuttonsenabled = false;
        var id = $("input", $(".productdetails")).val();
        PageMethods.getProduct(id, false,
            function (result) {
                eval("var r = " + result + ";");

                $(".productdetails").fadeOut(200, function () {
                    $(".linkproduct").attr("href", "product.aspx?id=" + r.Id);
                    $(".productdetails").html(r.Html);
                    $(".productdetails").fadeIn(200);
                    defbuttonsenabled = true;
                });

            }
            );
    }
    return false;
}
