﻿/// <reference path="jquery-1.3.2.min.js" />
/// <reference path="jquery.url.packed.js" />

(function($) {
    $(document).ready(function() {

        //get the path of the current url, we'll use this to compare to the paths of the other urls
        var currUrl = $.url.attr("path");

        //get the current category query string if there is one
        var currCat = $.url.param("c")

        //the category alias currently displayed
        var catAlias = null;

        //find the category that has the current path or the current query string value and select it...
        var catItem = null;
        if (currCat == null || currCat == "") {
            if (currUrl == "/StorageSolutions/AtticLaddersLanding/BuyOnlineLadders.aspx") {
                catItem = $("#prodCatDropDown option:eq(1)");
            } 
            else{
                //if there is no category, we'll assume that we are currently on a category page
                catItem = $("#prodCatDropDown option[value='" + currUrl + "']");
            }
        }
        else {
            //if there is a cat query string, then select the corresponding item
            catItem = $("#prodCatDropDown option[title='" + currCat + "']");
        }




        if (catItem.length > 0) {
            catItem.attr("selected", "selected");
            catAlias = catItem.attr("title");
        }


        //find the product that has the current path if there is a category...
        if (currCat != null && currCat != "") {
            var prodItem = $("#prodItemDropDown option[value='" + currUrl + "']");
            if (prodItem.length > 0) {
                prodItem.attr("selected", "selected");
            }
        }

        //bind the category lookup button
        $(".productSelector.category input.button").click(function() {
            var selected = $("#prodCatDropDown option:selected");
            var url = selected.val();
            window.location = url;
        });

        //bind the product lookup button
        $(".productSelector.product input.button").click(function() {
            var selected = $("#prodItemDropDown option:selected");
            var url = selected.val() + "?c=" + escape(catAlias);
            window.location = url;
        });

    });
})(jQuery);