var CONFIG = {}, Waterkoelers = {}, objLargeCart, objSmallCart, objAjaxCall, objOverlay, objMessage;

window.addEvent('domready', function()
{
	CONFIG.BASE_URL = $(document.head).getElement('base').get('href');
	
	objMessage = new Waterkoelers.Message;
	
	// Reset Form Inputfields
	new Waterkoelers.resetInputs('.resetinput');
	
	// Create Tabs
	$$('.tabcontent').each(function(el, i)
	{
		new Waterkoelers.Tabs( 
			el.getElements('ul.tabs li'),
			el.getElements('div.tab'), 
			el.getElement('ul.tabs li.active')
		);
	});
	
	// Create Small Shopping Cart
	if ($('shoppingcart'))
	{
		objSmallCart = new Waterkoelers.ShoppingCartSmall({}, $('shoppingcart'));
	}
	
	// Create Large Shopping Cart
	if ($('shoppingcart_large'))
	{
		objLargeCart = new Waterkoelers.ShoppingCartLarge({}, $('shoppingcart_large'));
	}
	
	// Product Detail Page
	if ($('product_detail'))
	{
		new Waterkoelers.ProductDetailPage;
	};
	
	// Customer Form For Copy fields
	if ($('customerform'))
	{
		new Waterkoelers.CustomerForm(
		{
			elWrapper: $('customerform')
		});
	};
	
	if ($('topoffer'))
	{
		new Waterkoelers.Topoffer;
	};
	
	// Custom Form Submits
	$$('.formSubmit').addEvent('click', function(e)
	{
		e.stop();
		this.getParent('form').submit();
	});
	
	new Waterkoelers.customFormSubmit;
	
	// Payment Form, Click Events
	$$('fieldset.payment-option').each(function(el, i)
	{
		el.getElement('input.radio').addEvents(
		{
			click: function()
			{
				if (this.get('checked'))
				{
					if (el.getParent('form').getElement('fieldset.active'))
					{
						el.getParent('form').getElement('fieldset.active').removeClass('active');
					}
					el.addClass('active');
				};
			}
		});		
		el.getElement('input.radio').fireEvent('click');
	});
	
	objOverlay = new Waterkoelers.Overlay;
	new Waterkoelers.ImageOverlay;
	
	$$('.defaultamounter').each(function(el)
	{
		new Waterkoelers.ProductAmounterDefault(
		{
			'elAmounter': el,
			'minAmount': 6
		});
	});
	
});


Waterkoelers.Topoffer = new Class(
{
	options: {
		elWrapper: false,
		arrItems: false,
		intItems: false,
		intDelay: 8000,
		intActive: 0,
		intTimer: false
	},
	Implements: Options,
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.options.elWrapper = $('topoffer');
		this.options.arrItems = this.options.elWrapper.getElements('div.pushbox');
		this.options.intItems = this.options.arrItems.length;
		
		this.hideOthers();
		
		if (this.options.intItems > 1)
		{
			this.options.intTimer = this.showNext.periodical(this.options.intDelay, this);
		}
	},
	
	hideOthers: function()
	{
		this.options.arrItems.each(function(el, i)
		{
			if (i != 0)
			{
				el.setStyle('display', 'block').fade('hide');
			};
			
			el.set('tween', { 'duration': 500 });
		});
	},
	
	getNext: function()
	{
		this.options.intActive++;
		if (this.options.intActive >= this.options.intItems)
		{
			this.options.intActive = 0;
		}
	},
	
	showNext: function()
	{
		this.options.arrItems[this.options.intActive].fade(0);
		this.getNext();
		this.options.arrItems[this.options.intActive].fade(1);
	}
});


Waterkoelers.CustomerForm = new Class(
{
	options: {
		elWrapper: false,
		arrCopyFields: false,
		arrResultFields: new Array(),
		elToggler: false
	},
	Implements: [Options, Events],
	
	initialize: function(options, elWrapper)
	{
		this.setOptions(options);
		
		this.options.elToggler = this.options.elWrapper.getElement('.togglecopy');
		
		this.options.arrCopyFields = this.options.elWrapper.getElements('.copyfield');		
		this.options.arrCopyFields.each(function(el, i)
		{			
			this.options.arrResultFields.push(this.options.elWrapper.getElement('input[name='+el.get('name')+'_invoice]'));
		}.bind(this));
		
		this.options.arrCopyFields.addEvents(
		{
			blur: function()
			{
				this.options.arrResultFields.each(function(el, i)
				{
					el.set('value', this.options.arrCopyFields[i].get('value'));
				}.bind(this));
				
				if (this.options.elWrapper.getElement('.genderfield:checked'))
				{
					var strValue = this.options.elWrapper.getElement('.genderfield:checked').get('value');
					this.options.elWrapper.getElements('input[name=gender_invoice]').each(function(el, i)
					{
						if (el.get('value') == strValue)
						{
							el.set('checked', true);
						};
					});
				};
			}.bind(this)
		});
		
		this.options.elToggler.addEvents(
		{
			click: function()
			{
				var blnChecked = this.options.elToggler.get('checked');
				if (blnChecked)
				{
					this.options.arrResultFields.each(function(el, i)
					{
						el.set('value', '');
					}.bind(this));
					this.options.elWrapper.getElement('.invoiceaddress').show();
				}
				else
				{
					this.options.arrCopyFields[0].fireEvent('blur');
					this.options.elWrapper.getElement('.invoiceaddress').hide();
				}
			}.bind(this)
		});
	}
});


Waterkoelers.customFormSubmit = new Class(
{
	options: {
		arrForms: false
	},
	Implements: Options,	
	initialize: function(options)
	{		
		this.options.arrForms = $$('.customFormSubmit');				
		this.submitToSession();
		
		this.options.arrForms.each(function(elForm, intKey)
		{
			elForm.getElement('.link_submit').addEvent('click', function(e)
			{
				e.stop();
				elForm.send();
			});
		});
	},
	
	submitToSession: function()
	{
		this.options.arrForms.each(function(elForm, intKey)
		{
			elForm.set('send', 
			{
				method: 'post',
				onComplete: function(objResponse)
				{
					// Return Object
					objReturn = JSON.decode(objResponse);

					if (objReturn.blnValid)
					{
						document.location.href = CONFIG.BASE_URL + 'bestellen/winkelwagen/type/' + objReturn.data.ordertype;
					};
				}.bind(this)
			});
			elForm.addEvent('submit', function(e)
			{
				e.stop();
				elForm.send();
			}.bind(this));
		});
	}
});


