var preloadSrc = ['/images/menu-motocross-on.gif','/images/menu-enduro-on.gif', '/images/menu-trial-on.gif', '/images/menu-speedway-on.gif', '/images/menu-jaarata-on.gif', '/images/menu-supermoto-on.gif'];
for (var src in preloadSrc)
{
	var preloadImg = new Image();
	preloadImg.src = preloadSrc[src];
}

$(document).ready(function(){
	var bg;

	$('#user').focus(function(){
		if($(this).val() == 'Käyttäjä')
			$(this).val('');		
	});
	$('#user').blur(function(){
		if($(this).val() == '')
			$(this).val('Käyttäjä');
	});
	$('#pass').focus(function(){
		if($(this).val() == 'Salasana')
			$(this).val('');		
	});
	$('#pass').blur(function(){
		if($(this).val() == '')
			$(this).val('Salasana');
	});
	
	$('.menuitem a.mainitem img.on').fadeTo(0.001, 0, function() { $(this).show(); });
	$('.submenu').each(function()
	{
		$(this).data('animateHeight', $(this).height());
	});
	$('.submenu').css('height', '0px').animate({'height': '0px'}, 0.001);
	
	$('.menuitem').hover(function(){
		var animateHeight = $(this).children('.submenu').data('animateHeight');
		$(this).find('a.mainitem img.on').stop().animate({'opacity': 1.0}, 'fast');
		$(this).children('.submenu').stop().animate({'height': animateHeight+'px'}, 'fast');
	}, function(){
		$(this).find('a.mainitem img.on').stop().animate({'opacity': 0.0}, 'fast');
		$(this).children('.submenu').stop().animate({'height': '0px'}, 'fast');
		
	});
	
	$('#login .field input').focus(function()
	{
		if (!this.activated)
		{
			$(this).val('').css('color', '#000');
			this.activated = true;
		}
	});
	
	$('#login .field input').blur(function()
	{
		var $this = $(this);
		if ($this.val() == '')
		{
			$this.css('color', '#888').val($this.attr('type') == 'text' ? 'Käyttäjänimi' : 'Salasana');
			this.activated = false;
		}
	});
	
	$('.image-container').hover(function(){
		$('.image-container-additional').show();
	}, function(){
		$('.image-container-additional').hide();		
	});
	
	$('.image-container-additional img').click(function(){
		var file = $(this).attr('file');
		var author = $(this).attr('author');
		var description = $(this).attr('alt');
		
		
		$(this).parent().siblings('img').attr('src', "/upload/media/resized-"+file);
		$(this).parent().next('p.kuvateksti').html( (description) ? description : '' + (description && author) ? ', ' : '' + (author) ? '<i>Kuva: '+author+'</i>' : '');
		
	});
});
