$(document).ready(function(){
	// hilighting valittu
	$('.valittu').each(function(){
		$(this).css('background-position', '0 -' + $(this).css('height'));
	});
	
	$(".hilight:not(.valittu)").hover(
		function(){
			$(this).css("background-position", "0 -" + $(this).css('height'));
		},
		function(){
			$(this).css("background-position", "0 0");
		}
	);

	initializeGallery();

});

function checkRequired()
{
	var valid;
	valid = false;

	$(".required").each(function(){
		if(this.value == undefined || this.value == ''){
			valid = false;
			alert("Arvo puuttuu: " + $(this).attr('rel'));
			return false;
		}

		valid = true;
		return true;
	});

	return valid;
}

/**
 * Comment
 */
function initializeGallery()
{
	$('#content-image').css('height', ($('#galleria img').first().height() + 0) +"px");
	$('#galleria img').first().show();
	$('#content-image span').first().show();

	$('#galleria-nav a[rel]').click(function(event){
		event.preventDefault();
		$(".gallery_content>div").hide();
		var rel = $(this).attr('rel');
		$('.gallery_content').show();
		$('#' + rel).fadeIn('slow');
	});

	$('.galleria a[rel]').click(function(event){
		event.preventDefault();
		var rel = $(this).attr('rel');
		$('.gallery-hide').hide();
		var img = $('#' + rel);
		$('#content-image').animate({height: img.height() + 0}, 400, function(){
			img.fadeIn('slow');
			$('#caption-' + rel).show();
		});
	})

}