Waterkoelers.ProductDetailPage = new Class(
{
	options: {
		elWrapper: false,
		elFormsToSession: false,
		arrOrderTypeElements: false
	},
	Implements: [Options, Events],
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.options.elWrapper = $('product_detail');		
		this.options.elFormsToSession = this.options.elWrapper.getElement('.formToSession');
		this.options.arrOrderTypeElements = this.options.elWrapper.getElements('.setOrderType');
		
		this.options.elWrapper.getElement('form button').addEvent('click', function()
		{
			$('ordertype').set('value', 'order');
		});
				
		this.submitToSession();
		
		this.changeInputs();
	},
	
	changeInputs: function()
	{
		this.options.arrOrderTypeElements.each(function(elButton, intKey)
		{
			elButton.addEvents(
			{
				click: function(e)
				{
					e.stop();
					arrValue = elButton.get('title').split('::');
					$('ordertype').set('value', arrValue[0]);
					$('sellingtype').set('value', arrValue[1]);
					
					this.options.elFormsToSession.send();
				}.bind(this)
			});
		}.bind(this));
	},
	
	submitToSession: function()
	{
		this.options.elFormsToSession.set('send', 
		{
			method: 'post',
			onComplete: function(objResponse)
			{
				// Return Object
				objReturn = JSON.decode(objResponse);
				
				if (objReturn.blnValid)
				{
					document.location.href = CONFIG.BASE_URL + 'bestellen/winkelwagen/type/' + objReturn.data.ordertype;
				};
			}.bind(this)
		});
		
		this.options.elFormsToSession.addEvent('submit', function(e)
		{
			e.stop();
			this.options.elFormsToSession.send();
		}.bind(this));
	}
	
});


// ShoppingCart Large
Waterkoelers.ShoppingCartLarge = new Class(
{
	
	options: {
		elWrapper: false,
		elLoading: false,
		elTotalField: false,
		ProductAmounter: false,
		strAjaxCallPath: 'sessionHandler.php',
		blnFirst: true
	},
	Implements: Options,
	
	initialize: function(options, elWrapper)
	{		
		this.setOptions(options);
		
		this.options.elWrapper = elWrapper;
		this.options.elLoading = elWrapper.getElement('#cart_loading');
		this.options.elTotalField = elWrapper.getElement('.totalprice-cart');
		
		this.changeSellingType();	
		
		this.options.blnFirst = false;	
		
		this.addCartEvents();
	},
	
	getRentAmount: function(elMain)
	{
		var value = elMain.getElement('input.rent_years').get('value').toInt();
		if (value > 4)
		{
			return 4;
		}
		return value;
	},
	
	updateProductTotal: function(elMain)
	{
		var intPrice, intAmount, intTime = 0;
		if (elMain.getElement('.sellingtype').get('value') == 'rent')
		{		
			var rentYears = this.getRentAmount(elMain);
			// Set Stuff
			elMain.getElement('span.subtotal_product_buy').hide();
			
			elMain.getElement('span.subtotal_product_rent_year1').hide();
			elMain.getElement('span.subtotal_product_rent_year2').hide();
			elMain.getElement('span.subtotal_product_rent_year3').hide();
			elMain.getElement('span.subtotal_product_rent_year4').hide();
			elMain.getElement('span.subtotal_product_rent_year'+rentYears).inline();
			
			intPrice = elMain.getElement('span.subtotal_product_rent_year'+rentYears).get('text').replace(',', '.').toFloat();
			intTime = elMain.getElement('.rent_years').get('value');
		}
		else
		{			
			// Set Stuff
			if (!elMain.hasClass('noProduct'))
			{
				//elMain.getElement('span.subtotal_product_rent').hide();
				elMain.getElement('span.subtotal_product_rent_year1').hide();
				elMain.getElement('span.subtotal_product_rent_year2').hide();
				elMain.getElement('span.subtotal_product_rent_year3').hide();
				elMain.getElement('span.subtotal_product_rent_year4').hide();
			};
			elMain.getElement('span.subtotal_product_buy').inline();
			intPrice = elMain.getElement('span.subtotal_product_buy').get('text').replace(',', '.').toFloat();
		}
		intAmount = elMain.getElement('.productamount').get('value');
		
		if (elMain.hasClass('waterItem'))
		{
			if (intAmount <= 12)
			{
				intPrice = elMain.getElement('span.subtotal_product_buy_org').get('text').replace(',', '.').toFloat();
			};
			if(intAmount > 12 && intAmount < 25)
			{
				intPrice = elMain.getElement('span.subtotal_product_buy_org').get('text').replace(',', '.').toFloat();			
				intPrice = this.toNumber(intPrice * 12 / 13, 15);
				intPrice = this.toCalculate(intPrice).toFloat();
			}

			if(intAmount > 24)
			{
				intPrice = elMain.getElement('span.subtotal_product_buy_org').get('text').replace(',', '.').toFloat();
				intPrice = this.toNumber(intPrice * 12 / 13, 15);
				intPrice = this.toCalculate(intPrice);
				intPrice = this.toNumber(intPrice * 24 / 25, 15);
				intPrice = this.toCalculate(intPrice);
			}
			
			if (elMain.getElement('.subtotal_product_buy').get('text') != this.toNumber(intPrice) && this.options.blnFirst == false)
			{
				// Set Message
				objMessage.set('De prijs van het geselecteerde product is veranderd in: &euro; '+ this.toNumber(intPrice));
			}

			elMain.getElement('.subtotal_product_buy').set('text', this.toNumber(intPrice));
		}
		
		elMain.getElement('.total_product').set('text', this.toNumber(intPrice * intAmount));		

		this.updateTotal();
	},
	
	changeSellingType: function()
	{
		$$('.sellingtype').each(function(el, i)
		{			
			el.addEvents(
			{
				change: function()
				{
					if (el.getParent().getNext('.togglefield'))
					{
						if (el.get('value') == 'rent')
						{
							if (el.getParent().getNext('.togglefield').getElement('input').get('value') == 0)
							{
								el.getParent().getNext('.togglefield').getElement('input').set('value', 1);
							}
							el.getParent().getNext('.togglefield').show();
						}
						else
						{
							el.getParent().getNext('.togglefield').hide();
							if (el.getParent().getNext('.togglefield').getElement('input').get('value') == 1)
							{
								el.getParent().getNext('.togglefield').getElement('input').set('value', 0);
							}
						}
					};
					this.updateProductTotal(el.getParent('tr'));
				}.bind(this)
			});
			el.fireEvent('change');
		}.bind(this));
	},
	
	addCartEvents: function()
	{
		this.options.ProductAmounter = new Waterkoelers.ProductAmounter;
		
		$$('.btn_delete_large').each(function(el, i)
		{
			if (el.hasEvent('click') == null)
			{
				el.addEvents(
				{
					click: function(e)
					{
						e.stop();
						el.getParent('tr').getElements('td').highlight('#ffb2b2');
						this.removeProduct.delay(400, this, el.getParent('tr'));
					}.bind(this)
				});
			}
		}.bind(this));
		
		$$('.updateSelect').each(function(el, i)
		{
			el.addEvent('change', function()
			{
				this.updateSession(el);
			}.bind(this));
		}.bind(this));
	},
	
	updateSession: function(elInput)
	{
		var objUpdateRequest = new Request.JSON(
		{
			url: CONFIG.BASE_URL + this.options.strAjaxCallPath + '?function=updateSession'
		}).post(
		{
			'hash': elInput.getParent('tr').getElement('.hashname').get('value'),
			'key': elInput.get('name'),
			'value': elInput.get('value')
		});
		
		this.updateProductTotal(elInput.getParent('tr'));
	},
	
	removeFromSession: function(el)
	{
		var objUpdateRequest = new Request.JSON(
		{
			url: CONFIG.BASE_URL + this.options.strAjaxCallPath + '?function=removeFromSession'
		}).post({ 'hash': el.getElement('.hashname').get('value') });
	},
	
	removeProduct: function(el)
	{
		this.removeFromSession(el);
		el.dispose();
		
		this.updateTotal();
	},
	
	updateTotal: function()
	{		
		var intSubTotal = 0;
		var intRentTotal = 0;
		var intDeposit = 0;
		var intShipping = 0;

		this.options.elWrapper.getElements('.shoppingcart_table tbody tr.productrow').each(function(elTr, intKey)
		{
			if (elTr.getElement('.sellingtype').get('value') == 'buy')
			{
				intSubTotal += this.toCalculate(elTr.getElement('.total_product').get('text')).toFloat();
			}
			else
			{
				var rentYears = this.getRentAmount(elTr);
				var intProductTotal = elTr.getElement('.subtotal_product_rent_year'+rentYears).get('text').replace(',', '.').toFloat();
				
				intRentTotal += intProductTotal * this.toCalculate(elTr.getElement('.productamount').get('value')).toInt();
			}
			if (elTr.hasClass('depositItem') && !elTr.hasClass('actionItem'))
			{
				intDeposit += 10 * elTr.getElement('.productamount').get('value').toInt();
			}

			if (elTr.hasClass('actionItem'))
			{
				intDeposit += elTr.getElement('span.depositAction').get('text') * elTr.getElement('.productamount').get('value').toInt();
			}

		}.bind(this));
			
		this.options.elTotalField.getElement('span.subtotal').set('text', this.toNumber(intSubTotal));
		this.options.elTotalField.getElement('span.deposit').set('text', this.toNumber(intDeposit));
		this.options.elTotalField.getElement('span.shipping').set('text', this.toNumber(intShipping));
		this.options.elTotalField.getElement('span.totalprice').set('text', this.toNumber((intSubTotal + intDeposit + intShipping)));
		this.options.elTotalField.getElement('span.totalprice_month').set('text', this.toNumber(intRentTotal));
	},
	
	toCalculate: function(argStrNumber)
	{
		return argStrNumber.replace(',', '.');
	},
	
	toNumber: function(argIntNumber, argIntFloat)
	{
		if(argIntFloat == null)
		{
			argIntFloat = 2;
		}
		return argIntNumber.toFloat().toFixed(argIntFloat).replace('.', ',');
	}
	
});


