jQuery.noConflict();

jQuery(document).ready(function($)
{
	// Rekrylomake
	$('.ujs_toggle_target').each(function()
	{
		$(this).click(function(e)
		{
			$($(this).attr('href')).toggle();
			if ($($(this)).children().attr('src') == 'http://www.nsgroup.fi/images/icon_plus.png') { $($(this)).children().attr('src', 'http://www.nsgroup.fi/images/icon_minus.png'); }
			else { $($(this)).children().attr('src', 'http://www.nsgroup.fi/images/icon_plus.png'); }
			e.preventDefault();
		});
	});
	
	// Validation
	$("form.tyonhaku").validate(
	{
		errorElement: "span",
		meta: "validate",
		rules:
		{
			tyonhaku_nimi: "required",
			tyonhaku_puhelinnumero: "required",
			tyonhaku_syntymaaika: "required",
			tyonhaku_aidinkieli: "required",
			kielitaito_englanti: "required",
			kielitaito_ruotsi: "required",
			//kielitaito_muu: { required: function(element) { return $("input#tyonhaku_kielitaito_muu").val() != ''; } },
			tyonhaku_voisin_aloittaa: "required"
		},
		errorPlacement: function(error, element)
		{
			error.appendTo( element.prev() );
		}
	});
	
	// Tabbed box navigation
	$('ul.ui-tabs-nav').tabs(); // http://jqueryfordesigners.com/demo/coda-slider.html
	
	// Hide content
	$('.ujs_hide').hide();
	
	// Stripe
	$('.ujs_stripe li:nth-child(even)').addClass('even');
	$('.ujs_stripe tbody tr:nth-child(odd)').addClass('odd');
	
	// Hover
	$('.ujs_hover li').hover( function() {$(this).addClass('selected');}, function() {$(this).removeClass('selected');} );
	
	// Table sorter
	$("table#avoimet_tyopaikat").tablesorter(
	{
		headers:
		{
			3: { sorter: false }, // Haku paattyy
			4: { sorter: false } // Lisatiedot
		},
		widgets: ['zebra']
	});
	
	$("table#avoimet_tyopaikat").addClass('tablesorter');
	
	// Links within page - animated scrolling
	// http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
	$('p a[href*=#]').each(function()
	{
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') )
		{
			var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
			var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target)
			{
				var targetOffset = $target.offset().top;
				$(this).click(function()
				{
					$('html, body').animate({scrollTop: targetOffset}, 200);
					return false;
				});
			}
		}
	});
});
