jQuery.fn.packtool = function() 
{
    var o = $(this)[0];

	if(o !== undefined)
	{
		var packTool = o;
		var packElements = $(packTool).find('.packelement');
		var packTypes = getProductTypes(packElements);
		var packLength = packTypes.length;
		
		$('.the_pack').each(
			function()
			{
				var elements = $(this).find('.packelement');
				elements.not($(elements).eq(0)).css('opacity', 0.3);
			}
		);

		$('.product_list .product').live('click', 
			function()
			{
				var type = getCurrentProductType(this);
				var currentPackElement = $('.the_pack .packelement.'+type);
				
				for ( var i in packTypes )
				{
					if(packTypes[i] == type)
					{
						var current = i;
						current++;
					}
				}
				
				if( current == packLength )
				{
					$('#confirme_pack').css('display','none');
					$('.the_pack .packelement').css('opacity', 1);
				}
				else 
				{
					$('.the_pack .packelement').css('opacity', 0.3);
					$('.the_pack .packelement.'+packTypes[current++]).css('opacity', 1);
				}
			}
		);
		
		function getProductTypes(e)
		{
			var types = [];
			e.each(
				function()
				{
					var type = $(this).attr('class').split(' ')[3].toString();
					types.push( type );
				}
			);
			return types;
		}
		
		function getCurrentProductType(e)
		{
			return $(e).parent().attr('class').split(' ')[1];
		}

	}
}