// ShoppingCart Small
Waterkoelers.ShoppingCartSmall = new Class(
{
	
	options: {
		elWrapper: false,
		elEmpty: false,
		elFull: false,
		elAddCartButtons: false,
		elTotalField: false,
		ProductAmounter: false,
		Cart: false,
		strAjaxCallPath: 'sessionHandler.php',
		blnFirst: true
	},
	Implements: Options,
	
	initialize: function(options, elWrapper)
	{	
		this.setOptions(options);
		
		this.options.elWrapper = elWrapper;
		this.options.elEmpty = elWrapper.getElement('#cart_empty');
		this.options.elFull = elWrapper.getElement('#cart_full');
		
		if (this.options.elFull)
		{
			this.options.elTotalField = this.options.elFull.getElement('.cart_total');

			this.options.Cart = this.options.elFull.getElements('.cart_item');
			
			this.addCartEvents();
			
			this.updateTotal();
			
			this.options.blnFirst = false;
		}
		else
		{
			this.options.Cart = new Hash();
		}
	},
	
	updateWaterPrice: function(elMain)
	{
		
		var intPrice, intAmount;
		
		// Set Stuff
		intPrice = elMain.getElement('span.price em.price_buy').get('text').split(' ')[0];
		intPrice = intPrice.replace(',', '.').toFloat();

		intAmount = elMain.getElement('.product_amounter input').get('value');

		if (intAmount <= 12)
		{
			intPrice = elMain.getElement('span.price_buy_org').get('text').replace(',', '.').toFloat();
		}
			
		if(intAmount > 12 && intAmount < 25)
		{
			intPrice = elMain.getElement('span.price_buy_org').get('text').replace(',', '.').toFloat();			
			intPrice = this.toNumber(intPrice * 12 / 13, 15);
			intPrice = this.toCalculate(intPrice).toFloat();
		}
		if(intAmount > 24)
		{
			intPrice = elMain.getElement('span.price_buy_org').get('text').replace(',', '.').toFloat();
			intPrice = this.toNumber(intPrice * 12 / 13, 15);
			intPrice = this.toCalculate(intPrice);			
			intPrice = this.toNumber(intPrice * 24 / 25, 15);
			intPrice = this.toCalculate(intPrice);
		}
		
		if (elMain.getElement('span.price em.price_buy').get('text') != this.toNumber(intPrice) && this.options.blnFirst == false)
		{
			// Set Message
			objMessage.set('De prijs van het geselecteerde product is veranderd in: &euro; '+ this.toNumber(intPrice));
		};
		
		elMain.getElement('span.price em.price_buy').set('text', this.toNumber(intPrice));

		return intPrice;
	
	},	
	
	addCartEvents: function()
	{
		this.options.ProductAmounter = new Waterkoelers.ProductAmounterSmallCart;
		
		$$('.btn_delete').each(function(el, i)
		{
			if (el.hasEvent('click') == null)
			{
				el.addEvents(
				{
					click: function()
					{
						el.getParent().highlight('#ffb2b2');
						this.removeProduct.delay(400, this, el.getParent());
					}.bind(this)
				});
			}
		}.bind(this));
		
		this.options.Cart.each(function(el, i)
		{
			if (el.getElement('fieldset'))
			{
				el.getElements('fieldset input').each(function(elInput)
				{
					elInput.addEvent('change', function(e)
					{
						this.updateSellingType(el);
					}.bind(this));
				}.bind(this));
			}
		}.bind(this));
	},
	
	removeProduct: function(el)
	{
		// Remove Element From Cookie
		var objUpdateRequest = new Request.JSON(
		{
			url: CONFIG.BASE_URL + this.options.strAjaxCallPath + '?function=removeFromSession'
		}).post({ 'hash': el.getElement('.hashname').get('value') });
		
		el.dispose();
		
		this.updateTotal();
		
		this.checkEmpty();
	},
	
	updateAmount: function(argElInput)
	{
		var objUpdateRequest = new Request.JSON(
		{
			url: CONFIG.BASE_URL + this.options.strAjaxCallPath + '?function=updateSession'
		}).post(
		{
			'hash': argElInput.getParent('.cart_item').getElement('.hashname').get('value'),
			'key': argElInput.get('name'),
			'value': argElInput.get('value')
		});
		
		if(argElInput.hasClass('waterBottle'))
		{
			this.updateWaterPrice(argElInput.getParent('.cart_item'));
		}
		
		this.updateTotal();
	},
	
	updateSellingType: function(argElMain)
	{
		var strSellingType = argElMain.getElement('input[type=radio]:checked').get('value');
		var objUpdateRequest = new Request.JSON(
		{
			url: CONFIG.BASE_URL + this.options.strAjaxCallPath + '?function=updateSession'
		}).post(
		{
			'hash': argElMain.getElement('.hashname').get('value'),
			'key': 'sellingtype',
			'value': strSellingType
		});
		
		switch (strSellingType)
		{
			case 'buy':
			{
				argElMain.getElement('span.price em.price_rent').hide();
				argElMain.getElement('span.price em.price_buy').inline();
				argElMain.getElement('span.price em.price_type').set('text', 'p/s');
				break;
			}
			case 'rent':
			{
				argElMain.getElement('span.price em.price_rent').inline();
				argElMain.getElement('span.price em.price_buy').hide()
				argElMain.getElement('span.price em.price_type').set('text', 'p/m');			
				break;
			}
		}
		
		argElMain.getElement('.sellingtype').set('value', strSellingType);
		
		this.updateTotal();
	},
	
	updateTotal: function()
	{
		var intSubTotal = 0;
		var intRentTotal = 0;
		var intDeposit = 0;
		var intShipping = 0;
		
		this.options.elFull.getElements('.cart_item').each(function(elItem, intKey)
		{			
			if (elItem.getElement('.sellingtype').get('value') == 'buy')
			{
				if (elItem.hasClass('waterItem'))
				{
					intSubTotal += this.updateWaterPrice(elItem) * elItem.getElement('div.product_amounter input').get('value').toInt();								
				}
				else
				{
					intSubTotal += this.toCalculate(elItem.getElement('span.price em.price_buy').get('text').split(' ')[0]) * elItem.getElement('div.product_amounter input').get('value').toInt();
				}
			}
			else
			{
				var intProductTotal = this.toCalculate(elItem.getElement('span.price em.price_rent').get('text')) * elItem.getElement('div.product_amounter input').get('value').toInt();
				intRentTotal += intProductTotal;
			}
			if (elItem.hasClass('depositItem') && !elItem.hasClass('actionItem'))
			{
				intDeposit += 10 * elItem.getElement('.productamount').get('value').toInt();
			}



			if (elItem.hasClass('actionItem'))
			{
				intDeposit += elItem.getElement('span.depositAction').get('text') * elItem.getElement('div.product_amounter input').get('value').toInt();
			}
		}.bind(this));
			
		this.options.elTotalField.getElement('span.subtotal').set('text', this.toNumber(intSubTotal));
		this.options.elTotalField.getElement('span.deposit').set('text', this.toNumber(intDeposit));
		this.options.elTotalField.getElement('span.shipping').set('text', this.toNumber(intShipping));
		this.options.elTotalField.getElement('span.totalprice').set('text', this.toNumber((intSubTotal + intDeposit + intShipping)));
		this.options.elTotalField.getElement('span.totalprice_month').set('text', this.toNumber(intRentTotal));
	},
	
	checkEmpty: function()
	{
		if (this.options.elFull.getElements('.cart_item').length > 0)
		{
			// Cart Full
			this.options.elWrapper.getElement('.fullcart').show();	
			this.options.elWrapper.getElement('.emptycart').hide();	
		}
		else
		{
			// Cart Empty
			this.options.elWrapper.getElement('.fullcart').hide();	
			this.options.elWrapper.getElement('.emptycart').show();
		}
	},
	
	toCalculate: function(argStrNumber)
	{
		return argStrNumber.replace(',', '.');
	},
	
	toNumber: function(argIntNumber, argIntFloat)
	{
		if(argIntFloat == null)
		{
			argIntFloat = 2;
		}
		return argIntNumber.toFloat().toFixed(argIntFloat).replace('.', ',');
	}
	
});


