Estate.Plastica = (function() {
	/* START PUBLIC */
	return {
		ToggleProductsOnHome: function() {
			jQuery("#MeerPlasticaSites span.mpsHeading2, #ShowProducts span.close").click(function() {
				if (jQuery("#ShowProducts:visible").size() == 0) {
					jQuery("#ShowProducts").slideDown()
				} else {
					jQuery("#ShowProducts").slideUp()
				}
			})
		}
	}
	/* END PUBLIC */
})();


Estate.Plastica.Popup = (function() {
	function placePopupCode(html, argPopupId) {
		var popupId	 = ""
		if (typeof(argPopupId) != "undefined") {
			popupId = argPopupId
		}
		if (document.getElementById('DivPopupWindow' + popupId) == null) {
			var popupHTML = '';
			popupHTML += '<div id="DivPopupWindow' + popupId + '" class="divPopupWindow divPopupWindow' + popupId + '"><div class="innerDivPopupWindow">';
			popupHTML += '    <div class="close"></div>';
			popupHTML += '    <div class="popupContent"></div>';
			popupHTML += '</div></div>';
			popupHTML += '<div id="DivPopupBackground' + popupId + '" class="divPopupBackground divPopupBackground' + popupId + '"></div>';
			jQuery('body').append(popupHTML);
		} else {
			jQuery('#DivPopupWindow' + popupId + ' div.popupContent').html('');
		}

		if (typeof (html) == 'string') {
			jQuery('#DivPopupWindow' + popupId + ' div.popupContent').html(html);
		}
	}

	/* START PUBLIC */
	return {
		Open: function(html, argPopupId) {
			var popupId = ""
			if (typeof (argPopupId) != "undefined") {
				popupId = argPopupId
			}
			placePopupCode(html, popupId)
			var popupConfig = {
				animationSpeed: 250,
				closeText: "",
				scrollToWindow: true,
				windowSelector: "#DivPopupWindow" + popupId,
				backgroundSelector: "#DivPopupBackground" + popupId
			}
			var popup = new Estate.Popup(popupConfig);
			popup.Open();
		},

		SetProductMontagePopup: function() {
			jQuery('#ProductMontage > ul > li.lightbox > img, #ProductMontage > ul > li.lightbox > div.imageOverlay').click(function() {
				Estate.Plastica.Popup.Open(jQuery(this).parent().find("div.montageLightbox").html());
			})
		},

		SetProductKwaliteitenPopup: function() {
			jQuery('#ProductKwaliteiten > ul > li.lightbox > img, #ProductKwaliteiten > ul > li.lightbox > div.imageOverlay').click(function() {
				Estate.Plastica.Popup.Open(jQuery(this).parent().find("div.montageLightbox").html());
			})
		}
	}
	/* END PUBLIC */
})();




Estate.Plastica.Monsteraanvraag = (function() {
	var config = {
		show: 'Laten zien',
		hide: 'Verbergen'
	}
	
	function openCloseToggle(element) {
		var container = jQuery("#FoundColors")
		if (jQuery("#FoundColors:visible").size() > 0) {
			jQuery(container).fadeOut(250, function() { jQuery(this).attr('filter', '') });
			jQuery(element).text(config.show);
		} else {
			jQuery(container).fadeIn(250, function() { jQuery(this).attr('filter', '') });
			jQuery(element).text(config.hide);
		}
	}
	
	function setPostAddressEvents() {
		if (jQuery("#PostAddressToggle input:checked").size() > 0) {
			jQuery("#PostAddress").fadeOut()
		} else {
			jQuery("#PostAddress").fadeIn()
		}
	}

	function setPostAddressMarketeersEvents(checkBoxContainer, altAddressContainer) {
		if (jQuery(checkBoxContainer).find("input:checked").size() > 0) {
			jQuery(altAddressContainer).fadeOut()
		} else {
			jQuery(altAddressContainer).fadeIn()
		}
	}

	/* START PUBLIC */
	return {
		InitCloseButton: function(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);

			Estate.Check.UpdateLiteral(config, newConfig)
			
			jQuery("#KleurProductClose").css("cursor", "pointer");
			jQuery("#KleurProductClose").click(function() {
				openCloseToggle(this)
			})
		},
		
		SetPostAddressEvents: function() {
			if (jQuery("#PostAddressToggle input:checked").size() > 0) {
				jQuery("#PostAddress").hide()
			}
			jQuery("#PostAddressToggle input, #PostAddressToggle label").click(setPostAddressEvents)
			jQuery("#PostAddressToggle input").change(setPostAddressEvents)
			jQuery("#PostAddressToggle input").keyup(setPostAddressEvents)
		},
		
		SetPostAddressEventsMarketeers: function() {
			var checkBoxContainer = jQuery("div.scfForm div.company span.scfCheckbox")
			var altAddressContainer = jQuery("div.scfForm div.company + div")
			
			jQuery(checkBoxContainer).find("input").attr("checked", "checked")
			jQuery(altAddressContainer).hide()

			jQuery(checkBoxContainer).find("input, label").click(function() { setPostAddressMarketeersEvents(checkBoxContainer, altAddressContainer) })
			jQuery(checkBoxContainer).find("input").change(function() { setPostAddressMarketeersEvents(checkBoxContainer, altAddressContainer) })
			jQuery(checkBoxContainer).find("input").keyup(function() { setPostAddressMarketeersEvents(checkBoxContainer, altAddressContainer) })
		}
	}
	/* END PUBLIC */
})();




