
//*// ### begin
// fix navigation links with preceeding www. if it is not there already
(function (u) {
  if (!u) {
    return;
  }

  var domain = (function (d) {
        while (d.length > 2 && d.shift());

        return d.join(".");
      }(u.split(".")))
      ,env = (u.match(/^beta|www(?:dev[2]?|qa|sb[12]|0[12])?/) || [])[0] || "www"
      ,fixed = env + "." + domain
      ,path = new RegExp(domain + "(.*)")
      ,prefix = new RegExp(fixed);

  $("nav")
    .find("a")
        .map(function (indx, node) {
          if (!prefix.test(node.href)) {
            node.href = "//" + fixed + node.href.match(path)[1];
          }
        });
}(window.location.hostname));
// fix navigation links with preceeding www. if it is not there already
//*// ### finish

!!window.jQuery && (function ($) {

// ### begin
// jQuery Easing functions v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
  $.extend($.easing, {
    "easeInBack": function (x, t, b, c, d, s) {
      s = s || 1.70158;
      return c * (t /= d) * t * ((s + 1) * t - s) + b;
    }
  });
// jQuery Easing;
// ### finish


// ### begin
// Alphabetic Headings 
  $.fn.alphaHeadings = function () {
    return this.each(function () {
      var
        c = 0,
          
        char,
          
        filters = $("<div class=\"alphaFilters\"><p>Filter Products: </p></div>").
          prependTo(this),
          
        fn = function (event) {
          event.preventDefault();
          this.blur();
          var alpha = this.title;
          list.
            hide();
          noProd.hide();
          
          if(map[alpha]) {
            list.
              filter(function () {
                return RegExp("^" + alpha, "i").test($(this).text());
              }).
                show();
          } else {
            noProd.show();
          }
        },
        
        list = $(this).children("dd"),
          
        map = (function (m) {
          list.
            each(function () {
              m[$(this).text().slice(0, 1)] = true; // using slice(0, 1) instead of [0] because of old versions of IE
            });
          return m;
        }({})),
        
        noProd = $("<p>No Products.</p>").
          insertAfter(filters).
          hide();
      
      filters.
        append($("<a>", {
          "click": function (event) {
            this.blur();
            event.preventDefault();
            list.show();
          },
          "href": "#",
          "text": "All"
        }));
      
      while (c++ < 26) {
        char = String.fromCharCode(64 + c);
        filters.
          append($("<a>", {
            "class": !map[char] && "noProducts",
            "click": fn,
            "title": char,
            "href": "#",
            "text": char
          }));
      }
    });
  };
// Alphabetic Headings
// ### finish


// ### begin
// Auto Email Links
  $.fn.autoEmailLinks = function () {
    return this.each(function () {
      var self = $(this),
          tokens = self.text().split("|");
      
      $("<a/>", {
        "text": self.attr("alt") || self.text(),
        "href": "mailto:" + self.text(),
        "title": self.attr("alt") || self.text()
      }).
        replaceAll(self);
    });
  };
// Auto Email Links
// ### finish


// ### begin
// Browse Products  
  $.fn.browseProducts = function () {
    var cache = {},
        menu = this.
          children("ul"),
        
        scrollers = menu.
          children("li").
            filter(function () {
              // filter out any items that do not have a scroller as a child
              return $(this).children(".scroller").length === 1;
            }),
        
        search = window.location.search.match(/f=(.+?)&/);
    
    scrollers.
      click(function () {
        var self = $(this);
        
        // close all that are open
        scrollers.
          not(self).
            removeClass("expanded").
            children(".scroller").
              slideUp(400);
        
        // toggle the clicked slider
        self.
          toggleClass("expanded").
          children(".scroller").
            slideToggle(400);
      }).
      children("a").
        click(function (event) {
          event.preventDefault();
          this.blur();
        }).
        append("<span class=\"sprite\"></span>");
    
    scrollers.
      find("ul a").
        click(function (event) {
          event.preventDefault();
          event.stopPropagation();
          
          var self = $(this),
              
              crumb = /f=([^&]+)/.exec(self.attr("href"))[1] + "/" +
                      /t=([^&]+)/.exec(self.attr("href"))[1].
                        replace(/\+/g, "-").
                        slice(0, -1),
              
              current = self.
                          parent().
                            find("div.products");
          
          // rollup all others
          scrollers.
            find("div.products").
              not(current). // allow toggle to collapse the current list
                slideUp(400);
          
          current.
            slideToggle(400, function () {
              // Needed for older versions of IE not behaving properly 
              ie6 || ie7 && $(this).remove();
            });
          
          // check to see if this menu has been loaded
          if (current.length > 0) {
            // NOTE!: this is duplicated because the response of an AJAX call might not come back fast enough for the following to be outside the "if" block
            //current.slideToggle(400);
          } else {
            $.get("/base/cat/RetrieveProductNode/" + crumb).
              done(function (response) {
                response = $($("<div/>").html($(response)));
                response.
                  addClass("products").
                  appendTo(self.parent()).
                  unbind("click").
                  click(function (event) {
                    event.stopPropagation();
                  });
                
              });
          }
        });
    /*/
    if (search && search[1]) {
      scrollers.
        find("a[href$=" + search[1] + "]").
          click();
    } else {
      scrollers.first().click();
    }
    //*/
  };
// Browse Products
// ### finish


// ### begin
// Bulleted Links
  $.fn.bulleted = function () {
    return this.each(function () {
      $(this).
        prepend($("<span/>", {
          "class": "sprite"
        }));
    });
  };
// Bulleted Links
// ### finish


// ### begin
// Centurion Rotator
  $.fn.centurion_rotator = function (_options) {
    _options = $.extend({}, {
      duration: 600,
      panels: ".panel"
    }, _options);

    return this.
      each(function (indx, DOMobj) {
        if ($(this).find(_options.panels).length < 2) {
          return;
        }
        
        var 
          // centralize the scheduling of the animation so that it doesn't end up all over
          // the place, and so that on initial load it doesn't animate immediately
          animate = function () {
            if (options.auto && !hovering && options.count > 1) {
              // cache the pending timeout so that we can cancel it in the mouse hover
              pending = setTimeout(nextPanel, options.timing);
            }
          },
         
          coins = $("<div/>", {
              "class": "coins",
              "css": {
                "z-index": 2000 // so that the coins are always above the animation
              }
            }),
          
          hovering = false, // state variable for when the mouse hovers; to pause animation

          nextPanel = function () {
            // clearTimeout needs to be here for when a user clicks "next" multiple times
            clearTimeout(pending);
            coins.setCurrent((1 + coins.children("a.current").index()) % panels().length);
            self.
              stop(true).
              transition();
            animate();
          },
          
          // override defaults with options
          options = $.extend({}, {
                timing: parseInt(8000 + Math.random() * 4000, 10)
              }, _options),
              
          panels = function () {
            return self.find(options.panels);
          },
          
          pending, // chache variable for pending timeouts
          
          self = $(this), // cache variable for wrapper element of the slider
          
          slider = $("<div/>", {
            "class": "clearfix",
            "css": {
              "height": (function () {
                return panels().
                  map(function () {return $(this).height();}).
                    sort().
                    toArray().
                    pop();
              }()),
              "position": "relative",
              "width": panels().length * self.width()
            }
          });
        
        options.auto = self.hasClass("banner");
        options.count = panels().length;
        options.effect = (self.hasClass("banner") ? "fade" : "slide");
        
        coins.setCurrent = function (i) {
          return coins.
            children("a").
              removeClass("current").
              eq(i).
                addClass("current");
        };
        
        //*/ setup custom trasition based on if this is a banner or panel slider
        if (options.effect === "slide") {
          panels().
            appendTo(slider.appendTo(self)).
            css({
              "position": "relative",
              "width": self.width()
            });
          self.transition = function (indx) {
            slider.
              animate({
                "left": "-" + self.width() * indx
              }, options.duration);
          };
        } else {
          panels().
            slice(1).
              hide();
          
          // custom transition function for the collection
          self.transition = function (indx) {
            var 
              panes = panels(),
              current = panes.filter(":visible").index();
            indx = (indx > -1 && indx < panes.length) ? indx : (current + 1) % panes.length;
            
            if(!panes.eq(indx).is(":visible")) {
              panes.
                eq(current).
                  css({
                    "z-index": 1000
                  }).
                  end().
                eq(indx).
                  css({
                    "z-index": 1
                  }).
                  show(function () {
                    panes.
                      eq(current).
                        fadeOut(options.duration, function () {
                          panes.
                            css({
                              "z-index": "auto"
                            });
                        });
                  });
            }
          };
        }
        //*/
                
        //*/ add links to "coins" element; with click events to show the proper panel
        if (options.count > 1) {
          coins.
            appendTo(self).
            html((function () {
              var result = $();
              panels().
                each(function () {
                  var target = $(this);
                  result = result.add($("<a/>",{
                    click: function () {
                      if($(this).hasClass("current")) {
                        return;
                      }
                      self.transition(panels().index(target));
                      coins.setCurrent(coins.children("a").index(this));
                    }
                  }));
              });
              return result.
                css({"cursor": "pointer"});
            }()));
          
          coins.transient = self.hasClass("banner")
            ? function () {coins.fadeToggle();}
            : function () {};
          coins.transient();
        }
        //*/
    
        //*/ bring default panels to the forefront of the list
        self.
          children(".default").
            // bring the primary to the front of the stack
            append(self).
            // remove the "primary" class so that the library controls when to show and hide elements not the css
            removeClass("default");
        //*/
        
        /*/ size the viewport of the slider to the max height of the contained panels
        self.
          css({
            "height": parseInt(slider.css("height"), 10) + parseInt(coins.outerHeight(), 10) + parseInt(self.children("h3").outerHeight(), 10)
          });
        //*/
        
        //*/ add hover state management so the animation stops when hovering
        self.
          hoverIntent(function () {
            hovering = true;
            clearTimeout(pending);
            coins.transient();
            panels().stop(true, true);
          }, function () {
            hovering = false;
            animate();
            coins.transient();
          });
        //*/
        
        panels().
          filter("[data-link!=\"\"]").
          click(function() {
            window.location.href = $(this).attr("data-link");
          }).
          css({
            "cursor": "pointer"
          });
        
        // start the animation(s)
        animate();
        coins.setCurrent(0);
        
      });
  };
// Centurion Rotator
// ### finish
  
  
/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)};
  
  
// ### begin
// Image Buttons
  $.fn.imageButtons = function (options) {
    options = $.extend({}, {
    }, options);
    
    var button = $("<button>", {
        "alt": "Perform Search",
        "class": "centurionButton",
        "title": "Submit",
        "type": "submit"
      });
    
    return this.each(function () {
      var self = $(this).hide();
      
      button.
        clone().
        html(self.text() || self.attr("value")).
        appendTo(self.parent()).
        click(function (event) {
          event.preventDefault();
          self.click();
        });
    });
  };
