
  var pngfix = null;

  window.addEvent("domready", function () { 

  // ===============================================================================================================================================================

    document.slider  = new CCPROMO_slider();
    var slider       = document.slider;
    slider.width     = 484;
    slider.height    = 394;
    slider.container = $("CCPROMO_grid_grid_view");

    slider.add_tile($("CCPROMO_grid_grid"));
    slider.add_tile($("CCPROMO_grid_tip"));

    slider.render();

  // ===============================================================================================================================================================

    var x = 0;

    // iterate over each expert

    ["CCPROMO_grid_brooklyn_decker", "CCPROMO_grid_michelle_callahan", "CCPROMO_grid_janine_driver"].each(function (element) {

      $(element).getElements(".CCPROMO_tip").each(function (el) {

        var tips_container = this.element.replace("grid", "tips");

        // set grid click action

        $(el).addEvent("click", function (slider, counter, tips_container) {

          var tip_counter = 0;

          // set correct visibility for tip detail

          $(tips_container).getElements(".CCPROMO_tip_detail").each(function (tip) {

            tip.style.display = (this.counter == this.chosen_tip) ? "block" : "none";

            this.counter++;

          }.bind({"counter"    : tip_counter,
                  "chosen_tip" : counter}));

          $(tips_container).getElements(".CCPROMO_tip_close").each(function (x_button) {

            $(x_button).addEvent("click", function (slider) { slider.back(); }.pass(slider));

          }.bind({"slider" : slider}));

          slider.forward();

        }.pass([this.slider, this.counter, tips_container]));

        this.counter++;

      }.bind({"element" : $(element).id,
              "counter" : x,
              "slider"  : slider}));

    });

    $$(".CCPROMO_tip").each(function (el) {

                              $(el).addEvent("mouseenter", function () {

                                                             this.addClass("selected");
                                                             $(this).getElements(".CCPROMO_get_tip")[0].removeClass("hidden");

                                                           }.bind(el));

                              $(el).addEvent("mouseleave", function () {

                                                             this.removeClass("selected");
                                                             $(this).getElements(".CCPROMO_get_tip")[0].addClass("hidden");

                                                           }.bind(el));

                            });

  // ===============================================================================================================================================================

    $("CCPROMO_content").tweening      = false;
    $("CCPROMO_grid_grid_view").chosen = true;

    function show_list(show_animation) {

      if (!$("CCPROMO_grid_list_view").chosen && !$("CCPROMO_content").tweening) {

        $("CCPROMO_grid_controls_grid").getElements("img")[0].src = "images/gridView-icon_off.gif";
        $("CCPROMO_grid_controls_list").getElements("img")[0].src = "images/listView-icon_on.gif";

        $("CCPROMO_grid_grid_view").style.display = "none";
        $("CCPROMO_grid_list_view").style.display = "block";

        if (show_animation !== false) {

          var slide = new Fx.Slide("CCPROMO_grid_list_view").hide().toggle().chain(function () {
            $("CCPROMO_content").tweening = false;
            $("CCPROMO_grid_grid_view").parentNode.style.height = "auto";
            $("CCPROMO_grid_list_view").parentNode.style.height = "auto";
          });

          $("CCPROMO_content").tweening = true;

        } // end if

        $("CCPROMO_grid_grid_view").parentNode.style.height = "auto"; // reset 3px-border-div to height:auto to resolve a list/grid toggling issue coming in from selecting a specific expert
        $("CCPROMO_grid_list_view").parentNode.style.height = "auto"; // reset 3px-border-div to height:auto to resolve a list/grid toggling issue coming in from selecting a specific expert

        $("CCPROMO_grid_grid_view").chosen = false;
        $("CCPROMO_grid_list_view").chosen = true;

      } // end if

    } // end show_list()

    function show_grid() {

      if (!$("CCPROMO_grid_grid_view").chosen && !$("CCPROMO_content").tweening) {

        $("CCPROMO_grid_controls_grid").getElements("img")[0].src = "images/gridView-icon_on.gif";
        $("CCPROMO_grid_controls_list").getElements("img")[0].src = "images/listView-icon_off.gif";

        $("CCPROMO_grid_grid_view").fade("hide");
        $("CCPROMO_grid_grid_view").style.display = "block";
        $("CCPROMO_grid_list_view").style.display = "none";

        $("CCPROMO_grid_list_view").parentNode.style.height = "0px";
        $("CCPROMO_grid_list_view").parentNode.style.height = "auto";
        $("CCPROMO_grid_grid_view").parentNode.style.height = "auto";

        var fade = new Fx.Tween($("CCPROMO_grid_grid_view"));

        fade.start("opacity", 0.0, 1.0).chain(function () {
          $("CCPROMO_content").tweening = false;
        });

        $("CCPROMO_content").tweening = true;

        $("CCPROMO_grid_grid_view").chosen = true;
        $("CCPROMO_grid_list_view").chosen = false;

      } // end if

    } // end show_grid()

    $("CCPROMO_grid_controls_grid").addEvent("click", function () {

      show_grid();

    });

    $("CCPROMO_grid_controls_grid").addEvent("mouseenter", function () {

      if (!$("CCPROMO_grid_grid_view").chosen) {

        this.getElements("img")[0].src = "images/gridView-icon_on.gif";

      } // end if

    }.bind($("CCPROMO_grid_controls_grid")));

    $("CCPROMO_grid_controls_grid").addEvent("mouseleave", function () {

      if (!$("CCPROMO_grid_grid_view").chosen) {

        this.getElements("img")[0].src = "images/gridView-icon_off.gif";

      } // end if

    }.bind($("CCPROMO_grid_controls_grid")));

    $("CCPROMO_grid_controls_list").addEvent("click", function () {

      show_list();

    });

    $("CCPROMO_grid_controls_list").addEvent("mouseenter", function () {

      if (!$("CCPROMO_grid_list_view").chosen) {

        this.getElements("img")[0].src = "images/listView-icon_on.gif";

      } // end if

    }.bind($("CCPROMO_grid_controls_list")));

    $("CCPROMO_grid_controls_list").addEvent("mouseleave", function () {

      if (!$("CCPROMO_grid_list_view").chosen) {

        this.getElements("img")[0].src = "images/listView-icon_off.gif";

      } // end if

    }.bind($("CCPROMO_grid_controls_list")));

  // ===============================================================================================================================================================

    ["CCPROMO_nav_item_brooklyn_decker", "CCPROMO_nav_item_michelle_callahan", "CCPROMO_nav_item_janine_driver"].each(function (el) {

      // will mootools event still allow parent A tag to work when tabbed-into and Enter is hit? this used to be an inline onclick attribute

      $($(el).parentNode).addEvent("click", function (event) {

        if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) { // ie6 and ie7 require special handling - they prevent onkeydown events from registering from the ENTER key, and instead register as onclick

          if (event.event.srcElement == this.src.href) {

            window.location.href = this.url;

          } else {

            return false;

          } // end if

        } else {

          if ((typeof(MouseEvent) == "undefined") || (MouseEvent && (event.event.constructor == MouseEvent))) {

            return false;

          } // end if

        } // end if

      }.bind({"src" : $(el).parentNode,
              "url" : $(el).parentNode.href}));

      $($(el).parentNode).addEvent("keydown", function (event) {

        if (event.key == "enter") {

          window.location.href = this.url;

        } // end if

      }.bind({"url" : $(el).parentNode.href}));

      // choose an expert

      $(el).addEvent("click", function (slider, element) {

        var expert = element.id.substring("CCPROMO_nav_item_".length);

        pageTracker._trackPageview("/event/promotions/get_closer/choose_" + expert);

        if ($("CCPROMO_content").expert !== expert) {

          // reset slider
          slider.current_tile                               = 0;
          slider.container.getElements("div")[0].style.left = "0px";

          ["brooklyn_decker", "michelle_callahan", "janine_driver"].each(function (expert) {

            $("CCPROMO_profile_" + expert).style.display = (this.chosen_expert == expert) ? "block" : "none";
            $("CCPROMO_grid_"    + expert).style.display = (this.chosen_expert == expert) ? "block" : "none";
            $("CCPROMO_tips_"    + expert).style.display = (this.chosen_expert == expert) ? "block" : "none";
            $("CCPROMO_list_"    + expert).style.display = (this.chosen_expert == expert) ? "block" : "none";
            $("CCPROMO_grid_controls_headline_"    + expert).style.display = (this.chosen_expert == expert) ? "block" : "none";

            if (this.chosen_expert == expert) {

              $("CCPROMO_nav_item_"               + expert).addClass("CCPROMO_selected");
              $("CCPROMO_grid_controls_headline_" + expert).removeClass("hidden");

              $("CCPROMO_content").expert = expert;

            } else {

              $("CCPROMO_nav_item_"               + expert).removeClass("CCPROMO_selected");
              $("CCPROMO_nav_item_"               + expert).removeClass("CCPROMO_load_selected");
              $("CCPROMO_grid_controls_headline_" + expert).addClass("hidden");

            } // end if

          }.bind({"chosen_expert" : expert}));

        } // end if

      }.pass([this.slider, $(el)]));

      $(el).addEvent("mouseenter", function () {

        var expert = this.id.substring("CCPROMO_nav_item_".length);

        if (!this.hasClass("CCPROMO_load_selected") && ($("CCPROMO_content").expert !== expert)) {

          this.addClass("CCPROMO_selected");

        } // end if

      }.bind($(el)));

      $(el).addEvent("mouseleave", function () {

        var expert = this.id.substring("CCPROMO_nav_item_".length);

        if (!this.hasClass("CCPROMO_load_selected") && ($("CCPROMO_content").expert !== expert)) {

          this.removeClass("CCPROMO_selected");

        } // end if

      }.bind($(el)));

    }.bind({"slider" : slider}));

  // ===============================================================================================================================================================

    if (pngfix) { // IE6
  
      pngfix.root = "CCPROMO_content";

      $$(".CCPROMO_profile_bottom img").each(function (el) { el.src = "images/KK.introBack-btm.gif"; });

      pngfix.init();

    } // end if

  // ===============================================================================================================================================================

    if (window.location.href.indexOf("?") > -1) {

      window.location.href.split("?")[1].split("&").each(function (par) {

        var key = par.split("=")[0];

        if (key == "expert") {

          show_list(false);

          $("CCPROMO_grid_controls_grid").style.display = "inline";
          $("CCPROMO_grid_controls_list").style.display = "inline";

        } // end if

      });

    } // end if

  // ===============================================================================================================================================================

  });