// Product Amounter in Shopping Cart
Waterkoelers.ProductAmounter = new Class(
{
	options: {
		minAmount: 6,
		maxAmount: 250
	},
	Implements: [Options, Events],
	
	initialize: function(options)
	{
		$$('.product_amounter').each(function(elAmounter, intKey)
		{			
			// RETURN if Amounter already exists
			if (elAmounter.hasClass('defined')){ return; }
			else { elAmounter.addClass('defined'); }
			
			var elInput = elAmounter.getElement('input');
			var strValue = elInput.get('value');
			var elPlusButton = elAmounter.getElement('li.plus');
			var elMinButton = elAmounter.getElement('li.min');
			
			elInput.addEvents(
			{
				keydown: function(e)
				{
					if (this.isNumeric(e.key, e.code) == false)
					{
						e.preventDefault();
					}
				}.bind(this),
				blur: function(e)
				{
					if (elInput.hasClass('waterBottle'))
					{
						if (elInput.get('value') == '' || elInput.get('value') < this.options.minAmount)
						{
							objMessage.set('De minimale afname hoeveelheid is ' + this.options.minAmount);
							elInput.set('value', this.options.minAmount);
							elInput.fireEvent('change');
						};
					}
					else
					{
						if (elInput.get('value') == '' || elInput.get('value') < 1)
						{
							elInput.set('value', 1);
							elInput.fireEvent('change');
						};
					}
				}.bind(this),
				mousewheel: function(event)
				{
					event.preventDefault();
					if (elInput.hasClass('waterBottle'))
					{
						if (event.wheel > 0)
						{
							elInput.set('value', elInput.get('value').toInt() + 1);
							elInput.fireEvent('change');
						}
						else
						{
							if (elInput.get('value').toInt() > this.options.minAmount)
							{
								elInput.set('value', elInput.get('value').toInt() - 1);
								elInput.fireEvent('change');
							}
						}
					}
					else
					{
						if (event.wheel > 0)
						{
							elInput.set('value', elInput.get('value').toInt() + 1);
							elInput.fireEvent('change');
						}
						else
						{
							if (elInput.get('value').toInt() > 1)
							{
								elInput.set('value', elInput.get('value').toInt() - 1);
								elInput.fireEvent('change');
							}
						}
					}
				}.bind(this),
				change: function()
				{
					if (elInput.hasClass('rent_years') && elInput.get('value').toInt() > 0 && elInput.get('value').toInt() < 5)
					{
						//objMessage.set('De huurprijs van uw product is veranderd');
					}
					if (elInput.get('value') > this.options.maxAmount)
					{
						elInput.set('value', this.options.maxAmount);
						
						// Set Message
						objMessage.set('Maximale afname overschreden. Neem contact met ons op indien u meer wilt.');
					}
					objLargeCart.updateSession(elInput);
				}.bind(this)
			});
			
			elPlusButton.addEvent('click', function(e)
			{
				e.preventDefault();
				elInput.set('value', elInput.get('value').toInt() + 1);
				elInput.fireEvent('change');
			});
			
			elMinButton.addEvent('click', function(e)
			{
				e.preventDefault();
				
				var intValue = elInput.get('value').toInt();
				if (elInput.hasClass('waterBottle'))
				{
					if (intValue - 1 > (this.options.minAmount - 1))
					{
						--intValue;

						elInput.set('value', intValue);
						elInput.fireEvent('change');
					};
				}
				else
				{
					if (intValue - 1 > 0)
					{
						--intValue;

						elInput.set('value', intValue);
						elInput.fireEvent('change');
					};
				}
			}.bind(this))
		}.bind(this));
	},
	
	isNumeric: function(strText, intKeyCode)
	{
		var strValidChars = '0123456789';
		var blnIsNumber = true;
		var strChar;
		
		var arrAcceptKeys = new Array('8', '37', '39', '46');
		
		for (i = 0; i < strText.length && blnIsNumber == true; i++) 
		{ 
			strChar = strText.charAt(i); 
			if (strValidChars.indexOf(strChar) == -1 && this.in_array(intKeyCode, arrAcceptKeys) == false) 
			{
				blnIsNumber = false;
				if(intKeyCode >= 96 && intKeyCode <= 105)
				{
					blnIsNumber = true;
				}
			}
		}
		return blnIsNumber;
	},
	
	in_array: function(needle, haystack, argStrict)
	{
	    var key = '', strict = !!argStrict; 
	    if (strict) {
	        for (key in haystack) {
	            if (haystack[key] === needle) {
	                return true;
				}
	        }
	    } else {
	        for (key in haystack) {
	            if (haystack[key] == needle)
				{
					return true;
	            }
	        }
	    }
		return false;
	}
});