Estate.Plastica.ImageViewer = (function() {
	/* Start public */
	return {
		Init: function() {
			var flashvars = {};
				flashvars.xmlConfigURL = document.location.href + "?xml=1";
			var params = {};
				params.wmode = "transparent";
			var attributes = {};

			if (swfobject.getFlashPlayerVersion().major >= 9) {
				swfobject.embedSWF("/Flash/ImagesSpotlight.swf?random=" + Math.random(), "Spotlight", "478", "238", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
			}
		}
	}
	/* End public */
})();


Estate.Plastica.KleurLightBox = (function() {
	var config = {
		accordionSelector: "#KleurProducten",
		animationSpeed: 200,
		popupIdAppend: "",
		loadMessage: "<div class='lightboxLoader'><img src='/images/ajax-loader.gif' width='32' height='32' alt='Loading...' /></a>"
	}

	function afterAjaxLoad() {
		initAccordion()
		initPopupEvents()
	}

	function initAccordion() {
		var accordionItem = jQuery(config.accordionSelector);
		jQuery(accordionItem).find("li:eq(0) ul").show();
		jQuery(accordionItem).find("li").click(function() {
			jQuery(this).parent("ul").addClass("ignore")
			jQuery(accordionItem).find("ul:visible").not(".ignore").slideUp(config.animationSpeed)
			jQuery(this).find("> ul:hidden").slideDown(config.animationSpeed)
			jQuery(this).find("ul").removeClass("ignore")
		})
	}

	function initPopupEvents() {
		jQuery('#DivPopupWindow'+ config.popupIdAppend +' div.kleurAfbeelding1op1, #DivPopupWindow'+ config.popupIdAppend +' div.kleurAfbeeldingImpressie').click(function() {
			placeImagePopupCode("<img src='" + jQuery(this).find('img').attr('src') + "' alt='' />")
			var popupConfig = {
				animationSpeed: 250,
				scrollToWindow: false,
				closeText: "",
				windowSelector: "#DivPopupWindowImage",
				backgroundSelector: "#DivPopupBackgroundImage"
			}
			var popup = new Estate.Popup(popupConfig);
			popup.Open();
		})
	}

	function placeImagePopupCode(html) {
		if (document.getElementById('DivPopupWindowImage') == null) {
			var popupHTML = '';
			popupHTML += '<div id="DivPopupWindowImage" class="divPopupWindow divPopupWindowImage"><div class="innerDivPopupWindow">';
			popupHTML += '    <div class="close"></div>';
			popupHTML += '    <div class="popupContent"></div>';
			popupHTML += '</div></div>';
			popupHTML += '<div id="DivPopupBackgroundImage" class="divPopupBackground divPopupBackgroundImage"></div>';
			jQuery('body').append(popupHTML);
		} else {
			jQuery('#DivPopupWindowImage div.popupContent').html('');
		}

		if (typeof (html) == 'string') {
			jQuery('#DivPopupWindowImage div.popupContent').html(html);
		}
	}
	
	/* START PUBLIC */
	return {
		Init: function(loadURL, popupId) {
			if (typeof (popupId) != "undefined") {
				config.popupIdAppend = popupId
			}
			jQuery("#DivPopupWindow"+ config.popupIdAppend +" div.popupContent").html(config.loadMessage)
			jQuery("#DivPopupWindow" + config.popupIdAppend + " div.popupContent").load(loadURL + " #mainform > div", afterAjaxLoad)
			jQuery("#DivPopupWindow" + config.popupIdAppend + " div.popupContent").addClass("kleurLightbox")
			jQuery("#DivPopupWindow" + config.popupIdAppend + "").attr("class", "divPopupWindow divPopupWindowKleuren")
		}
	}
	/* END PUBLIC */
})();






Estate.Plastica.ProjectLightBox = (function() {
	var config = {
		loadMessage: "<div class='lightboxLoader'><img src='/images/ajax-loader.gif' width='32' height='32' alt='Loading...' /></a>"
	}

	function afterAjaxLoad() {
		initGallery()
		initTabs()
	}

	function initGallery() {
		var gallery = new Estate.Gallery();
		gallery.Run();
	}

	function initTabs() {
		var tabList = jQuery("#DivPopupWindow dl")
		jQuery(tabList).find("dd:eq(0)").show()
		jQuery(tabList).find("dt:eq(0)").addClass("active")
		jQuery(tabList).find("dd").each(function(index) {
			jQuery(this).css("margin-top", -(index*30) + "px")
		})
		jQuery(tabList).find("dt").click(function() {
			jQuery(tabList).find("dt").removeClass("active")
			jQuery(tabList).find("dd").hide()
			jQuery(this).addClass("active")
			jQuery(this).next("dd").show()
		})
	}

	/* START PUBLIC */
	return {
		Init: function(loadURL) {
			jQuery("#DivPopupWindow div.popupContent").html(config.loadMessage)
			jQuery("#DivPopupWindow div.popupContent").load(loadURL + " #mainform > div", afterAjaxLoad)
			jQuery("#DivPopupWindow").attr("class", "divPopupWindow divPopupWindowProjecten")
		}
	}
	/* END PUBLIC */
})();






Estate.Plastica.Forms = (function() {
	var config = {
		feedbackText: " tekens over",
		feedbackCss: "maxSizeFeedback",
		feedbackCssNearLimit: "maxSizeFeedbackNearLimit",
		NearLimitAlert: 20
	}



	function addFeedbackContainer(selector) {
		jQuery(selector).after("<span class='" + config.feedbackCss + "'></span>")
	}

	function onCharactersAdded(element, maxChars) {
		var stringSize = jQuery(element).val().length
		if (stringSize > 0) {
			
			if ((maxChars - stringSize) < config.NearLimitAlert) {
				jQuery(element).next("span." + config.feedbackCss).addClass(config.feedbackCssNearLimit)
			} else {
				jQuery(element).next("span." + config.feedbackCss).removeClass(config.feedbackCssNearLimit)
			}
			if ((maxChars - stringSize) < 0) {
				jQuery(element).val(jQuery(element).val().substr(0, maxChars))
				jQuery(element).next("span." + config.feedbackCss).html(0 + config.feedbackText);
			}

			stringSize = jQuery(element).val().length
			jQuery(element).next("span." + config.feedbackCss).html((maxChars - stringSize) + config.feedbackText);
		}
	}
	
	
	
	/* START PUBLIC */
	return {
		SetTextAreaMaxCharacters: function(selector, maxChars, feedbackText) {
			if (typeof(feedbackText) !== "undefined") {
				config.feedbackText = " " + feedbackText;
			}
			if (jQuery(selector).size() > 0) {
				addFeedbackContainer(selector)
				jQuery(selector).keyup(function() { onCharactersAdded(this, maxChars) })
				jQuery(selector).change(function() { onCharactersAdded(this, maxChars) })
				jQuery(selector).mouseout(function() { onCharactersAdded(this, maxChars) })
				jQuery(selector).mouseover(function() { onCharactersAdded(this, maxChars) })
			}
		}
	}
	/* END PUBLIC */
})();