// Image Buttons
// ### finish
  
  
// ### begin
// Play button overlay
  $.fn.playButtonOverlay = function () {
    var pb = $("<span>")
          .addClass("sprite playButtonOverlay")
          .css("opacity", 0.3);
    
    return this.each(function () {
      var self = $(this)
          ,mypb = pb.clone();
      
      self
        .append(mypb)
        .hover(function () {
          mypb
            .stop(true)
            .fadeTo(200, 1);
        },function () {
          mypb
            .stop(true)
            .fadeTo(200, 0.3);
        });
    });
  };
// Play button overlay
// ### finish
  
  
// ### begin
// Product Images
  $.fn.productImages = function (options) {
    options = $.extend({}, {
      duration: 400
      ,opacity: 0.5
      ,rotations: 5
      ,timing: 8000
    }, options);
    
    return this.each(function () {
      // don't do any of the following if it isn't necessary
      if($(this).children("img").length < 2) {
        return this;
      }
      
      var self = $(this),
          
          advance = function (retreat) {
            // stop animating when all images have been shown 4 times
            if(++counter > list.length * options.rotations || hovering) {
              return;
            }
            
            // set this so that the scroller can be positioned back to the correct location on mouseleave
            position = -(imageWidth * (counter % list.length));
            
            // this animation sequence is less jarring than watching a long list of images reset.
            scroller.
              hide().
              css("left", position).
              fadeIn(options.duration);
            
            animate();
          },
          
          animate = function () {
            clearTimeout(pending);
            
            pending = setTimeout(advance, options.timing);
          },
          
          counter = 0, // keep count of image impressions in rotation
          
          hovering = false,
          
          imageWidth = self.find("img").width(),
          
          list, // this gets assign to below when the images have been wrapped in links
          
          more = $("<div/>").
            addClass("moreImages").
            appendTo(self).
            html("More images..."),
          
          pending,
          
          position = 0, // cached value of scroller left-position
          
          scroller = $("<div/>");
      
      // cache these values since it wont change while the page is up
      self.offsetLeft = Math.floor(self.offset().left);
      self.fullWidth = self.outerWidth();
      
      self.
        hover(function () {
          clearTimeout(pending);
          hovering = !hovering;
          !hovering && animate();
          if(!hovering && counter === list.length * options.rotations) {
            counter = 0;
          }
          
          scroller.
            stop(true, true);
        });
      
      /*/ functionality not implemented for now; there are more important things to be doing!
      self.
        hover(function () {
          clearTimeout(pending);
          hovering = !hovering;
          !hovering && animate();
          //counter = 0;
          more.
            fadeToggle(options.duration);
          
          // when the mouse leaves return the scroller to the position it was at when hover started
          !hovering && scroller.css("left", position);
          
          self.
            css("background", "url(" + (hovering ? list.eq(counter).children().attr("src") : "") + ") scroll no-repeat 0px 0px");
          
          scroller.
            css({
              // somehow make scroller into smaller thumbnails
              "zoom": hovering ? 0.5 : 1.0
            }).
            stop(true, true);
        }).
        mousemove(function (e) {
          var loc = e.pageX - self.offsetLeft,
              ratio = loc / self.fullWidth;
          
          scroller.
            css("left", -Math.floor(ratio * (scroller.outerWidth() - imageWidth)));
        });
      //*/
      
      // wrap images in <a href="..."></a> and add colorbox functionality to them
      self.
        children("img").
          attr("title", "Click to navigate images").
          wrap(function () {
            return $("<a/>", {
                "href": this.src,
                "rel": "slideshow" // colorbox plugin needs this to make it a slide show
              });
          });
      
      // put all the newly created links into the scroller div for the hover effect
      list = self.
        children("a").
        colorbox($.extend({}, options, {
          fixed: true,
          onClosed: function () {
            hovering = false;
            animate();
          },
          onComplete: function () {
            // open colorbox
            hovering = true;
            clearTimeout(pending);
          }
        }));
      
      scroller.
        append(list).
        css("position", "absolute"). // needed for animate to work properly
        prependTo(self).
        width(scroller.w = imageWidth * list.length);
      
      animate();
    });
  };
