$(document).ready(function() {
	// Figure out the location based on the browser URL
	var path = location.href;
	var referer = document.referrer;
	//alert("path: "+path+" referrer: "+referer);
	path_t = path.split("?");
	var p = path_t.length;
	//alert(p);
	if (p == 1 || p == 0) {
		path2 = '?path=news';
	}
	else {
		path = '?'+path_t[1];
	
		path_tt = path.split("&");
		path_t = path_tt[0];
		//alert(path_t);
		//if (path_t == '?path=news') {
			path2 = path_t;
			//alert(path);
		//}
		var pp = path_tt.length;	
	
		if (path2 == '?path=notes' && pp < 2) {
			path = '?path=notes&elem=career';
		}
		else if (path2 == '?path=orders' && pp < 2) {
			path = '?path=orders&elem=magazine';
		}
		else if (path2 == '?path=media' && pp < 2) {
			path = '?path=media&elem=7';
		}
		else if (path2 == '?path=contact' && pp < 2) {
			path = '?path=contact&elem=18';
		}
		else if (path2 == '?path=events' && pp < 2) {
			path = '?path=events&elem=agievent';
		}
		else if (path2 == '?path=pages') {
			path2 = path;	
		}
	}
	//alert(path);
	var index = "";
	var nav = $('#nav a[@href$="' + path2 + '"]');
	
	
	
	
		if (path2 != '?path=orders') {
			$('#navi_orders ul').hide();
		}
		else if (pp > 1 || path2 == '?path=orders') {
			var nav_sub = $('#nav a[@href$="' + path + '"]');
			nav_sub.addClass('sub_active');
		}
		if (path2 != '?path=events') {
			$('#navi_tapahtumat ul').hide();
		}
		else if (pp > 1 || path2 == '?path=events') {
			var nav_sub = $('#nav a[@href$="' + path + '"]');
			nav_sub.addClass('sub_active');
		}
		if (path2 != '?path=notes') {
			$('#navi_notes ul').hide();
		}
		else if (pp > 1 || path2 == '?path=notes') {
			var nav_sub = $('#nav a[@href$="' + path + '"]');
			nav_sub.addClass('sub_active');
		}
		
		if (path2 != '?path=media') {
			$('#navi_media ul').hide();
		}
		else if (pp > 1 || path2 == '?path=media') {
			var nav_sub = $('#nav a[@href$="' + path + '"]');
			nav_sub.addClass('sub_active');
		}
		if (path2 != '?path=contact') {
			$('#navi_contact ul').hide();
		}
		else if (pp > 1 || path2 == '?path=contact') {
			var nav_sub = $('#nav a[@href$="' + path + '"]');
			nav_sub.addClass('sub_active');
		}
	
		if (path2 != '?path=news') {
			$('#navi_news ul').hide();
		}
		else if (pp > 1) {
			
			if (pp == 3) {
				
				path = path_tt[0]+'&'+path_tt[1];
				var nav_sub = $('#nav a[@href$="' + path + '"]');
				nav_sub.addClass('sub_active');
			}
			else {
				var nav_sub = $('#nav a[@href$="' + path + '"]');
				nav_sub.addClass('sub_active');
			}
		}
	// Hide all subnavigation
	
	//$('#nav li ul').hide();

	// Check the home link against the path and set the navigation accordingly. 
	//if (path != index) {
		
	// Add the active class to the current path and activate it's subnavigation
	nav.addClass('active').siblings("ul").slideDown("slow");
	// If the active class has subnavigation, show it
	nav.parents("ul").show();
	
	//}
	/*
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/
});