
$(document).ready(function(){
	
	/* Materiaaliryhmä-ikkunat */
	$('#info-window .item h3 a').click(function() {
		$('.window').fadeOut(250);
		var Window = $(this).parent('h3').next('.window');
		if(Window.is(':visible'))
			Window.fadeOut(250);
		else
			Window.fadeIn(250);
		return false;
	});
	$('#info-window .window a.close').click(function() {
		$('.window').fadeOut(250);
	});
	
	/* Buttoni */
	$('<span class="button-bg"></span>').appendTo('a.button-big');
	
	/* Facebox */
	$('a[rel*=facebox]').facebox({
		closeImage: 'facebox/closelabel.png'
	});
	
});


/* Lomakkeen validointi */
function validate_form(Form) {
	
	var Error = false;
	
	$(Form +' .validate_msg').fadeOut();
	$(Form +' label').css('color', '#000000');
	
	$(Form + ' select').each(function() {
		if($(this).children('option:selected').val() == '0' && $(this).prev('label').is(':contains("*")'))
			Error = stop_validate($(this));
	});
	
	$(Form +' input[type="text"], '+ Form +' input[type="checkbox"], '+ Form +' input[type="radio"]').each(function() {
		if($(this).val() == '' && $(this).prev('label').is(':contains("*")')) {
			Error = stop_validate($(this));
		}
	});
	
	$(Form +' textarea').each(function() {
		if($(this).val() == '' && $(this).prev('label').is(':contains("*")')) {
			Error = stop_validate($(this));
		}
	});
	
	if(Error == true) {
		$(Form +' .validate_msg').fadeIn();
		return false;
	} else {
		return true;
	}
}

function stop_validate(Item) {
	Item.prev('label').css('color', '#ff0000');
	return true;
};


/* Email-suojaus */
function email_antispam(End, Domain, Name) {
	document.write("<a href=\"mailto: "+ Name +"\u0040"+ Domain +"\u002e"+End+"\">"+Name+"\u0040"+Domain);
	document.write("\u002e"+End+"</a>");
}