// Product Images
// ### finish


// ### begin
// Product Media
  $.fn.productMedia = function () {
    var anchor
        ,speed = 1200;
    
    this.
      each(function () {
        var mediaNode = $(this);
        mediaNode.
          children("h4").
            append("<span class=\"sprite\"></span>").
            attr("alt", "Expand/Collapse").
            before($("<a/>", {
              "name": $(this).children().first().text()
            })).
            attr("title", "Expand/Collapse").
            click(function () {
              mediaNode.
                toggleClass("collapsed").
                children("h4").
                  next().
                    slideToggle(800);
            }).
            filter(function () {
              return "#" + (this.innerHTML.match(/^\w+/))[0] !== window.location.hash;
            }).
              click().
              end().
            click(function () {
              var h = (this.innerHTML.match(/^\w+/))[0];
              
              // set the hash/anchor value of the url so it is linkable from outside the site
              window.location.hash = h;
              
              // scroll the page to the opened media item
              $("html, body").
                animate({
                  scrollTop: $("a[name=" + h + "]").offset().top
                }, speed);
            });
      });
    
    // when the page is loading, scroll to the indicated media item
    if (window.location.hash) {
      anchor = $("a[name=" + window.location.hash.slice(1) + "]");
      
      anchor.length && $("html, body").
        animate({
          scrollTop: anchor.offset().top
        }, speed);
    }
    
    return this;
  };
