$(
	function ()
	{
		var menu	= $('#header .menu img');
		
		$(window).bind ('hashchange',
			function (event)
			{
				event.preventDefault ();
				event.stopPropagation();
				var div	= $(window.location.hash.replace ('#', '#_'));
				
				if (div.length > 0)
				{
					div.siblings ('.active').hide ();
					div.show ().addClass ('active');
					
					var a	= $('a[href=' + window.location.hash + ']');
					if (a.length > 0)
					{
						if (a.attr ('title'))
							document.title	= a.attr ('title') + ' - Alfa Romeo Download';
						else
							document.title	= 'Alfa Romeo Download';
						
						var img	= a.children ('img');
						var old	= $('img.ajax-active-image');
							
						if (old.length > 0)
						{
							activeImage (old.removeClass ('ajax-active-image'));
						}
					
						if (img.length > 0)
						{
							
							img.addClass ('ajax-active-image');
							activeImage (img);
						}
					}
				}
				
				return false;
			}
		);
	
	
		$('#content_left > div').hide ().each (
			function ()
			{
				$(this).children ('div:even').addClass ('even');
			}
		);
	
		$('a[href^=#]').bind ('click',
			function (event)
			{
				event.preventDefault ();
				var a	= $(this);
				window.location.hash	= a.attr ('href');
			}
		);
	
		
		if (window.location.hash.length < 1)
		{
			window.location.hash	= menu.first ().parent ().attr ('href');
		}
		else
		{
			$(window).trigger ('hashchange');	
		}
	
	
		$('#content_right').cycle ();
		$('img.hover').hover (function () { hoverImage (this); });
		
		function hoverImage (e)
		{
			var src	= $(e).attr ('src');
			
			if (src.match (/_h\.png/))
				src	= src.replace (/_h\.png/, '.png');
			else
			{
				if (!src.match (/_s\.png/))
					src	= src.replace (/\.png/, '_h.png');
			}
			
			$(e).attr ('src', src);
		}
		
		function activeImage (e)
		{
			if ($(e).length < 1) return false;

			var src	= $(e).attr ('src');

			if (src.match (/_s\.png/))
				src	= src.replace (/_s\.png/, '.png');
			else
			{
				if (src.match (/_h\.png/))
					src	= src.replace (/_h\.png/, '_s.png');
				else
					src	= src.replace (/\.png/, '_s.png');
			}
			
			$(e).attr ('src', src);
		}
	}
);