/**
* 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
*/
(function ($) { $.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) } })(jQuery);


/*
* Superfish v1.4.8 - jQuery menu widget
* Copyright (c) 2008 Joel Birch
*
* Dual licensed under the MIT and GPL licenses:
* 	http://www.opensource.org/licenses/mit-license.php
* 	http://www.gnu.org/licenses/gpl.html
*
* CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
*/

; (function ($)
{
  $.fn.superfish = function (op)
  {

    var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="', c.arrowClass, '"> &#187;</span>'].join('')),
			over = function ()
			{
			  var $$ = $(this), menu = getMenu($$);
			  clearTimeout(menu.sfTimer);
			  $$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function ()
			{
			  var $$ = $(this), menu = getMenu($$), o = sf.op;
			  clearTimeout(menu.sfTimer);
			  menu.sfTimer = setTimeout(function ()
			  {
			    o.retainPath = ($.inArray($$[0], o.$path) > -1);
			    $$.hideSuperfishUl();
			    if (o.$path.length && $$.parents(['li.', o.hoverClass].join('')).length < 1) { over.call(o.$path); }
			  }, o.delay);
			},
			getMenu = function ($menu)
			{
			  var menu = $menu.parents(['ul.', c.menuClass, ':first'].join(''))[0];
			  sf.op = sf.o[menu.serial];
			  return menu;
			},
			addArrow = function ($a) { $a.addClass(c.anchorClass).append($arrow.clone()); };

    return this.each(function ()
    {
      var s = this.serial = sf.o.length;
      var o = $.extend({}, sf.defaults, op);
      o.$path = $('li.' + o.pathClass, this).slice(0, o.pathLevels).each(function ()
      {
        $(this).addClass([o.hoverClass, c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
      });
      sf.o[s] = sf.op = o;

      $('li:has(ul)', this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over, out).each(function ()
      {
        if (o.autoArrows) addArrow($('>a:first-child', this));
      })
			.not('.' + c.bcClass)
				.hideSuperfishUl();

      var $a = $('a', this);
      $a.each(function (i)
      {
        var $li = $a.eq(i).parents('li');
        $a.eq(i).focus(function () { over.call($li); }).blur(function () { out.call($li); });
      });
      o.onInit.call(this);

    }).each(function ()
    {
      var menuClasses = [c.menuClass];
      if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
      $(this).addClass(menuClasses.join(' '));
    });
  };

  var sf = $.fn.superfish;
  sf.o = [];
  sf.op = {};
  sf.IE7fix = function ()
  {
    var o = sf.op;
    if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity != undefined)
      this.toggleClass(sf.c.shadowClass + '-off');
  };
  sf.c = {
    bcClass: 'sf-breadcrumb',
    menuClass: 'sf-js-enabled',
    anchorClass: 'sf-with-ul',
    arrowClass: 'sf-sub-indicator',
    shadowClass: 'sf-shadow'
  };
  sf.defaults = {
    hoverClass: 'sfHover',
    pathClass: 'overideThisToUse',
    pathLevels: 1,
    delay: 800,
    animation: { opacity: 'show' },
    speed: 'normal',
    autoArrows: true,
    dropShadows: true,
    disableHI: false, 	// true disables hoverIntent detection
    onInit: function () { }, // callback functions
    onBeforeShow: function () { },
    onShow: function () { },
    onHide: function () { }
  };
  $.fn.extend({
    hideSuperfishUl: function ()
    {
      var o = sf.op,
				not = (o.retainPath === true) ? o.$path : '';
      o.retainPath = false;
      var $ul = $(['li.', o.hoverClass].join(''), this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility', 'hidden');
      o.onHide.call($ul);
      return this;
    },
    showSuperfishUl: function ()
    {
      var o = sf.op,
				sh = sf.c.shadowClass + '-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility', 'visible');
      sf.IE7fix.call($ul);
      o.onBeforeShow.call($ul);
      $ul.animate(o.animation, o.speed, function () { sf.IE7fix.call($ul); o.onShow.call($ul); });
      return this;
    }
  });

})(jQuery);

// innerfade http://medienfreunde.com

(function ($)
{

  $.fn.innerfade = function (options)
  {
    return this.each(function ()
    {
      $.innerfade(this, options);
    });
  };

  $.innerfade = function (container, options)
  {
    var settings = {
      'animationtype': 'fade',
      'speed': 'normal',
      'type': 'sequence',
      'timeout': 2000,
      'containerheight': 'auto',
      'runningclass': 'innerfade',
      'children': null
    };
    if (options)
      $.extend(settings, options);
    if (settings.children === null)
      var elements = $(container).children();
    else
      var elements = $(container).children(settings.children);
    if (elements.length > 1)
    {
      $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
      for (var i = 0; i < elements.length; i++)
      {
        $(elements[i]).css('z-index', String(elements.length - i)).css('position', 'absolute').hide();
      };
      if (settings.type == "sequence")
      {
        setTimeout(function ()
        {
          $.innerfade.next(elements, settings, 1, 0);
        }, settings.timeout);
        $(elements[0]).show();
      } else if (settings.type == "random")
      {
        var last = Math.floor(Math.random() * (elements.length));
        setTimeout(function ()
        {
          do
          {
            current = Math.floor(Math.random() * (elements.length));
          } while (last == current);
          $.innerfade.next(elements, settings, current, last);
        }, settings.timeout);
        $(elements[last]).show();
      } else if (settings.type == 'random_start')
      {
        settings.type = 'sequence';
        var current = Math.floor(Math.random() * (elements.length));
        setTimeout(function ()
        {
          $.innerfade.next(elements, settings, (current + 1) % elements.length, current);
        }, settings.timeout);
        $(elements[current]).show();
      } else
      {
        alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
      }
    }
  };

  $.innerfade.next = function (elements, settings, current, last)
  {
    if (settings.animationtype == 'slide')
    {
      $(elements[last]).slideUp(settings.speed);
      $(elements[current]).slideDown(settings.speed);
    } else if (settings.animationtype == 'fade')
    {
      $(elements[last]).fadeOut(settings.speed);
      $(elements[current]).fadeIn(settings.speed, function ()
      {
        removeFilter($(this)[0]);
      });
    } else
      alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
    if (settings.type == "sequence")
    {
      if ((current + 1) < elements.length)
      {
        current = current + 1;
        last = current - 1;
      } else
      {
        current = 0;
        last = elements.length - 1;
      }
    } else if (settings.type == "random")
    {
      last = current;
      while (current == last)
        current = Math.floor(Math.random() * elements.length);
    } else
      alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
    setTimeout((function ()
    {
      $.innerfade.next(elements, settings, current, last);
    }), settings.timeout);
  };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element)
{
  if (element.style.removeAttribute)
  {
    element.style.removeAttribute('filter');
  }
}

// beforeafter http://www.catchmyfame.com/2009/06/25/jquery-beforeafter-plugin/

(function (a) { a.fn.extend({ beforeAfter: function (b) { var d = { animateIntro: false, introDelay: 1000, introDuration: 1000, showFullLinks: true, imagePath: "/cedar-shingles-before-after/images/" }; var b = a.extend(d, b); var c = Math.round(Math.random() * 100000000); return this.each(function () { var e = b; var h = a(this); var n = a("img:first", h).width(); var p = a("img:first", h).height(); a(h).width(n).height(p).css({ overflow: "hidden", position: "relative", padding: "0" }); var m = a("img:first", h).attr("src"); var j = a("img:last", h).attr("src"); a("img:first", h).attr("id", "beforeimage" + c); a("img:last", h).attr("id", "afterimage" + c); a("img", h).remove(); a("div", h).css("float", "left"); a(h).prepend('<div id="dragwrapper' + c + '"><div id="drag' + c + '"><img width="8" height="56" alt="handle" src="' + e.imagePath + 'handle.gif" title="Drag me left or right to see the before and after images" id="handle' + c + '" /></div></div>'); a("#dragwrapper" + c).css({ position: "absolute", padding: "0", left: (n / 2) - (a("#handle" + c).width() / 2) + "px", "z-index": "20" }).width(a("#handle" + c).width()).height(p); a("#dragwrapper" + c).css({ opacity: 0.25 }); a("div:eq(2)", h).height(p).width(n / 2).css({ "background-image": "url(" + m + ")", position: "absolute", overflow: "hidden", left: "0px", "z-index": "10" }); a("div:eq(3)", h).height(p).width(n).css({ "background-image": "url(" + j + ")", position: "absolute", overflow: "hidden", right: "0px" }); a("#drag" + c).width(2).height(p).css({ background: "#888", position: "absolute", left: "3px" }); a("#beforeimage" + c).css({ position: "absolute", top: "0px", left: "0px" }); a("#afterimage" + c).css({ position: "absolute", top: "0px", right: "0px" }); a("#handle" + c).css({ "z-index": "100", position: "relative", cursor: "pointer", top: (p / 2) - (a("#handle" + c).height() / 2) + "px", left: "-3px" }); a(h).append('<img src="' + e.imagePath + 'lt-small.png" width="7" height="15" id="lt-arrow' + c + '"><img src="' + e.imagePath + 'rt-small.png" width="7" height="15" id="rt-arrow' + c + '">'); if (e.showFullLinks) { a(h).after('<div class="balinks" id="links' + c + '" style="position:relative"><span class="bflinks"><a id="showleft' + c + '" href="javascript:void(0)">Show only before</a></span><span class="bflinks"><a id="showright' + c + '" href="javascript:void(0)">Show only after</a></span></div>'); a("#links" + c).width(n); a("#showleft" + c).css({ position: "relative", left: "0px" }).click(function () { a("div:eq(2)", h).animate({ width: n }, 200); a("#dragwrapper" + c).animate({ left: n - a("#dragwrapper" + c).width() + "px" }, 200) }); a("#showright" + c).css({ position: "absolute", right: "0px" }).click(function () { a("div:eq(2)", h).animate({ width: 0 }, 200); a("#dragwrapper" + c).animate({ left: "0px" }, 200) }) } var g = a("#dragwrapper" + c).offset(); var k = g.left; var i = a("div:eq(2)", h).width(); var f = a("div:eq(3)", h).width(); a("#dragwrapper" + c).draggable({ handle: a("#handle" + c), containment: h, axis: "x", drag: function (q, o) { var s = a(this).offset(); var r = s.left - k; a("div:eq(2)", h).width(i + r); a("#lt-arrow" + c).stop().animate({ opacity: 0 }, 0); a("#rt-arrow" + c).stop().animate({ opacity: 0 }, 0) } }); if (e.animateIntro) { a("div:eq(2)", h).width(n); a("#dragwrapper" + c).css("left", n - (a("#dragwrapper" + c).width() / 2) + "px"); setTimeout(function () { a("#dragwrapper" + c).css({ opacity: 1 }).animate({ left: (n / 2) - (a("#dragwrapper" + c).width() / 2) + "px" }, e.introDuration, function () { a("#dragwrapper" + c).animate({ opacity: 0.25 }, 1000) }); a("div:eq(2)", h).width(n).animate({ width: n / 2 + "px" }, e.introDuration, function () { l() }) }, e.introDelay) } else { l() } function l() { a(h).hover(function () { a("#lt-arrow" + c).stop().css({ "z-index": "20", position: "absolute", top: p / 2 - a("#lt-arrow" + c).height() / 2 + "px", left: parseInt(a("#dragwrapper" + c).css("left")) - 10 + "px" }).animate({ opacity: 1, left: parseInt(a("#lt-arrow" + c).css("left")) - 6 + "px" }, 200); a("#rt-arrow" + c).stop().css({ position: "absolute", top: p / 2 - a("#lt-arrow" + c).height() / 2 + "px", left: parseInt(a("#dragwrapper" + c).css("left")) + 10 + "px" }).animate({ opacity: 1, left: parseInt(a("#rt-arrow" + c).css("left")) + 6 + "px" }, 200); a("#dragwrapper" + c).animate({ opacity: 1 }, 200) }, function () { a("#lt-arrow" + c).animate({ opacity: 0, left: parseInt(a("#lt-arrow" + c).css("left")) - 6 + "px" }, 350); a("#rt-arrow" + c).animate({ opacity: 0, left: parseInt(a("#rt-arrow" + c).css("left")) + 6 + "px" }, 350); a("#dragwrapper" + c).animate({ opacity: 0.25 }, 350) }); a(h).click(function (q) { var r = q.pageX - this.offsetLeft; var o = n - r; a("#dragwrapper" + c).stop().animate({ left: r - (a("#dragwrapper" + c).width() / 2) + "px" }, 600); a("div:eq(2)", h).stop().animate({ width: r + "px" }, 600); a("#lt-arrow" + c).stop().animate({ opacity: 0 }, 50); a("#rt-arrow" + c).stop().animate({ opacity: 0 }, 50) }); a(h).one("mousemove", function () { a("#dragwrapper" + c).stop().animate({ opacity: 1 }, 500) }) } }) } }) })(jQuery);

$(document).ready(function ()
{
  // Initialize top nav

  $('ul.sf-menu').superfish(
  {
    delay: 500,
    animation: { opacity: 'show' },
    speed: 'fast',
    autoArrows: false,
    dropShadows: false
  });

  $('a[rel="external"]').click(function ()
  {
    window.open($(this).attr('href'));
    return false;
  });

  $(".clickableDiv").css("cursor", "pointer");

  $(".clickableDiv").click(function ()
  {
    window.location = $(this).find("a").attr("href");
    
    return false;
  });
}); 