// Product Media
// ### finish

  $.fn.reverse = [].reverse;

// ### begin
// Sales Regions Map interactivity
  $.fn.salesRegions = function (options) {
    return this.each(function () {
      var divs = (function (d) {
            var filter = function (str) {
              return d.filter(function () {
                return $(this).children("h3").text().match(RegExp(str));
              });
            };
            return {
              West: filter("West"),
              NorthCentral: filter("North Central"),
              NorthEast: filter("North East"),
              SouthEast: filter("South East")
            };
          }($("div.salesRegionInfo"))),
          self = $(this),
          images = {
            West: self.children("img[id$=West]"),
            NorthCentral: self.children("img[id$=NorthCentral]"),
            NorthEast: self.children("img[id$=NorthEast]"),
            SouthEast: self.children("img[id$=SouthEast]"),
            Warehouses: self.children("img[id$=Warehouses]")
          },
          warehouses = $("#warehouseLocations");
      
      divs.all = $().
        add(divs.West).
        add(divs.NorthCentral).
        add(divs.NorthEast).
        add(divs.SouthEast).
        hide();
      
      images.all = $().
        add(images.West).
        add(images.NorthCentral).
        add(images.NorthEast).
        add(images.SouthEast).
        add(images.Warehouses).
        hide();
      
      warehouses.
        //attr("href", "#").
        click(function (event) {
          event.preventDefault();
        }).
        hoverIntent(function () {
          images.
            Warehouses.
              css("z-index", "100").
              fadeIn();
        }, function () {
          images.
            Warehouses.
            fadeOut(function () {
              $(this).css("z-index", "auto");
            });
        });
      
      self.
        children("img").
          css({
            "z-index": "auto"
          })
        .last().
          prependTo(self);
      
      self.
        find("map area").
          attr("alt", "Click for Contact Information").
          attr("title", "Click for Contact Information").
          hoverIntent(function (e) {
            images.all.stop(true, true);
            
            images[this.href.match(/\w+$/)].
              css("z-index", "100").
              fadeToggle();
              
          }, function () {
            images.all.stop(true, true);
            
            images[this.href.match(/\w+$/)].
              css("z-index", "1").
              fadeToggle();
          }).
          click(function (event) {
            event.preventDefault();
            
            /**/
            $().colorbox({
              fixed: true,
              html: $("<div/>", {"class": "colorbox-innercontent"}).append(divs[this.href.match(/\w+$/)].html()),
              returnFocus: true,
              //title: this.alt,
              width: 350
            });
            /**/
          });
    });
  };
