/// <reference path="jquery-1.5.js" />
var EventBubble = function (calendar, items) {
	var self = this;
	var bubbleMarkup = '<div id="eventBubble" ><div class="bubbleWrapper"><div class="top"><div class="left"></div><div class="mid"></div><div class="right"></div></div><div class="bubbleBox"><div class="bubbleContent"><h3><a href="">Dette er tittelen på en aktivitet</a></h3><div class="date"></div><p></p><a href="http:///">Link til event</a></div></div><div class="bottom"><div class="left"></div><div class="mid"></div><div class="right"></div></div><div class="closeMe"></div></div><div class="bubbleArrow"></div></div>';
	this.calendar = $(calendar);
	this.items = $(items);
	$("body").append(bubbleMarkup);
	this.bubble = $("#eventBubble");
	this.eventContent = $(".bubbleContent", this.bubble);
	this.bubble.isOpen = false;
	this.eventTitle = $("h3 a", this.eventContent);
	this.eventDate = $(".date", this.eventContent);
	this.eventInfo = $("p", this.eventContent);
	this.eventLink = $("p", this.eventContent);
	this.bubbleArrow = $(".bubbleArrow", this.bubble);
	this.onEventSelected = function (event) {
		var clickedItem = event.data;
		//console.log(clickedItem);
		var calOffset = self.calendar.offset();
		var clickTop = event.pageY - calOffset.top;
		var clickLeft = event.pageX - calOffset.left;
		self.eventTitle.text("");
		self.eventDate.text("");
		self.eventInfo.text("");
		//self.eventTitle.text("");
		self.eventTitle.text(clickedItem.attr("title"));
		self.eventDate.text("");
		self.eventInfo.text("");
		if (self.bubble.hasClass("over")) {
			self.bubble.removeClass("over");
		}
		if (self.bubble.hasClass("under")) {
			self.bubble.removeClass("under");
		}
		if (self.bubble.hasClass("left")) {
			self.bubble.removeClass("left");
		}
		if (self.bubble.hasClass("right")) {
			self.bubble.removeClass("right");
		}
		if (clickTop > (self.calendar.height() / 2)) {
			self.bubble.addClass("over");
			self.bubble.css({ top: event.pageY - 240 });
		}
		else {
			self.bubble.addClass("under");
			self.bubble.css({ top: event.pageY + 20});
		}
		if (clickLeft > (self.calendar.width() / 2)) {
			self.bubble.addClass("right");
			self.bubble.css({left: event.pageX - 310});
		}
		else {
			self.bubble.addClass("left");
			self.bubble.css({ left: event.pageX - 50});
		}
		if (!self.bubble.isOpen) {
			self.bubble.show();
		}
		event.preventDefault();
		return null;
	}
	this.closeBubble = function (event) {
		//console.log("closeBubble()");
		self.bubble.hide();
		self.eventTitle.text("");
		self.eventDate.text("");
		self.eventInfo.text("");
		//$(this.eventLink.attr("href").text("nisse"));
	}
	$(".closeMe").click(this.closeBubble);
	this.items.each(function (i) {
		$(this).click($(this), self.onEventSelected);
	});
}
var goToLink = function () {
	window.location = $("a.eventLink", this).attr("href");
}
function random_color(format) {
	var rint = Math.round(0xffffff * Math.random());
	switch (format) {
		case 'hex':
			return ('#0' + rint.toString(16)).replace(/^#0([0-9a-f]{6})$/i, '#$1');
			break;
		case 'rgb':
			return 'rgb(' + (rint >> 16) + ',' + (rint >> 8 & 255) + ',' + (rint & 255) + ')';
			break;
		default:
			return rint;
			break;
	}
}
function fadeOutItem(id) {
	if (jQuery.support.opacity) {
		$(id).delay(3000);
		$(id).animate({ opacity: 0 }, 1000, function () {
			$(this).hide();
			$(this).css({ opacity: 1 });
		});
	}
	else {
		$(id).delay(3000);
		$(id).slideUp(400);
	}
}
var HoverInfo = function (items, infoSource, isTitleAttribute) {
	var self = this;
	var popMarkup = '<div class="hoverInfo"><div class="contentWrapper"><div class="content"><p></p></div><div class="bottom"></div></div></div>';
	this.items = $(items);
	this.hoverTimer = 0;
	if (typeof isTitleAttribute === "undefined") {
		this.isTitleAttribute = false;
	}
	else {
		this.isTitleAttribute = isTitleAttribute;
	}
	this.infoSource = infoSource;
	this.startHoverTimer = function () {
		self.stopHoverTimer();
		self.hoverTimer = setInterval(function () {
			//self.nextItem();
			//console.log("out (timed)");
			self.stopHoverTimer();
			self.popMarkup.hide();
			self.popMarkup.isOpen = false;
		}, 100);
	};
	this.stopHoverTimer = function () {
		clearInterval(self.hoverTimer);
	};
	$("body").append(popMarkup);
	this.popMarkup = $(".hoverInfo");
	this.popInner = $(".hoverInfo .content p");
	this.popMarkup.isOpen = false;
	this.onMouseOver = function (event) {
		//console.log("over");
		self.stopHoverTimer();
		var popupText = "";
		if (self.isTitleAttribute) {
			popupText = $(this).attr(self.infoSource);
		}
		else {
			popupText = $(self.infoSource, this).text();
		}
		if (popupText !== "" && popupText !== "undefined") {
			self.popInner.text(popupText);
		}
		if (!self.popMarkup.isOpen && popupText !== "") {
			var $wrapper = $(".contentWrapper", self.popMarkup);
			$wrapper.css({ opacity: 0, top: 20 });
			self.popMarkup.show();
			$wrapper.stop().animate({ opacity: 1, top: 0 }, 200, "easeOutSine");
			//event.preventDefault();
			self.popMarkup.isOpen = true;
		}
		else if (self.popMarkup.isOpen && popupText == "") {
			self.popMarkup.hide();
			self.popMarkup.isOpen = false;
		}
	};
	this.onMouseOut = function (event) {
		//self.popMarkup.hide();
		//console.log("out");
		self.startHoverTimer();
		//event.preventDefault();
	};
	this.onMouseMove = function (event) {
		self.stopHoverTimer();
		self.popMarkup.css({ top: event.pageY - (self.popMarkup.outerHeight() + 20), left: event.pageX - 15 });
		event.preventDefault();
	};
	//this.items.mouseover(this.onMouseOver);
	this.items.mouseout(this.onMouseOut);
	this.items.mouseenter(this.onMouseOver);
	//this.items.mouseleave(this.onMouseOut);
	this.items.mousemove(this.onMouseMove);
}
var TopStoryManager = function (storyItems, btnItems, linkElement) {
	var self = this;
	this.btnItems = $(btnItems);
	this.btnItems.each(function (i) {
		$(this).click(i, function (e) {
			self.setSelected(e.data);
		});
	});
	this.storyItems = $(storyItems);
	this.storyItems.each(function (i) {
		if (!$(this).hasClass("selected")) {
			$(this).hide();
		}
		var link = $($(self.btnItems.get(i)).find(linkElement)).attr("href");
		$($(this).find("a")).attr("href", link);
	});
	this.selectedItem = $(storyItems + ".selected");
	this.selectedBtn = $(btnItems + ".selected");
	this.setSelected(0);
};
TopStoryManager.prototype.setSelected = function (nr) {
	//console.log("setSelected(" + nr + ")");
	if (typeof this.selectedBtn != "undefined") {
		this.selectedBtn.removeClass("selected");
	}
	if (typeof this.selectedItem != "undefined") {
		this.selectedItem.removeClass("selected");
		this.selectedItem.hide();
	}
	this.selectedBtn = $(this.btnItems.get(nr));
	this.selectedBtn.addClass("selected");
	this.selectedItem = $(this.storyItems.get(nr));
	this.selectedItem.addClass("selected");
	this.selectedItem.show();
};
var ItemsOnPress = function (items, onPressClass) {
	this.items = $(items);
	this.items.each(function (i) {
		this.addPress = function (e) {
			//console.log("onPress");
			$(this).addClass(e.data);
		};
		this.killPress = function (e) {
			//console.log("e.data : " + e.data);
			if($(this).hasClass(onPressClass))
			{
				$(this).removeClass(e.data);
			}
		};
		$(this).mousedown(onPressClass, this.addPress);
		$(this).mouseup(onPressClass, this.killPress);
		$(this).mouseleave(onPressClass, this.killPress);
	});
}
var AddLinkToItems = function (itemsToLink) {
	this.itemsToLink = $(itemsToLink);
	this.itemsToLink.each(function (i) {
		$(this).click($("a", this).attr("href"), function (e) {
			//console.log("e.data : " + e.data);
			window.location = e.data;
		});
	});
}
/* Campaign-Hover */
var DarkHover = function (containerItems, triggerItem) {
	var self = this;
	this.containerItems = $(containerItems);
	this.triggerItems = $(triggerItem);
	//console.log(this.triggerItems);
	//console.log($(this.triggerItems.get(0)).css("z-index"));
	this.containerItems.each(function (index) {
		$(this).append('<div class="campaignHover"></div>');
		$(".campaignHover", this).css({ width: $(this).outerWidth(), height: $(this).outerHeight(), zIndex: 10, opacity: 0 });
	});
	this.rollOver = function (event) {
		//console.log("over");
		var $hover = $(".campaignHover", self.containerItems.get(this.index));
		$hover.show();
		$hover.stop().animate({ opacity: .5 }, 400, "easeOutQuart");
		event.preventDefault();
	};
	this.rollOut = function (event) {
		//console.log("out");
		$(".campaignHover", self.containerItems.get(this.index)).stop().animate({ opacity: 0 }, 800, "easeOutQuart", function () { $(this).hide() });
		event.preventDefault();
	};
	this.triggerItems.each(function (index) {
		this.index = index;
		//$(this).parent(".readmore").css("z-index", 11);
		var $readMore = $(this).find(".readmore");
		$readMore.css("z-index", 11);
		$(this).css({cursor: "pointer"});
		$(this).mouseover(self.rollOver);
		$(this).mouseleave(self.rollOut);
		$(this).click(function () {
			document.location.href = $readMore.children("a").attr("href");
		});
	});
};
/* Horisontal ItemScroller */
var ItemScrollerHorisontal = function (itemContainer, nextBtn, prevBtn) {
	var self = this;
	this.currentItem = 0;
	this.itemContainer = $(itemContainer);
	this.maskWidth = this.itemContainer.parent().width();
	this.prevBtn = $(prevBtn);
	this.nextBtn = $(nextBtn);
	this.items = this.itemContainer.children("li");
	// +++ Revamped paste test +++
	this.totalItems = this.items.length;
	this.itemTotalWidth = $(this.items.get(0)).outerWidth(true);
	$(this.items.get(this.items.length - 1)).css({ marginRight: 0 });
	this.itemContainer.css({ width: ((this.totalItems * this.itemTotalWidth) - $(this.items.get(0)).css("margin-right").replace("px", "")) });
	this.prevBtn.addClass("disabled");
	if (this.itemContainer.width() <= self.maskWidth) {
		this.nextBtn.addClass("disabled");
	}
	this.doScroll = function (leftPos) {
		var scroll = false;
		if ((self.itemContainer.width() + this.itemTotalWidth - leftPos) > self.maskWidth) {
			scroll = true;
		}
		//console.log("(self.itemContainer.width() + this.itemTotalWidth - leftPos) : " + (self.itemContainer.width() + this.itemTotalWidth - leftPos));
		//console.log("container W: " + self.itemContainer.width() + " mask W: " + self.maskWidth + " leftPos: " + leftPos + " scroll: " + scroll);
		return scroll;
	};
	this.stepNext = function (event) {
		if (self.doScroll($(self.items[self.currentItem + 1]).position().left)) {
			self.currentItem++;
			/*
			console.log("totalItems: " + self.totalItems);
			console.log("currentItem: " + self.currentItem);
			*/
			//if (self.currentItem >= self.totalItems-2) {
			if (self.currentItem >= self.totalItems - 1) {
				console.log("endItem?");
				self.nextBtn.addClass("disabled");
			}
			else {
				if (self.nextBtn.hasClass("disabled"))
					self.nextBtn.removeClass("disabled");
				if (self.currentItem != 0)
					self.prevBtn.removeClass("disabled");
			};
			var current = $(self.items[self.currentItem]);
			//console.log("current.position().left : " + current.position().left);
			if (!self.doScroll($(self.items[self.currentItem + 1]).position().left)) {
				self.nextBtn.addClass("disabled");
			}
			self.itemContainer.stop().animate({ left: "-" + current.position().left }, 300, "easeOutQuart");
		}
		else {
			self.nextBtn.addClass("disabled");
			//self.itemContainer.stop().animate({ left: "-" + (self.itemContainer.width() - self.maskWidth -10) }, 300, "easeOutQuart");
		}
		//console.log("currentItem: " + self.currentItem + " -- totalItems: " + self.totalItems);
		event.preventDefault();
	}
	this.stepPrev = function (event) {
		prev = $(self.items[self.currentItem]);
		self.currentItem--;
		if (self.currentItem <= 0) {
			self.currentItem = 0;
			self.prevBtn.addClass("disabled");
		}
		else {
			if (self.prevBtn.hasClass("disabled")) {
				self.prevBtn.removeClass("disabled");
			}
		}
		if (self.currentItem != self.totalItems - 1) {
			self.nextBtn.removeClass("disabled");
		}
		var current = $(self.items[self.currentItem]);
		//console.log("current.position().left : " + current.position().left);
		self.itemContainer.stop().animate({ left: "-" + current.position().left }, 300, "easeOutQuart");
		event.preventDefault();
	}
	this.prevBtn.click(this.stepPrev);
	this.nextBtn.click(this.stepNext);
	// --- Revamped paste test ---
	/*
	this.totalItems = this.items.length - 1;
	this.itemContainer.css({ width: ((this.totalItems + 1) * ($(this.items.get(0)).width() + 10)) });
	this.prevBtn.addClass("disabled");
	if (this.items.length == 1)
	this.nextBtn.addClass("disabled");
	this.doScroll = function (leftPos) {
	var scroll = false;
	if ((self.itemContainer.width() - leftPos) > self.maskWidth) {
	scroll = true;
	}
	return scroll;
	};
	this.stepNext = function (event) {
	if (self.doScroll($(self.items[self.currentItem + 1]).position().left)) {
	prev = $(self.items[self.currentItem]);
	self.currentItem++;
	if (self.currentItem >= self.totalItems-2) {
	//self.currentItem = self.totalItems;
	self.nextBtn.addClass("disabled");
	}
	else {
	if (self.nextBtn.hasClass("disabled"))
	self.nextBtn.removeClass("disabled");
	if (self.currentItem != 0)
	self.prevBtn.removeClass("disabled");
	};
	var current = $(self.items[self.currentItem]);
	//console.log("current.position().left : " + current.position().left);
	self.itemContainer.stop().animate({ left: "-" + current.position().left }, 300, "easeOutQuart");
	}
	else {
	self.nextBtn.addClass("disabled");
	//self.itemContainer.stop().animate({ left: "-" + (self.itemContainer.width() - self.maskWidth -10) }, 300, "easeOutQuart");
	}
	//console.log("currentItem: " + self.currentItem + " -- totalItems: " + self.totalItems);
	event.preventDefault();
	}
	this.stepPrev = function (event) {
	prev = $(self.items[self.currentItem]);
	self.currentItem--;
	if (self.currentItem <= 0) {
	self.currentItem = 0;
	self.prevBtn.addClass("disabled");
	}
	else {
	if (self.currentItem != self.totalItems-2)
	self.nextBtn.removeClass("disabled");
	if (self.prevBtn.hasClass("disabled"))
	self.prevBtn.removeClass("disabled");
	}
	var current = $(self.items[self.currentItem]);
	//console.log("current.position().left : " + current.position().left);
	self.itemContainer.stop().animate({ left: "-" + current.position().left }, 300, "easeOutQuart");
	event.preventDefault();
	}
	this.prevBtn.click(this.stepPrev);
	this.nextBtn.click(this.stepNext);
	*/
};
/* END Horisontal ItemScroller */
/* RotatingGallery */
var RotatingGallery = function (galleryContainer, indicatorItems, startItem) {
	var self = this;
	this.galleryContainer = $(galleryContainer);
	this.indicatorList = $("li", indicatorItems);
	this.items = this.galleryContainer.children("li.campaignItem");
	if (this.items.length<2) return;
	this.items.each(function (i) {
		$("img", this).addClass("handIcon");
		$(this).click($("a", this).attr("href"), function (e) {
			//console.log("e.data : " + e.data);
			window.location = e.data;
		});
	});
	/*
	this.items.each(function () {
	$(this).css({ backgroundColor: random_color('hex') });
	});
	*/
	this.galleryContainer.width((this.items.length + 1) * $(this.items.get(0)).width());
	this.totalItems = this.items.length;
	this.wrapAround = self.galleryContainer.append("<li class='campaignItem wrapAround'>" + $(self.items[0]).html() + "</li>");
	this.wrapAround = $(".wrapAround");
	if (typeof startItem == "undefined") {
		this.currentItem = 0;
	}
	else {
		this.currentItem = startItem;
		this.galleryContainer.css({ left: (-$(this.items[this.currentItem]).position().left) });
	}
	$indicator = $(this.indicatorList[self.currentItem]);
	$indicator.addClass("activeIndicator");
	this.startAnimTimer = function () {
		self.animTimer = setInterval(function () {
			self.nextItem();
		}, 6000);
	};
	this.stopAnimTimer = function () {
		clearInterval(self.animTimer);
	};
	this.nextItem = function () {
		var $indicator = $(self.indicatorList[self.currentItem]);
		$indicator.removeClass("activeIndicator");
		self.currentItem++;
		var current = $(self.items[self.currentItem]);
		if (self.currentItem >= self.totalItems) {
			self.currentItem = 0;
			self.galleryContainer.stop().animate({ left: "-" + self.wrapAround.position().left }, 900, "easeInOutQuart", function () { self.galleryContainer.css({ left: 0 }); });
		}
		else {
			if (self.currentItem == 1) {
				self.galleryContainer.css({ left: 0 });
			}
			self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 900, "easeInOutQuart");
		};
		$indicator = $(self.indicatorList[self.currentItem]);
		$indicator.addClass("activeIndicator");
		//console.log("current : " + self.currentItem);
	}
	this.gotoItem = function (event) {
		//console.log("indicator HIT: " + event.data.index);
		var $indicator = $(self.indicatorList[self.currentItem]);
		$indicator.removeClass("activeIndicator");
		self.currentItem = event.data.index;
		$indicator = $(self.indicatorList[event.data.index]);
		$indicator.addClass("activeIndicator");
		self.stopAnimTimer();
		var current = $(self.items[event.data.index]);
		self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 900, "easeInOutQuart", self.startAnimTimer);
	}
	this.indicatorList.each(function (index) {
		$(this).bind("click", { index: index }, self.gotoItem);
	});
	this.startAnimTimer();
};
/* END RotatingGallery */
/* Vertical ItemScroller */
var ItemScroller = function (itemContainer, upBtn, downBtn) {
	var self = this;
	this.mouseDown = false;
	this.currentItem = 0;
	this.itemContainer = $(itemContainer);
	this.maskHeight = this.itemContainer.parent().height();
	this.upBtn = $(upBtn);
	this.downBtn = $(downBtn);
	this.items = this.itemContainer.children("li");
	this.items.each(function (index) {
		var $item = $(this);
	});
	this.totalItems = this.items.length - 1;
	this.upBtn.addClass("disabled");
	if (this.items.length == 1)
		this.downBtn.addClass("disabled");
	this.doScroll = function (topPos) {
		var scroll = false;
		//console.log("container height: " + self.itemContainer.height() + " - topPos: " + topPos + " - Total: " + (self.itemContainer.height() - topPos));
		if ((self.itemContainer.height() - topPos) > self.maskHeight) {
			scroll = true;
		}
		return scroll;
	};
	this.stepDown = function (event) {
		self.dirUp = false;
		if (self.doScroll($(self.items[self.currentItem + 1]).position().top)) {
			prev = $(self.items[self.currentItem]);
			self.currentItem++;
			if (self.currentItem >= self.totalItems) {
				self.currentItem = self.totalItems;
				self.downBtn.addClass("disabled");
			}
			else {
				if (self.downBtn.hasClass("disabled"))
					self.downBtn.removeClass("disabled");
				if (self.currentItem != 0)
					self.upBtn.removeClass("disabled");
			};
			var current = $(self.items[self.currentItem]);
			self.itemContainer.stop().animate({ top: "-" + current.position().top }, 300, "easeOutQuart");
		}
		else {
			self.itemContainer.stop().animate({ top: "-" + (self.itemContainer.height() - self.maskHeight + 1) }, 300, "easeOutQuart");
		}
		event.preventDefault();
	}
	this.stepUp = function (event) {
		self.dirUp = true;
		prev = $(self.items[self.currentItem]);
		self.currentItem--;
		if (self.currentItem <= 0) {
			self.currentItem = 0;
			self.upBtn.addClass("disabled");
		}
		else {
			if (self.currentItem != self.totalItems)
				self.downBtn.removeClass("disabled");
			if (self.upBtn.hasClass("disabled"))
				self.upBtn.removeClass("disabled");
		}
		var current = $(self.items[self.currentItem]);
		self.itemContainer.stop().animate({ top: "-" + current.position().top }, 300, "easeOutQuart");
		event.preventDefault();
	}
	this.mdTimer = 0;
	this.dirUp = false;
	this.mdLoop = function () {
		if (self.mouseDown) {
			if (self.dirUp && self.itemContainer.position().top < 0) {
				if ((self.itemContainer.position().top + 20) < 0) {
					self.itemContainer.css({ top: self.itemContainer.position().top + 20 });
				}
				else {
					self.itemContainer.css({ top: 0 });
					clearInterval(self.mdTimer);
				}
			}
			else if (self.dirUp && self.itemContainer.position().top > 0) {
				self.itemContainer.css({ top: 0 });
			}
			else if (self.doScroll(Math.abs(self.itemContainer.position().top))) {
				self.itemContainer.css({ top: self.itemContainer.position().top - 20 });
			}
			else {
				clearInterval(self.mdTimer);
			}
			if (!self.doScroll(Math.abs(self.itemContainer.position().top))) {
				clearInterval(self.mdTimer);
				self.itemContainer.css({ top: self.itemContainer.position().top + 9 });
			}
		}
		else {
			clearInterval(self.mdTimer);
		}
	};
	this.startMdTimer = function () {
		clearInterval(self.mdTimer);
		self.mdTimer = setInterval(function () {
			self.mdLoop();
		}, 50);
	};
	this.mUp = function () {
		clearInterval(self.mdTimer);
		self.mouseDown = false;
	};
	this.mDown = function () {
		self.mouseDown = true;
		self.startMdTimer();
	};
	this.upBtn.mousedown(this.mDown);
	this.upBtn.mousedown(function () { self.dirUp = true; });
	this.upBtn.mouseup(this.mUp);
	this.upBtn.mouseleave(this.mUp);
	this.downBtn.mousedown(this.mDown);
	this.downBtn.mousedown(function () { self.dirUp = false; });
	this.downBtn.mouseup(this.mUp);
	this.downBtn.mouseleave(this.mUp);
	//this.upBtn.mousedown(this.stepUp);
	//this.downBtn.mousedown(this.stepDown);
};
/* END Vertical ItemScroller */
/* InspirationGallery */
var InspirationGallery = function (galleryContainer, prevBtn, nextBtn, shadows) {
	var self = this;
	this.currentItem = 0;
	this.galleryContainer = $(galleryContainer);
	this.shadows = $(shadows);
	this.prevBtn = $(prevBtn);
	this.nextBtn = $(nextBtn);
	this.items = this.galleryContainer.children("li");
	this.galleryContainer.width(this.items.length * $(this.items.get(0)).width());
	/*
	if (jQuery.support.opacity) {
	$(".navBtn", this.prevBtn).css({ opacity: .3 });
	$(".navBtn", this.nextBtn).css({ opacity: .3 });
	}
	*/
	this.shadows.each(function (index) {
		this.shadow = $(".shadow", this);
		this.btn = $(".navBtn", this);
		if (jQuery.support.opacity) {
			this.shadow.css({ opacity: 0 });
			this.shadow.show();
			this.btn.stop().fadeTo(300, .2);
			$(this).css({ background: "transparent"});
		}
		else {
			this.shadow.hide();
			//$(this).css({ opacity: 0 });
		}
	});
	this.totalItems = this.items.length - 1;
	this.prevBtn.addClass("disabled");
	if (this.items.length == 1)
		this.nextBtn.addClass("disabled");
	// Mouse over/out functions
	this.shadowOver = function () {
		if (!$("a", this).hasClass("disabled")) {
			if (jQuery.support.opacity) {
				this.shadow.stop().fadeTo(300, 1);
				if ($(".navBtn:animated", this).length < 1) {
					this.btn.stop().fadeTo(300, .6);
				}
			}
			else {
				this.shadow.show();
			}
		}
	};
	this.shadowOut = function () {
		if (jQuery.support.opacity) {
			this.shadow.stop().fadeTo(500, 0);
			this.btn.stop().fadeTo(300, .2);
		}
		else {
			this.shadow.hide();
		}
	};
	this.navOver = function () {
		if (jQuery.support.opacity) {
			$(".navBtn", this).stop().fadeTo(300, 1);
		}
		else {
			//this.show();
		}
	};
	this.navOut = function () {
		if (jQuery.support.opacity) {
			$(".navBtn", this).stop().fadeTo(300, .5);
		}
		else {
			//this.hide();
		}
	};
	// navigation
	this.nextItem = function (event) {
		prev = $(self.items[self.currentItem]);
		self.currentItem++;
		if (self.currentItem == self.totalItems) {
			//self.currentItem = self.totalItems;
			self.nextBtn.addClass("disabled");
			if (self.currentItem == 1) {
				self.prevBtn.removeClass("disabled");
			}
		}
		else {
			if (self.nextBtn.hasClass("disabled")) {
				self.nextBtn.removeClass("disabled");
			}
			if (self.currentItem != 0) {
				self.prevBtn.removeClass("disabled");
			}
		};
		var current = $(self.items[self.currentItem]);
		self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 800, "easeOutQuart");
		event.preventDefault();
	}
	this.prevItem = function (event) {
		prev = $(self.items[self.currentItem]);
		self.currentItem--;
		if (self.currentItem <= 0) {
			self.currentItem = 0;
			self.prevBtn.addClass("disabled");
			if (self.nextBtn.hasClass("disabled") && self.items.length > 1) {
				self.nextBtn.removeClass("disabled");
			}
		}
		else {
			if (self.currentItem != self.totalItems) {
				self.nextBtn.removeClass("disabled");
			}
			if (self.prevBtn.hasClass("disabled")) {
				self.prevBtn.removeClass("disabled");
			}
		}
		var current = $(self.items[self.currentItem]);
		self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 800, "easeOutQuart");
		event.preventDefault();
	}
	// Bind mouse-events to elements
	this.prevBtn.click(this.prevItem);
	this.prevBtn.mouseover(this.navOver);
	this.prevBtn.mouseleave(this.navOut);
	this.nextBtn.click(this.nextItem);
	this.nextBtn.mouseover(this.navOver);
	this.nextBtn.mouseleave(this.navOut);
	this.shadows.mouseover(self.shadowOver);
	this.shadows.mouseleave(self.shadowOut);
};
// END InspirationGallery
/* GallerySlider */
var GallerySlider = function (galleryContainer, prevBtn, nextBtn) {
	var self = this;
	this.currentItem = 0;
	this.galleryContainer = $(galleryContainer);
	this.prevBtn = $(prevBtn);
	this.nextBtn = $(nextBtn);
	this.items = this.galleryContainer.children("li");
	this.galleryContainer.width(this.items.length * $(this.items.get(0)).width());
	this.items.each(function (index) {
		var $item = $(this);
	});
	this.totalItems = this.items.length - 1;
	this.prevBtn.addClass("disabled");
	if (this.items.length == 1)
		this.nextBtn.addClass("disabled");
	// Mouse over/out functions
	this.nextItem = function (event) {
		prev = $(self.items[self.currentItem]);
		self.currentItem++;
		if (self.currentItem == self.totalItems) {
			//self.currentItem = self.totalItems;
			self.nextBtn.addClass("disabled");
			if (self.currentItem == 1) {
				self.prevBtn.removeClass("disabled");
			}
		}
		else {
			if (self.nextBtn.hasClass("disabled")) {
				self.nextBtn.removeClass("disabled");
			}
			if (self.currentItem != 0) {
				self.prevBtn.removeClass("disabled");
			}
		};
		var current = $(self.items[self.currentItem]);
		self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 800, "easeOutQuart");
		event.preventDefault();
	}
	this.prevItem = function (event) {
		prev = $(self.items[self.currentItem]);
		self.currentItem--;
		if (self.currentItem <= 0) {
			self.currentItem = 0;
			self.prevBtn.addClass("disabled");
			if (self.nextBtn.hasClass("disabled") && self.items.length>1) {
				self.nextBtn.removeClass("disabled");
			}
		}
		else {
			if (self.currentItem != self.totalItems) {
				self.nextBtn.removeClass("disabled");
			}
			if (self.prevBtn.hasClass("disabled")) {
				self.prevBtn.removeClass("disabled");
			}
		}
		var current = $(self.items[self.currentItem]);
		self.galleryContainer.stop().animate({ left: "-" + current.position().left }, 800, "easeOutQuart");
		event.preventDefault();
	}
	// Bind mouse-events to elements
	this.prevBtn.click(this.prevItem);
	this.nextBtn.click(this.nextItem);
};
// END GallerySlider
