function ListGoodsView(id) {
    var margin = $("#goodsView").css('margin-top').substr(0, $("#goodsView").css('margin-top').length - 2) * -1;
    var new_margin = 0;
    var max_margin = num_tables * 431 - 431;

    if (id == 1)
        new_margin = margin + 431;
    else
        new_margin = margin - 431;

    if (new_margin > 0 && new_margin < 85)
        new_margin = 0;
    else if (new_margin < 0)
        new_margin = max_margin;
    else if (new_margin < max_margin && new_margin > max_margin - 431)
        new_margin = max_margin;
    else if (new_margin > max_margin)
        new_margin = 0;

    var old_margin = new_margin;

    if (id == 1)
        new_margin += 50;
    else
        new_margin -= 50;

    new_margin *= -1;
    old_margin *= -1;

    $("#goodsView").animate({
        marginTop:new_margin + "px"
    }, 700, function () {
        $("#goodsView").animate({
            marginTop:old_margin + "px"
        }, 500)
    });
}

function ListMiniView(id) {
    var margin = $("#miniGoodsView").css('margin-top').substr(0, $("#miniGoodsView").css('margin-top').length - 2) * -1;
    var new_margin = 0;
    var max_margin = goodsListLength * 85 - 538;

    if (id == 1)
        new_margin = margin + 85;
    else
        new_margin = margin - 85;

    if (new_margin > 0 && new_margin < 85)
        new_margin = 0;
    else if (new_margin < 0)
        new_margin = max_margin;
    else if (new_margin < max_margin && new_margin > max_margin)
        new_margin = max_margin;
    else if (new_margin > max_margin)
        new_margin = 0;

    $("#miniGoodsView").css('margin-top', "-" + new_margin + "px");
}

function ChangeImageMode(mode) {
    if (mode) {
        $("#d360").attr('src', '/images/360d.gif');
        $("#onlyPhoto").attr('src', '/images/photo_a.gif');
        imageMode = 1;
        $("#imageModeScrollPrev").hide();
        $("#imageModeScrollNext").hide();
    }
    else {
        $("#d360").attr('src', '/images/360d_a.gif');
        $("#onlyPhoto").attr('src', '/images/photo.gif');
        imageMode = 0;
        $("#imageModeScrollPrev").show();
        $("#imageModeScrollNext").show();
    }
}

function ChangeModeImage(id) {
    var new_image = activeGoodImage + id;

    if (new_image >= goodsImagesList.length)
        new_image = 0;

    if (new_image < 0)
        new_image = goodsImagesList.length - 1;

    $("#goodImage").hide();
    $("#goodImage").attr('src', goodsImagesList[new_image].src);
    $("#goodImage").fadeIn(500, function () {
    });

    activeGoodImage = new_image;
}

function ShowSize(shop) {
    $("#shop_" + activeShopSize).hide();
    $("#sizeHref_" + activeShopSize).css('color', '#ED0000');

    $("#shop_" + shop).show();
    $("#sizeHref_" + shop).css('color', '#000000');

    activeShopSize = shop;

    return false;
}

function ShowShop(shop) {
    $("#shopLayer_" + shop).show();
    ShowSize(shop);

    return false;
}

function HideShop(shop) {
    $(".shopLayer").hide();

    return false;
}

function ChangePanelImage(rnd) {
    var current = ($('div#rotator div.show') ? $('div#rotator div.show') : $('div#rotator div:first'));
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator div:first') : current.next()) : $('div#rotator div:first'));
    next.css({opacity:0.0})
        .addClass('show')
        .animate({opacity:1.0}, 1000);
    current.animate({opacity:0.0}, 1000)
        .removeClass('show');
}

$(document).ready(function () {
    $(".mainLayer").fadeIn(1000, function () {
    });

    $('div#rotator div').css({opacity:0.0, display:'block'});
    $('div#rotator div:first').css({opacity:1.0});

    $("#menuId1").hover(
        function () {
            $("#blackMenuAnim1").animate({
                    width:196
                }, 500);
        },
        function () {
            $("#blackMenuAnim1").animate({
                                width:0
                            }, 500);
        }
    );

    $("#menuId2").hover(
            function () {
                $("#blackMenuAnim2").animate({
                        width:196
                    }, 500);
            },
            function () {
                $("#blackMenuAnim2").animate({
                                    width:0
                                }, 500);
            }
        );

    $("#menuId3").hover(
            function () {
                $("#blackMenuAnim3").animate({
                        width:196
                    }, 500);
            },
            function () {
                $("#blackMenuAnim3").animate({
                                    width:0
                                }, 500);
            }
        );

    $('a.lightbox').lightBox();
});
