/**
 * Wayfarer Carousel
 * Version 0.9.6
 * Author Abel Mohler
 * URI: http://www.wayfarerweb.com/wcarousel.php
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 * 
 * Based on jCarouselLite (modified and improved)
 *
 * http://gmarwaha.com/jquery/jcarousellite/
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.0.1
 */
(function (d) {
	d.fn.wCarousel = function (e, g) {
		e = d.extend({
			prev: null,
			next: null,
			btnGo: null,
			mouseWheel: false,
			auto: null,
			speed: 200,
			easing: null,
			vertical: false,
			circular: true,
			visible: 3,
			start: 0,
			scroll: 1,
			callBefore: null,
			callAfter: null
		},
		e || {});
		if (typeof g == "function") {
			e.callAfter = g
		}
		var f = (typeof d.talk == "function" && typeof d.listen == "function") ? true: false;
		if (f) {
			e.plugin = "wCarousel";
			e.channel = "wayfarer";
			e.key = this;
			d.talk(e)
		}
		return this.each(function () {
			var p = false,
			n = (e.vertical) ? "top": "left",
			i = (e.vertical) ? "height": "width";
			var h = d(this),
			r = d(">ul", h),
			k = d(">li", r),
			w = k.size(),
			u = e.visible;
			if (e.circular) {
				r.prepend(k.slice(w - u - 1 + 1).clone()).append(k.slice(0, u).clone());
				e.start += u
			}
			var t = d("li", r),
			q = t.size(),
			x = e.start;
			h.css("visibility", "visible");
			t.css({
				overflow: "hidden",
				"float": (e.vertical) ? "none": "left"
			});
			r.css({
				margin: "0",
				padding: "0",
				position: "relative",
				"list-style-type": "none",
				"z-index": "1"
			});
			h.css({
				overflow: "hidden",
				position: "relative",
				"z-index": "2",
				left: "0px"
			});
			var m = e.vertical ? a(t) : c(t);
			var s = m * q;
			var o = m * u;
			t.css({
				width: t.width(),
				height: t.height()
			});
			r.css(i, s + "px").css(n, -(x * m));
			h.css(i, o + "px");
			if (e.prev) {
				d(e.prev).click(function () {
					return l(x - e.scroll)
				})
			}
			if (e.next) {
				d(e.next).click(function () {
					return l(x + e.scroll)
				})
			}
			if (e.btnGo) {
				d.each(e.btnGo, function (v, y) {
					d(y).click(function () {
						return l(e.circular ? e.visible + v: v)
					})
				})
			}
			if (e.mouseWheel && h.mousewheel) {
				h.mousewheel(function (v, y) {
					return (y > 0) ? l(x - e.scroll) : l(x + e.scroll)
				})
			}
			if (e.auto) {
				setInterval(function () {
					l(x + e.scroll)
				},
				e.auto + e.speed)
			}
			function j() {
				return t.slice(x).slice(0, u)
			}
			function l(v) {
				if (!p) {
					if (typeof e.callBefore == "function") {
						e.callBefore.call(this, j(), e);
						if (f) {
							e = d.listen(e)
						}
					}
					if (e.circular) {
						if (v < 0) {
							r.css(n, -((q - (u * 2)) * m) + "px");
							x = (v == e.start - u - 1) ? q - (u * 2) - 1 : q - (u * 2) - e.scroll
						} else {
							if (v >= q - u + 1) {
								r.css(n, -((u) * m) + "px");
								x = (v == q - u + 1) ? u + 1 : u + e.scroll
							} else {
								x = v
							}
						}
					} else {
						//alert(v+' '+q+' '+u);
						if (v < 0 || v > q - u) {
							return
						} else {
							x = v
						}
					}
					p = true;
					r.animate(n == "left" ? {
						left: -(x * m)
					}: {
						top: -(x * m)
					},
					e.speed, e.easing, function () {
						p = false;
						if (typeof e.callAfter == "function") {
							e.callAfter.call(this, j(), e);
							if (f) {
								e = d.listen(e)
							}
						}
					});
					if (!e.circular) {
						d(e.prev + "," + e.next).removeClass("disabled");
						d((x - e.scroll < 0 && e.prev) || (x + e.scroll > q - u && e.next) || []).addClass("disabled")
					}
				}
				return false
			}
		})
	};
	function b(e, f) {
		return parseInt(d.css(e[0], f)) || 0
	}
	function c(e) {
		return e[0].offsetWidth + b(e, "marginLeft") + b(e, "marginRight")
	}
	function a(e) {
		return e[0].offsetHeight + b(e, "marginTop") + b(e, "marginBottom")
	}
})(jQuery);
jQuery.fn.activeNav = function () {
	return this.each(function () {
		if (this.href == window.location.href || (this.href == wp_home + '/' + category_nicename + '/') || (this.href == wp_home + '/category/' + category_nicename + '/')) {
			$(this).addClass('active');
		}
		if (window.location.href.match(/\/raw\-search\//) || window.location.href.match(/\/\?filter=4/)) {
			$("#menu-4").addClass("active");
		}
	})
}
