$('document').ready(function(){

	/**
	* Front Career Tabs
	**/
	$("#frontCareerTabs li a").click(function() {
		if( !$(this).hasClass('current') ) {
			$('.tab').hide();
			$('#frontCareerTabs .tabNav li').removeClass('current prev');
			
			$(this).parent().addClass('current');
			var id = $(this).parent().attr('id').split('-');
			$("#frontCareerTabs .tab").eq(id[1]).show();
			if( id[1]!=0 ) {
				$("#frontCareerTabs .tabNav li").eq(id[1]-1).addClass('prev');
			}
		}
		return false;
	});
	

	/**
	* Top toolbar
	**/
	$(".tools li a.toggler").click(function() {
		if( !$(this).parent().hasClass('current') ) {
			$('.toolsContainer').hide();
			$('.tools li').removeClass('current');
			
			var c = $(this).parent().attr('class');
			$(this).parent().addClass('current');
			$('.toolsContainer.' + c ).show();
		}
		else {
			$('.toolsContainer').hide();
			$('.tools li').removeClass('current');
		}
		return false;
	});


	/**
	* Tabs
	**/
	$('.tabs.dynamic .tabsHeader a').click(function(){
		if( !$(this).hasClass('current') ) {
			var clickedTab = $(this).attr('class');

			$(this).parent().find('a').removeClass('current');
			$(this).addClass('current');	
			$(this).parent().parent().find('.tabsBody .tab').hide();
			$(this).parent().parent().find('.tabsBody .tab').removeClass('current');
			$(this).parent().parent().find('.tabsBody .tab.' + clickedTab).addClass('current');
			$(this).parent().parent().find('.tabsBody .tab.current').show();
		}
		else {
			//$(this).parent().find('a').removeClass('current');
		}
		return false;
	});


	/**
	* Custom dropdowns
	**/
	$('.dropdown select').change(function() {
		$(this).parent().find('.dropdownLabel').eq(0).html($(this).val());
	});

	$('#muutosMoottori .dropdown select#issueSelector').change(function() {
		window.location = $(this).val();
	});


	/**
	* Toggle sidebar login box visibility
	**/
	$('#toggle-login').click(function(){
		$('#user-login').toggle();
		
		if( $('.loginHeader a span').hasClass('close') ) {
			$('.loginHeader a span').removeClass('close');
			$('.loginHeader a span').addClass('open');
		}
		else if ( $('.loginHeader a span').hasClass('open') ) {
			$('.loginHeader a span').removeClass('open');
			$('.loginHeader a span').addClass('close');
		}
		
		return false;
	});

	/**
	* Sidebar search submit
	**/

	$('#mainsearchbutton').click(function(){

		$("#searchForm").submit();

	});
	
	/**
	* COMMENTS
	**/

	if(uriObject.queryKey.sent == 'true'){

		var message = '';
	
		if(ez_content_language == 'fi'){
	

			message += '<div class="systemMessage">';
			message += '<h3>Viestisi on lähetetty</h3>';
//			message += '<p>Kiitos kommentistasi.</p>';
			message += '</div>';

			$("#comments div.commentListBody").prepend(message);
			
		}
		
	}

	setTimeout(function(){
		$("div.systemMessage").slideDown("slow");
	},750);
	

	if(($('#commentInsert').find('#commentError')).length > 0) {
		window.location.hash="commentInsert";
	}

});







/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};


