Estate.Destil = {}






Estate.Destil.Acties = (function() {
	var config = {
		interval: 5000,
		speed: 250
	}
	var acties = new Array();
	var actieLoop;

	function setHeight(ul) {
		var height = 0
		jQuery(ul).find("li").each(function() {
			jQuery(this).show();
			if (jQuery(this).height() > height) {
				height = jQuery(this).height();
			}
			jQuery(this).hide();
		})
		jQuery(ul).css("height", height + "px")
	}

	function setWideStyle(el) {
		jQuery(el).find("li").each( function() {
		jQuery(this).find("p").remove().appendTo(jQuery(this).find("div.localColumn2"))
		})
	}
	
	function stopInterval(actiesBoxIndex) {
		clearInterval(acties[actiesBoxIndex])
	}

	function startInterval(actiesBoxIndex) {
		clearInterval(acties[actiesBoxIndex])
		acties[actiesBoxIndex] = setInterval("Estate.Destil.Acties.NextSlide(" + actiesBoxIndex + ")", config.interval)
	}



	/* START PUBLIC */
	return {
		Run: function() {
			jQuery("div.acties.tag_acties").each(function(index) {
				if (jQuery(this).find("ul li").length > 0) {
					jQuery(this).data('index', index)
					jQuery(this).prepend("<ol class='pager'></ol>");
					var ol = jQuery(this).find("ol");
					for (var i = 1; i <= jQuery(this).find("ul li").length; i++) {
						jQuery(ol).append("<li>" + i + "</li>")
					}
					jQuery(this).find("ul li").hide()
					jQuery(this).find("ul li:first").show()
					if (jQuery(this).hasClass("tag_actiesWide")) {
						setWideStyle(this);
					}

					jQuery(this).find("ol.pager li").each(function(pagerIndex) {
						jQuery(this).click(function() {
							Estate.Destil.Acties.NextSlide(index, pagerIndex)
						})
					})
					setHeight(jQuery(this).find("ul"))
					acties[index] = setInterval("Estate.Destil.Acties.NextSlide(" + index + ")", config.interval)

					jQuery(this).find("ul li:first").show().addClass("active")
					jQuery(this).find("ol li:first").addClass("active")
					startInterval(index)
					
					jQuery(this).mouseenter( function() {
						stopInterval(jQuery(this).data('index'))
					})

					jQuery(this).mouseleave( function() {
						startInterval(jQuery(this).data('index'))
					})
				}
			})
		},

		NextSlide: function(actiesBoxIndex, pagerIndex) {
			var actiesBox = jQuery("div.acties.tag_acties:eq(" + actiesBoxIndex + ")");
			
			if (typeof(pagerIndex) == "number") {
				jQuery(actiesBox).find("ul li:visible").fadeOut(config.speed, function() {
					jQuery(actiesBox).find("ul li:eq(" + pagerIndex + ")").fadeIn(config.speed, function() { jQuery(this).css("filter", "none") });
				});

				jQuery(actiesBox).find("ol li.active").removeClass("active");
				jQuery(actiesBox).find("ol li:eq(" + pagerIndex + ")").addClass("active");
			} else {
				var ulItemActive = jQuery(actiesBox).find("ul li:visible");
				var ulItemActiveIndex = jQuery(actiesBox).find("ul li").index(jQuery(ulItemActive)) + 1;
				if (ulItemActiveIndex > (jQuery(actiesBox).find("ul li").length - 1)) {
					ulItemActiveIndex = 0;
				}
				jQuery(actiesBox).find("ul li:visible").fadeOut(config.speed, function() {
					jQuery(actiesBox).find("ul li:eq(" + ulItemActiveIndex + ")").fadeIn(config.speed, function() { jQuery(this).css("filter", "none") });
				});

				var olItemActive = jQuery(actiesBox).find("ol li.active");
				var olItemActiveIndex = jQuery(actiesBox).find("ol li").index(jQuery(olItemActive)) + 1;
				if (olItemActiveIndex > (jQuery(actiesBox).find("ol li").length - 1)) {
					olItemActiveIndex = 0;
				}
				jQuery(olItemActive).removeClass("active");
				jQuery(actiesBox).find("ol li:eq(" + olItemActiveIndex + ")").addClass("active");
			}
		}
	}
	/* END PUBLIC */
})();













Estate.Destil.FAQ = (function() {
	/* START PUBLIC */
	return {
		Run: function() {
			jQuery("body").addClass("JsEnabled");
			jQuery("dl.list dd").hide();
			jQuery("dl.list dd:first").slideDown("slow")

			jQuery("dl.list dt").click(function() {
				if (jQuery(this).next("dd").is(":hidden")) {
					jQuery("dl.list dd").slideUp("slow")
					jQuery(this).next("dd").slideDown("slow");
				}
			})
		}
	}
	/* END PUBLIC */
})();







Estate.Destil.Popup = (function() {
	var config = {
		popupDeactivated: false
	}

	function setConfig() {
		checkDeactivation();
	}

	function checkDeactivation() {
		if (Estate.Cookies.Get("deactivateLoterij") == null) {
			config.popupDeactivated = false;
		} else {
			config.popupDeactivated = true;
		}
	}

	function scrollToPopupWindow() {
		//jQuery('html, body').animate({ scrollTop: jQuery("#DivPopupWindow").offset().top }, 500)
	}

	function handleCookie(element) {
		if (jQuery(element).is(':checked')) {
			Estate.Cookies.Set("deactivateLoterij", "true", new Date(2015, 12, 31, 23, 59, 59, 0), "/", "", false);
		} else {
			Estate.Cookies.Delete("deactivateLoterij");
		}
	}

	/* START PUBLIC */
	return {
		Open: function(ignoreCookie) {
			setConfig()

			if (config.popupDeactivated == false || ignoreCookie == true || jQuery("#DivPopupWindow span.tag_melding").text() != "") {
				jQuery("#DivPopupWindow").slideDown(250, scrollToPopupWindow);
				jQuery("#DivPopupBackground").css("opacity", 0)
				jQuery("#DivPopupBackground").animate({ opacity: 0.5 }, 250);
				jQuery("#DivPopupBackground").show()
				jQuery("#DivPopupBackground, #DivPopupWindow span.closeLoterij").click(function() {
					Estate.Destil.Popup.Close()
				})

				if (ignoreCookie == true || jQuery("#DivPopupWindow span.tag_melding").text() != "") {
					jQuery("#DivPopupWindow div.loterijfooter input, #DivPopupWindow div.loterijfooter label").hide()
				} else {
					jQuery("#DivPopupWindow input.tag_dontBugMe").change(function() {
						handleCookie(this)
					})
				}
			}
		},

		SetBackgroundIE6: function() {
			jQuery("#DivPopupBackground").css("height", jQuery("body").height() + "px")
		},

		Close: function() {
			handleCookie(jQuery("#DivPopupWindow input.tag_dontBugMe"))
			jQuery("#DivPopupWindow").slideUp(250);
			jQuery("#DivPopupBackground").animate({ opacity: 0 }, 250, function() { jQuery("#DivPopupBackground").hide() });
		}
	}
	/* END PUBLIC */
})();