// Product Amounter in Shopping Cart
Waterkoelers.ProductAmounterSmallCart = new Class(
{
	options: {
		minAmount: 6,
		maxAmount: 250
	},
	Implements: [Options, Events],
	
	initialize: function(options)
	{
		$('shoppingcart').getElements('.product_amounter').each(function(elAmounter, intKey)
		{		
			// RETURN if Amounter already exists
			if (elAmounter.hasClass('defined')){ return; }
			else { elAmounter.addClass('defined'); }
			
			var elInput = elAmounter.getElement('input');
			var strValue = elInput.get('value');
			var elPlusButton = elAmounter.getElement('li.plus');
			var elMinButton = elAmounter.getElement('li.min');
			
			elInput.addEvents(
			{
				keydown: function(e)
				{
					if (this.isNumeric(e.key, e.code) == false)
					{
						e.preventDefault();
					}
				}.bind(this),
				blur: function(e)
				{
					if (elInput.hasClass('waterBottle'))
					{
						if (elInput.get('value') == '' || elInput.get('value') < this.options.minAmount)
						{
							objMessage.set('De minimale afname hoeveelheid is ' + this.options.minAmount);
							elInput.set('value', this.options.minAmount);
							elInput.fireEvent('change');
						};
					}
					else
					{
						if (elInput.get('value') == '' || elInput.get('value') < 1)
						{
							elInput.set('value', 1);
							elInput.fireEvent('change');
						};
					}
				}.bind(this),
				mousewheel: function(event)
				{
					event.preventDefault();
					if (elInput.hasClass('waterBottle'))
					{
						if (event.wheel > 0)
						{
							elInput.set('value', elInput.get('value').toInt() + 1);
							elInput.fireEvent('change');
						}
						else
						{
							if (elInput.get('value').toInt() > this.options.minAmount)
							{
								elInput.set('value', elInput.get('value').toInt() - 1);
								elInput.fireEvent('change');
							}
						}
					}
					else
					{
						if (event.wheel > 0)
						{
							elInput.set('value', elInput.get('value').toInt() + 1);
							elInput.fireEvent('change');
						}
						else
						{
							if (elInput.get('value').toInt() > 1)
							{
								elInput.set('value', elInput.get('value').toInt() - 1);
								elInput.fireEvent('change');
							}
						}
					}
				}.bind(this),
				change: function()
				{
					if (elInput.get('value') > this.options.maxAmount)
					{
						elInput.set('value', this.options.maxAmount);
						
						// Set Message
						objMessage.set('Maximale afname overschreden. Neem contact met ons op indien u meer wilt.');
					}
					objSmallCart.updateAmount(elInput);
				}.bind(this)
			});
			
			elPlusButton.addEvent('click', function(e)
			{
				e.preventDefault();
				elInput.set('value', elInput.get('value').toInt() + 1);
				elInput.fireEvent('change');
			});
			
			elMinButton.addEvent('click', function(e)
			{
				e.preventDefault();
				
				var intValue = elInput.get('value').toInt();
				if (elInput.hasClass('waterBottle'))
				{
					if (intValue - 1 > (this.options.minAmount - 1))
					{
						--intValue;

						elInput.set('value', intValue);
						elInput.fireEvent('change');
					};
				}
				else
				{
					if (intValue - 1 > 0)
					{
						--intValue;

						elInput.set('value', intValue);
						elInput.fireEvent('change');
					};
				}
			}.bind(this))
		}.bind(this));
	},
	
	isNumeric: function(strText, intKeyCode)
	{
		var strValidChars = '0123456789';
		var blnIsNumber = true;
		var strChar;
		
		var arrAcceptKeys = new Array('8', '37', '39', '46');
		
		for (i = 0; i < strText.length && blnIsNumber == true; i++) 
		{ 
			strChar = strText.charAt(i); 
			if (strValidChars.indexOf(strChar) == -1 && this.in_array(intKeyCode, arrAcceptKeys) == false) 
			{
				blnIsNumber = false;
				if(intKeyCode >= 96 && intKeyCode <= 105)
				{
					blnIsNumber = true;
				}
			}
		}
		return blnIsNumber;
	},
	
	in_array: function(needle, haystack, argStrict)
	{
	    var key = '', strict = !!argStrict; 
	    if (strict) {
	        for (key in haystack) {
	            if (haystack[key] === needle) {
	                return true;
				}
	        }
	    } else {
	        for (key in haystack) {
	            if (haystack[key] == needle)
				{
					return true;
	            }
	        }
	    }
		return false;
	}
});


