(function()
{
	var orderListLink, originalValue;
	
	function updateLinkCount()
	{
		if (orderListLink === undefined)
		{
			orderListLink = $$('#header .mod_links .last h4').first();
			originalValue = orderListLink.innerHTML;
		}
		
		orderListLink.update(originalValue + ' (' + $('products_count').value + ')');
	}
	
	if (typeof updateProductCount === 'function')
	{
		updateProductCount = (function(method)
		{
			return function(amount)
			{
				method.call(this, amount);
				updateLinkCount();
			}
		})
		(updateProductCount);
	}
	
	document.observe('dom:loaded', function()
	{
		var header = $('header');
		
		if (header !== null)
		{
			header.setStyle({cursor: 'pointer'});
			
			header.observe('click', function()
			{
				window.location = '/home';
			});
			
			updateLinkCount();
		}
		
		$$('#products .mod_images').each(function(imageContainer)
		{
			var links = imageContainer.next('.mod_slogan').select('a');
			
			if (links.length > 0)
			{
				var href = links[0].readAttribute('href');
				
				imageContainer.select('.mod_images_image img').invoke('wrap', new Element('a', {'href': href}));
			}
		});
	});
})();

$j(function()
{
	if (location.pathname === '/informatie-aanvragen')
	{
		var label = $j('form label:contains(Product:)');
		if (label.length)
		{
			var input = $j('#' + label.attr('for'));
			var values = {}, entries = location.search.substring(1).split('&'), entry, i, length;
			for (i = 0, length = entries.length; i < length; i++)
			{
				entry = entries[i].split('=');
				if (entry.length === 2)
				{
					values[entry[0]] = unescape(entry[1]);
				}
			}
			input.val(values['product_name']);
		}
	}
	else
	{
		var container = $j('#main');
		var moreInfo = container.find('.more_information a');
		if (moreInfo.length)
		{
			var productName = container.find('>h1, >h3').text();
			productName = productName.substring(productName.lastIndexOf('>') + 1, productName.length);
			productName = $j.trim(productName);
			moreInfo.attr('href', '/informatie-aanvragen?product_name=' + escape(productName));
		}
	}
});

