(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}));
			}
		});
	});
})();