// Product Amounter in Shopping Cart
Waterkoelers.ProductAmounterDefault = new Class(
{
	options: {
		elAmounter: false,
		minAmount: 6,
		maxAmount: 250
	},
	Implements: [Options, Events],
	
	initialize: function(options)
	{
		this.setOptions(options);
				
		// RETURN if Amounter already exists
		if (this.options.elAmounter.hasClass('defined')){ return; }
		else { this.options.elAmounter.addClass('defined'); }
		
		var elInput = this.options.elAmounter.getElement('input');
		var strValue = elInput.get('value');
		var elPlusButton = this.options.elAmounter.getElement('li.plus');
		var elMinButton = this.options.elAmounter.getElement('li.min');

		elInput.addEvents(
		{
			keydown: function(e)
			{
				if (this.isNumeric(e.key, e.code) == false)
				{
					e.preventDefault();
				}
			}.bind(this),
			blur: function(e)
			{
				if (elInput.hasClass('waterBottle'))
				{
					if (elInput.get('value') == '' || elInput.get('value') < this.options.minAmount)
					{
						objMessage.set('De minimale afname hoeveelheid is ' + this.options.minAmount);
						elInput.set('value', this.options.minAmount);
						elInput.fireEvent('change');
					};
				}
				else
				{
					if (elInput.get('value') == '' || elInput.get('value') < 1)
					{
						elInput.set('value', 1);
						elInput.fireEvent('change');
					};
				}
			}.bind(this),
			mousewheel: function(event)
			{
				event.preventDefault();
				if (elInput.hasClass('waterBottle'))
				{
					if (event.wheel > 0)
					{
						elInput.set('value', elInput.get('value').toInt() + 1);
						elInput.fireEvent('change');
					}
					else
					{
						if (elInput.get('value').toInt() > this.options.minAmount)
						{
							elInput.set('value', elInput.get('value').toInt() - 1);
							elInput.fireEvent('change');
						}
					}
				}
				else
				{
					if (event.wheel > 0)
					{
						elInput.set('value', elInput.get('value').toInt() + 1);
						elInput.fireEvent('change');
					}
					else
					{
						if (elInput.get('value').toInt() > 1)
						{
							elInput.set('value', elInput.get('value').toInt() - 1);
							elInput.fireEvent('change');
						}
					}
				}
			}.bind(this),
			change: function()
			{
				if (elInput.get('value') > this.options.maxAmount)
				{
					elInput.set('value', this.options.maxAmount);
					
					// Set Message
					objMessage.set('Maximale afname overschreden. Neem contact met ons op indien u meer wilt.');
				}
				return;
			}.bind(this)
		});

		elPlusButton.addEvent('click', function(e)
		{
			e.preventDefault();
			elInput.set('value', elInput.get('value').toInt() + 1);
			elInput.fireEvent('change');
		});
		
		elMinButton.addEvent('click', function(e)
		{
			e.preventDefault();
			
			var intValue = elInput.get('value').toInt();
			if (elInput.hasClass('waterBottle'))
			{
				if (intValue - 1 > (this.options.minAmount - 1))
				{
					--intValue;

					elInput.set('value', intValue);
					elInput.fireEvent('change');
				};
			}
			else
			{
				if (intValue - 1 > 0)
				{
					--intValue;

					elInput.set('value', intValue);
					elInput.fireEvent('change');
				};
			}
		}.bind(this));
	},
	
	isNumeric: function(strText, intKeyCode)
	{
		var strValidChars = '0123456789';
		var blnIsNumber = true;
		var strChar;
		
		var arrAcceptKeys = new Array('8', '37', '39', '46');
		
		for (i = 0; i < strText.length && blnIsNumber == true; i++) 
		{ 
			strChar = strText.charAt(i); 
			if (strValidChars.indexOf(strChar) == -1 && this.in_array(intKeyCode, arrAcceptKeys) == false) 
			{
				blnIsNumber = false;
				if(intKeyCode >= 96 && intKeyCode <= 105)
				{
					blnIsNumber = true;
				}
			}
		}
		return blnIsNumber;
	},
	
	in_array: function(needle, haystack, argStrict)
	{
	    var key = '', strict = !!argStrict; 
	    if (strict) {
	        for (key in haystack) {
	            if (haystack[key] === needle) {
	                return true;
				}
	        }
	    } else {
	        for (key in haystack) {
	            if (haystack[key] == needle)
				{
					return true;
	            }
	        }
	    }
		return false;
	}
});


// Reset form Inputs
Waterkoelers.resetInputs = new Class(
{
	strInputElements: false,
	arrDefaultValues: new Array(),
		
	initialize: function(strInputFields)
	{		
		this.strInputElements = $$(strInputFields);

		this.strInputElements.each(function(el, i)
		{
			this.arrDefaultValues[i] = el.get('value');		
			el.addEvents(
			{
				focus: function(){ if (el.get('value') == this.arrDefaultValues[i]){ el.set('value', ''); }; }.bind(this),
				blur: function(){ if (!$chk(el.get('value'))){ el.set('value', this.arrDefaultValues[i]); }; }.bind(this)
			});
		}.bind(this));
	}
});


