jQuery.noConflict();

jQuery(document).ready(function($)
{
	// Footerin uutiskaruselli
	$("div#uutiskaruselli").jCarouselLite(
	{
		btnNext: ".carousel_next",
		btnPrev: ".carousel_prev",
		speed: 500,
		visible: 1,
		scroll: 1
	});
	
	// Alavalikon haitari
	$('div#sub_navigation ul.navigation ul').each(function() // Close all subnavs unless parent is active
	{
		if ($(this).parent().hasClass('active') == false && $(this).parent().hasClass('parent-active') == false)
		{$(this).hide();}
	});
/*	
	$('div#sub_navigation ul.navigation li:has(ul)').hover(function() // On hover open/close subnav. Active subnav is never closed.
	{
		$(this).addClass('current');
		$(this).children('ul').slideDown('fast');
	}, function()
	{
		if ($(this).hasClass('active') == false && $(this).hasClass('parent-active') == false)
		{
			$(this).removeClass('current');
			$(this).children('ul').slideUp('fast');
		}
	});
*/	
	// Haku label
	var hakulabel = $('label#search_label').html();
	$('label#search_label').hide();
	$('input#keywords').val(hakulabel);
	$('input#keywords').focus(function()
	{
		if ($(this).val() == hakulabel)
		{$(this).val('');}
	});
	
	$('input#keywords').blur(function()
	{
		if ($(this).val() == '' || $(this).val() == ' ')
		{$(this).val(hakulabel);}
	});
	
	// Form validation
	$("form.esitetilaus").validate(
	{
		errorElement: "span",
		rules:
		{
			name: { required: true, minlength: 3 },
			street: { required: true, minlength: 5 },
			postalcode: { required: true, minlength: 5 },
			city: { required: true, minlength: 2 }
		},
		messages:
		{
			name: " puuttuu",
			street: " puuttuu",
			postalcode: " puuttuu",
			city: " puuttuu"
		},
		errorPlacement: function(error, element)
		{
			error.appendTo( element.prev() );
		}
	});
	
	// Form validation
	$("form.tarjouspyynto").validate(
	{
		errorElement: "span",
		rules:
		{
			name: { required: true, minlength: 3 },
			phone: { required: true, minlength: 3 },
			email: { required: true, email: true },
			quote: { required: true, minlength: 10 }
		},
		messages:
		{
			name: " puuttuu",
			phone: " puuttuu",
			email: { required: " puuttuu", email: " on virheellinen" },
			quote: " puuttuu"
		},
		errorPlacement: function(error, element)
		{
			error.appendTo( element.prev() );
		}
	});
	
	// Form validation
	$("form.dwg").validate(
	{
		errorElement: "span",
		rules:
		{
			name: { required: true, minlength: 3 },
			email: { required: true, email: true },
			dwg: { required: true, minlength: 2 }
		},
		messages:
		{
			name: " puuttuu",
			email: { required: " puuttuu", email: " on virheellinen" },
			dwg: " Ilmoita tuotteen nimi tai tuotenumero."
		},
		errorPlacement: function(error, element)
		{
			error.appendTo( element.prev() );
		}
	});
});