// Sales Regions Map interactivity
// ### finish


// ### begin
// Soiled Linen
  $.fn.soiledLinen = function () {
    var videos = [
        ''
        ,'<!--[if IE]><object width="741" height="524" id="viddlerOuter-b8347ea0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="//www.viddler.com/simple/b8347ea0/"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-b8347ea0"><video id="viddlerVideo-b8347ea0" src="//www.viddler.com/file/b8347ea0/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/b8347ea0/" controls="controls" x-webkit-airplay="allow"></video></object></object><![endif]--> <!--[if !IE]> <!--> <object width="741" height="524" id="viddlerOuter-b8347ea0" type="application/x-shockwave-flash" data="//www.viddler.com/simple/b8347ea0/"> <param name="movie" value="//www.viddler.com/simple/b8347ea0/"> <param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-b8347ea0"> <video id="viddlerVideo-b8347ea0" src="//www.viddler.com/file/b8347ea0/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/b8347ea0/" controls="controls" x-webkit-airplay="allow"></video> </object></object> <!--<![endif]-->'
        ,'<!--[if IE]><object width="741" height="524" id="viddlerOuter-bbc0ee95" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="//www.viddler.com/simple/bbc0ee95/"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-bbc0ee95"><video id="viddlerVideo-bbc0ee95" src="//www.viddler.com/file/bbc0ee95/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/bbc0ee95/" controls="controls" x-webkit-airplay="allow"></video></object></object><![endif]--> <!--[if !IE]> <!--> <object width="741" height="524" id="viddlerOuter-bbc0ee95" type="application/x-shockwave-flash" data="//www.viddler.com/simple/bbc0ee95/"> <param name="movie" value="//www.viddler.com/simple/bbc0ee95/"> <param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-bbc0ee95"> <video id="viddlerVideo-bbc0ee95" src="//www.viddler.com/file/bbc0ee95/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/bbc0ee95/" controls="controls" x-webkit-airplay="allow"></video> </object></object> <!--<![endif]-->'
        ,'<!--[if IE]><object width="741" height="524" id="viddlerOuter-fb458766" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="//www.viddler.com/simple/fb458766/"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=0"><object id="viddlerInner-fb458766"><video id="viddlerVideo-fb458766" src="//www.viddler.com/file/fb458766/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/fb458766/" controls="controls" x-webkit-airplay="allow"></video></object></object><![endif]--> <!--[if !IE]> <!--> <object width="741" height="524" id="viddlerOuter-fb458766" type="application/x-shockwave-flash" data="//www.viddler.com/simple/fb458766/"> <param name="movie" value="//www.viddler.com/simple/fb458766/"> <param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=0"><object id="viddlerInner-fb458766"> <video id="viddlerVideo-fb458766" src="//www.viddler.com/file/fb458766/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/fb458766/" controls="controls" x-webkit-airplay="allow"></video> </object></object> <!--<![endif]-->'
        ,''
        ,'<!--[if IE]><object width="741" height="524" id="viddlerOuter-cc8e577b" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="//www.viddler.com/simple/cc8e577b/"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-cc8e577b"><video id="viddlerVideo-cc8e577b" src="//www.viddler.com/file/cc8e577b/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/cc8e577b/" controls="controls" x-webkit-airplay="allow"></video></object></object><![endif]--> <!--[if !IE]> <!--> <object width="741" height="524" id="viddlerOuter-cc8e577b" type="application/x-shockwave-flash" data="//www.viddler.com/simple/cc8e577b/"> <param name="movie" value="//www.viddler.com/simple/cc8e577b/"> <param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&autoplay=f&disablebranding=0&loop=0&hd=1"><object id="viddlerInner-cc8e577b"> <video id="viddlerVideo-cc8e577b" src="//www.viddler.com/file/cc8e577b/html5mobile/" type="video/mp4" width="741" height="504" poster="//www.viddler.com/thumbnail/cc8e577b/" controls="controls" x-webkit-airplay="allow"></video> </object></object> <!--<![endif]-->'
        ,''
        ,''
      ];
    return this.each(function () {
      var diagram = $(this)
            .clone()
          
          ,heading = $(this)
            .closest("article")
              .find("h2, h3, h4, h5")
                .first();
      
      diagram
        .find("ol li")
          .each(function (indx, node) {
            node.id = "soiledLinen-0" + (1 + indx);
            
            if (videos[indx] === '') {
              $(node)
                .children("a")
                  .colorbox()
                  .closest("li")
                    .addClass("zoom");
            } else {
              $(node)
                .click(function (event) {
                  event.preventDefault();
                  $().colorbox({
                    html: videos[indx]
                    ,innerHeight: ~~(videos[indx].match(/height=.?(\d+).?/))[1] + 5
                    ,innerWidth: ~~(videos[indx].match(/width=.?(\d+).?/))[1]
                  });
                })
                .closest("li")
                  .addClass("zoom");
            }
          });
    
      $("section")
        .empty()
        .append($("<article>"))
        .children()
          .first()
            .addClass("grid_12 alpha")
            .append(heading, diagram);
      
      $("header, footer")
        .remove();
      
      $("section")
        .css("border", 0);
    });
  };