// Default Tabs
Waterkoelers.Tabs = new Class(
{
	Implements: [Options,Events],
	initialize:function(tabs,content,activate)
	{
		this.tabs = $A(tabs);
		this.content = $A(content);
		
		if(!activate){ activate = 0; }	
		
		this.tabs.each(function(el,i)
		{
			el._parent = this;
			el.i = i;
			el.addEvent('click', function(e)
			{
				this._parent.activate(this.i);
				return false;
			});
		}.bind(this));
		
		if(activate != undefined)
		{
			if($type(activate) == 'element'){ activate.fireEvent('click'); }
			else { this.activate( activate ); }
		}
	},
	
	activate:function(argI)
	{
		this.tabs.each(function(el,i)
		{
			el.removeClass('active');			
			if(i == argI){ el.addClass('active'); }
		}.bind(this));
		
		this.content.each(function(el,i)
		{			
			if(i == argI)
			{
				el.setStyle('display','block');
				el.fade('hide').fade(1);
			}
			else
			{
				el.hide();
			}
		}.bind(this));
	}
	
});


Waterkoelers.Overlay = new Class(
{
	options: {
		strLinkPath: 'a[rel=showoverlay]',
		arrLinks: false,
		elOverlay: false,
		elMask: false,
		elImage: false
	},
	Implements: Options,
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.setDefaultOptions();
	},
	
	reinit: function()
	{
		this.options.elMask = document.body.getElement('.mask');
		this.options.elOverlay = document.body.getElement('.ajax_overlay');
	},
	
	setDefaultOptions: function()
	{
		this.options.arrLinks = $$(this.options.strLinkPath);
		
		if (this.options.arrLinks.length > 0)
		{
			this.options.elOverlay = new Element('div',
			{
				'class': 'ajax_overlay'
			}).inject(document.body, 'bottom');
			
			this.createCloseBtn();
			
			this.options.elMask = new Mask;
			this.options.elMask.addEvents(
			{
				click: function()
				{
					this.hideOverlay();
				}.bind(this)
			});
		};
		
		this.addLinkEvents();
	},
	
	createCloseBtn: function()
	{
		var elCloseBtn = new Element('span',
		{
			'class': 'btn_close',
			'events': 
			{
				click: function()
				{
					this.hideOverlay();
				}.bind(this)
			}
		}).inject(this.options.elOverlay);
	},
	
	addLinkEvents: function()
	{
		this.options.arrLinks.each(function(el, i)
		{
			el.addEvents(
			{
				click: function(e)
				{
					e.stop();
					
					this.getHtml(el.get('href'));		
					
				}.bind(this)
			});
		}.bind(this));
	},
	
	getHtml: function(strLocation)
	{
		var objRequest = new Request(
		{
			url: strLocation,
			onSuccess: function(strHtml)
			{
				new Fx.Scroll(window, 
				{
					duration: 300,
					onComplete: function()
					{
						this.showOverlay();
					}.bind(this)
				}).toElement(document.body);
				
				this.options.elOverlay.empty().set('html', strHtml);
				
				if (this.options.elOverlay.getElement('form.formToDatabase'))
				{
					if ($('stop-spam') && $('input-name')){
						var firstInp = 'I-am-no-Spam';
						var secondInp = 'Submit-my-input';
						$('input-name').addEvents({
							click: function(){
								$('stop-spam').set('value', firstInp);
							},
							blur: function(){
								if ($('stop-spam').get('value') == firstInp){
									$('stop-spam').set('value', secondInp);
								}
							}
						});
					}
					
					new Waterkoelers.FormToDatabase(this.options.elOverlay.getElement('form.formToDatabase'));
				}
				
				this.createCloseBtn();
			}.bind(this)
		}).send();
	},
	
	showOverlay: function(strLocation)
	{		
		this.options.elMask.show();
		this.options.elOverlay.show();
	},
	
	hideOverlay: function()
	{
		objOverlay.options.elMask.hide();
		objOverlay.options.elOverlay.empty().hide();
	}
});


Waterkoelers.ImageOverlay = new Class(
{
	options: {
		strLinkPath: 'a[rel=overlay]',
		arrLinks: false,
		elOverlay: false,
		elMask: false,
		elImage: false
	},
	Implements: Options,
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.setDefaultOptions();
	},
	
	setDefaultOptions: function()
	{
		this.options.arrLinks = $$(this.options.strLinkPath);
		
		if (this.options.arrLinks.length > 0)
		{
			this.options.elOverlay = new Element('div',
			{
				'class': 'image_overlay'
			}).inject(document.body, 'bottom');
			
			this.createCloseBtn();
			
			this.options.elMask = new Mask;
			this.options.elMask.addEvents(
			{
				click: function()
				{
					this.hideOverlay();
				}.bind(this)
			});
		};
		
		this.addLinkEvents();
	},
	
	createCloseBtn: function()
	{
		var elCloseBtn = new Element('span',
		{
			'class': 'btn_close',
			'events': 
			{
				click: function()
				{
					this.hideOverlay();
				}.bind(this)
			}
		}).inject(this.options.elOverlay);
	},
	
	addLinkEvents: function()
	{
		this.options.arrLinks.each(function(el, i)
		{
			el.addEvents(
			{
				click: function(e)
				{
					e.stop();
					
					this.setOverlay('loading', el.getParent().getCoordinates(document.body));
					this.loadImage(el);			
					
				}.bind(this)
			});
		}.bind(this));
	},
	
	setOverlay: function(strType, objCoordinates)
	{
		switch(strType)
		{
			default:
			case 'normal':
			{
				this.options.elOverlay.setStyles(
				{
					'position': 'absolute',
					'width': 0,
					'height': 0,
					'left': 0,
					'top': 0,
					'margin-left': 0,
					'margin-top': 0
				});
				break;
			}
				
			case 'loading':
			{
				this.options.elOverlay.empty();
				this.options.elOverlay.setStyles({
					'width': objCoordinates.width - 20,
					'height': objCoordinates.height - 20,
					'left': objCoordinates.left,
					'top': objCoordinates.top
				});

				this.options.elOverlay.setStyles({'display': 'block', 'opacity': .6});		
				this.options.elOverlay.addClass('loading');
				break;
			}
		}
	},
	
	loadImage: function(el)
	{		
		var loadImage = new Asset.image(el.get('href'), 
		{
			id: 'loadImage', 
			onload: function()
			{				
				this.resizeImage(loadImage);				
		    }.bind(this)
		});
	},
	
	resizeImage: function(loadImage)
	{	
		this.options.elMask.show();
		this.options.elOverlay.setStyle('opacity', 1);
		
		this.createCloseBtn();
		
		this.options.elOverlay.removeClass('loading');
		loadImage.inject(this.options.elOverlay);
		
		var objImageSize = loadImage.getSize();
		loadImage.setStyles(
		{
			'width': this.options.elOverlay.getStyle('width'),
			'height': this.options.elOverlay.getStyle('height')
		});
		
		var objMorph = new Fx.Morph(this.options.elOverlay,
		{
			duration: 400,
			onComplete: function()
			{
				this.options.elOverlay.setStyles(
				{
					'left': '50%',
					'top': '50%',
					'position': 'fixed'
				});
			}.bind(this)
		}).start(
		{
			'width': objImageSize.x,
			'height': objImageSize.y,
			'left': document.body.getSize().x / 2,
			'top': (document.body.getSize().y / 2) + document.getScroll().y,
			'margin-left': '-'+ (objImageSize.x / 2),
			'margin-top': '-'+ (objImageSize.y / 2)
		});
		
		var objMorphImage = new Fx.Morph(loadImage,
		{
			duration: 400
		}).start(
		{
			'width': objImageSize.x,
			'height': objImageSize.y
		});
	},
	
	hideOverlay: function()
	{
		this.options.elMask.hide();
		this.options.elOverlay.empty().hide();
		this.setOverlay('normal', '');
	}
});

