﻿$(document).ready(function () {
    var bypassSelectedCheck = true;
    // PRODUCTS
    //PRODUCT BAR
    $("img.productBar").click(
        function () {
            var id = $(this).parent().parent().attr("data-categoryid");
            var paddingTop = "10px"
            //change sizes of category images
            $("#productCategories>ul>li.selected>a>img").animate({ 'width': '45%', 'padding-top': '55px' }, 400);

            $(this).animate({ 'width': '100%', 'padding-top': paddingTop }, 400);

            $("#productCategories>ul>li.selected").removeClass("selected");
            $(this).parent().parent().addClass("selected");

            //move to the correct element in the arrowbar
            $(".arrowBar ul li[data-categoryid=" + id + "]").trigger("click", false);
        });


    //ARROW BAR
    $(".arrowBar ul li").click(function (sender, args) {
        var position = $(this).offset().left;
        var existingPosition = $(".arrowBar ul li.selected").offset().left;
        var backgroundX = 0;
        var suffix = "px 0";
        var width = 0;
        var margin = 0;
        var padding = 0;
        var id = $(this).attr("data-categoryid");

        //where does this link come in the list
        var index = $(this).index() - $(".arrowBar ul li.selected").index();

        //exit if already selected
        if ($(this).hasClass("selected")) {
            return false;
        }

        //get width and margin
        width = parseInt($(".arrowBar>ul>li").css("width"));
        margin = parseInt($(".arrowBar>ul>li").css("margin-left")) + parseInt($(".arrowBar>ul>li").css("margin-right"));
        padding = parseInt($(".arrowBar>ul>li").css("padding-left")) + parseInt($(".arrowBar>ul>li").css("padding-right"));

        var marginLeft = $("img.arrow").css('margin-left');
        marginLeft = marginLeft.split(" ")[0].replace("px", "");


        //set new background value
        marginLeft = parseInt(marginLeft) + ((margin + padding + width) * parseInt(index)); //165

        //move the background to the new position
        $(".arrow").stop().animate({ 'margin-left': marginLeft }, 500);

        //set the selected item
        $(".arrowBar ul li.selected").removeClass("selected");
        $(this).addClass("selected");

        if (args != false) {
            if ($("#productCategories")) {
                //move to the correct element in the category bar
                $("#productCategories li[data-categoryid=" + id + "] img").trigger("click");
            }
        }
    });
    var id = 0;
    
    if ($("#productCategories").length > 0) {
        id = $("#productCategories li.selected img").parent().parent().attr("data-categoryid");
        $(".arrowBar ul li[data-categoryid=" + id + "]").trigger("click");
    }
    else {
        id = $(".arrowBar ul li a.selected").parent().attr("data-categoryid");
        $(".arrowBar ul li[data-categoryid=" + id + "]").trigger("click");
    }

});

var disAllowRightClick = function (who, event) {
    if (event.which == 2 | event.which == 3) {
        if (event.isPropagationStopped() == false) {
            alert("right click functionality has been disabled");
        }
        event.stopPropagation()
        return false;
    }
};