// Soiled Linen
// ### finish


// ### begin
// Vertical Slider rewrite
  $.fn.verticalSlider = function (options) {
    options = $.extend({}, {
      duration: 1200
      ,limit: 3
      ,panels: ".panel"
      ,rotations: 3
      ,timing: 7000
    }, options);

    function fnPanels (wrapper, selector) {
      return function () { return wrapper.find(selector); };
    };

    function getHeights (indx, node) {
      return ~~($(node).outerHeight(true));
    };

    function getSum (seed, node) {
      return seed + node;
    };

    return this.each(function () {

      var self = $(this)

          ,panels = fnPanels(self, options.panels)

          ,height = (panels()
            .addClass("clearfix"))
            .map(getHeights)
            .toArray()
            .sort()
            .slice(-options.limit)
            .reduce(getSum)

          ,heightPlus = self
            .children()
            .not(panels())
            .addClass("clearfix")
            .map(getHeights)
            .toArray()
            .reduce(getSum)
          
          ,hovering = false

          ,impressions = 0

          ,maxImpressions = panels().length * options.rotations

          ,pending

          ,schedule = function () {
            clearTimeout(pending);
            if (!hovering && maxImpressions > impressions) {
              pending = setTimeout(slide, options.timing);
            }
          }

          ,slide = function () {
            panels()
              .eq(options.limit - 1)
                .slideUp(options.duration)
                .end()
              .last()
                .insertBefore(panels().first())
                .slideDown(options.duration, schedule);
          };
      
      if (panels().length > options.limit) {
        self
          .css("height", heightPlus + height)
          .hover(function () {
            (hovering = !hovering)
              ? panels().stop(true, true) && clearTimeout(pending)
              : schedule();
          });

        panels()
          .not(panels().slice(0, options.limit))
          .hide();

        schedule();
      }
    });
  };
// Vertical Slider rewrite
// ### finish
}(jQuery));