Waterkoelers.FormToDatabase = new Class(
{
	options: {
		elWrapper: false
	},
	
	Implements: Options,
	
	initialize: function(elForm, options)
	{
		this.options.elWrapper = elForm;
		
		this.options.elWrapper.addEvent('submit', function(e)
		{
			e.stop();
			
			if (this.checkInputs())
			{
				this.options.elWrapper.getElement('fieldset.form').hide();
				var PostRequest = new Request.JSON(
				{
					url: CONFIG.BASE_URL + 'ajax/index/addreview',
					onSuccess: function(objJSON)
					{
						if (objJSON.blnValid == true)
						{
							strHtml = '<h3>Uw recensie is toegevoegd</h3><p>Wij hebben uw recensie ontvangen. Bedankt voor het delen van uw mening.</p>';
							this.options.elWrapper.getElement('fieldset.message').set('html', strHtml);
							
							this.addComment(objJSON);
							
							objOverlay.hideOverlay.bind(this).delay(2000);
						}
						else {
							this.options.elWrapper.getElement('fieldset.form').show();
						}
					}.bind(this)
				}).post(
				{
					'product_id': this.options.elWrapper.getElement('#input-productid').get('value'),
					'name': this.options.elWrapper.getElement('#input-name').get('value'),
					'score': this.options.elWrapper.getElement('#input-score').get('value'),
					'content': this.options.elWrapper.getElement('#input-content').get('value'),
					'stop-spam': this.options.elWrapper.getElement('#stop-spam').get('value')
				});				
			}
		}.bind(this));
	},
	
	checkInputs: function()
	{
		var blnSuccess = true;
		this.options.elWrapper.getElements('.check').each(function(el)
		{
			if (el.get('value').length == 0)
			{
				el.addClass('errorfield');
				blnSuccess = false;
			}
			else
			{
				el.removeClass('errorfield');
			}
		});
		
		return blnSuccess;
	},
	
	addComment: function(objJSON)
	{
		if ($('reviews'))
		{
			var reviewWrapper = $('reviews');
			if (reviewWrapper.getElement('p.noreviews'))
			{
				reviewWrapper.getElement('p.noreviews').destroy();
				var reviewList = new Element('dl', { 'class': 'review_overview'}).inject(reviewWrapper.getElement('h2'), 'after');
			}
			else
			{
				var reviewList = reviewWrapper.getElement('dl.review_overview');
			}
			
			var defTitle = new Element('dt').inject(reviewList, 'top');
			var dtStrong = new Element('strong', { 'text': objJSON.arrRow.name }).inject(defTitle);
			for (var i = 1; i < 6; i++)
			{
				var strImage = '';
				if (i <= objJSON.arrRow.score){ strImage = 'inc/image/img_star_active.png'; }
				else { strImage = 'inc/image/img_star_inactive.png'; }
				
				var dtImage = new Element('img',
				{
					'src': strImage,
					'alt': 'score'
				}).inject(defTitle, 'bottom');
			}
			
			var defDesc = new Element('dd',
			{
				'html': '<p>'+ objJSON.arrRow.content +'</p>'
			}).inject(defTitle, 'after');
		}
	}
});


Waterkoelers.Message = new Class(
{
	options: {
		elMessageWrapper: false,
		elContent: false,
		fxMorph: false,
		blnActive: false,
		showDuration: 2500,
		defaultDuration: 2500,
		intTimer: null
	},
	Implements: Options,
	
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.createElements();
	},
	
	createElements: function()
	{
		this.options.elMessageWrapper = new Element('div',
		{
			'id': 'alertMessage',
			'styles': {
				'opacity': 0,
				'top': -100
			}
		}).inject(document.body, 'bottom');
		this.options.elContent = new Element('p').inject(this.options.elMessageWrapper);
		
		this.options.fxMorph = new Fx.Morph(this.options.elMessageWrapper,
		{
			duration: 500,
			onStart: function()
			{
				this.options.blnActive = true;
				this.options.intTimer = $clear(this.options.intTimer);
			}.bind(this),
			onComplete: function()
			{
				this.options.intTimer = (function()
				{
					this.hide();
				}).delay(this.options.showDuration, this)
			}.bind(this)
		});
	},
	
	set: function(strText)
	{
		if (this.options.blnActive)
		{
			if (this.options.elContent.get('html') != strText)
			{
				this.options.elContent.set('html', this.options.elContent.get('html') + '<br /><br />' + strText);
			}
		}
		else
		{
			this.options.elContent.set('html', strText);
		}
		this.show();
	},
	
	show: function()
	{
		this.options.fxMorph.start(
		{
			'top': -5,
			'opacity': 1
		});
	},
	
	hide: function()
	{
		(function()
		{
			this.options.elContent.empty();
			this.options.elMessageWrapper.setStyle('top', -100);
		}).delay(400, this);
		
		this.options.elMessageWrapper.fade(0);
		this.options.blnActive = false;
	}
	
	// objMessage.set('Maximale afname overschreden. Neem contact met ons op indien u meer wilt.');
});


// Element Implements
Element.implement(
{
	hasEvent: function(eventType,fn)
	{
		var myEvents = this.retrieve('events');
		return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn));
	},
	show: function()
	{
		this.setStyle('display','block');
	},
	inline: function()
	{
		this.setStyle('display','inline');
	},
	hide: function()
	{
		this.setStyle('display','none');
	}
});
