function showPricelist(list) {
	dojo.byId("pricelist").innerHTML = "\n\t<img src=\"/mad/tiedostot/kuvat/ajax-loader.gif\" alt=\"Loading..\" />\n";
	dojo.xhrGet( {
		url: "http://www.mad.fi/mad/pricelist.php", 
		load: function(response, ioArgs) {
			toggle_menu('sm_products');

			switch(list) {
				case "Software":
					select_submenu('a_products', '', '<a id="selected" onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Libraries":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a id="selected" onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Add-Ons":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a id="selected" onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Updates":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a id="selected" onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Work":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a id="selected" onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Training":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a id="selected" onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Club":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a id="selected" onclick="showPricelist(\'Club\');">Club</a>  |  <a onclick="showPricelist(\'Books\');">Books</a>');
					break;
				case "Books":
					select_submenu('a_products', '', '<a onclick="showPricelist(\'Software\');">Software</a>  |  <a onclick="showPricelist(\'Libraries\');">Libraries</a>  |  <a onclick="showPricelist(\'Add-Ons\');">Add-Ons</a>  |  <a onclick="showPricelist(\'Updates\');">Updates</a>  |  <a onclick="showPricelist(\'Work\');">Work</a>  |  <a onclick="showPricelist(\'Training\');">Training</a>  |  <a onclick="showPricelist(\'Club\');">Club</a>  |  <a id="selected" onclick="showPricelist(\'Books\');">Books</a>');
					break;
			}

			dojo.byId("pricelist").innerHTML = response;
			return response;
		},
		error: function(response, ioArgs) {
			console.error("HTTP status code: ", ioArgs.xhr.status);
			dojo.byId("pricelist").innerHTML = "";
			return response;
		},
		content: {list: list }
	});
}

function init_menus()
{
	collapse_menus();

	var page = document.location.toString();

	if(page.indexOf('sitemap_new.html') > -1)
	{
		collapse_menus();
	}

	if(page.indexOf('englishmad.html') > -1)
	{
		toggle_menu('sm_home');
	}

	if(page.indexOf('events.html') > -1)
	{
		toggle_menu('sm_home');
		select_submenu('a_home', 'sma_events', '');
	}

	if(page.indexOf('madenglish.html') > -1)
	{
		toggle_menu('sm_madenglish');
	}

	if(page.indexOf('employees.html') > -1)
	{
		toggle_menu('sm_madenglish');
		select_submenu('a_madenglish', 'sma_employees', '');
	}

	if(page.indexOf('products.html') > -1)
	{
		toggle_menu('sm_products');
	}

	if(page.indexOf('logs.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', 'sma_logs', '');
		//select_submenu('a_products', 'sma_logs', '<a href="/mad/logs-video.html">Video</a> | <a href="/mad/logs-downloads.html">Downloads</a>');
	}

	/*if(page.indexOf('logs-video.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', '', '<a id="selected" href="/mad/logs-video.html">Video</a> | <a href="/mad/logs-downloads.html">Downloads</a>');
	}

	if(page.indexOf('logs-downloads.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', '', '<a href="/mad/logs-video.html">Video</a> | <a id="selected" href="/mad/logs-downloads.html">Downloads</a>');
	}*/

	if(page.indexOf('englishdoublecheck2.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', 'sma_englishdoublecheck', '');
	}

	if(page.indexOf('englishzonematic.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', 'sma_englishzonematic', '');
	}

	if(page.indexOf('englishmuutoskone.html') > -1)
	{
		toggle_menu('sm_products');
		select_submenu('a_products', 'sma_englishmuutoskone', '');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html')
	{
		showPricelist('Software');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Software')
	{
		showPricelist('Software');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Libraries')
	{
		showPricelist('Libraries');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Add-Ons')
	{
		showPricelist('Add');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Updates')
	{
		showPricelist('Updates');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Work')
	{
		showPricelist('Work');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Training')
	{
		showPricelist('Training');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Club')
	{
		showPricelist('Club');
	}

	if(page == 'http://www.mad.fi/mad/pricelist.html?list=Books')
	{
		showPricelist('Books');
	}

	if(page.indexOf('training.html') > -1)
	{
		toggle_menu('sm_training');
	}

	if(page.indexOf('trainingschedule.html') > -1)
	{
		toggle_menu('sm_training');
		select_submenu('a_training', 'sma_trainingschedule', '');
	}

	if(page.indexOf('/mad/kirjastot/ruukki/index_en.html') > -1)
	{
		toggle_menu('sm_gdl');
		select_submenu('a_gdl', 'sma_ruukki', '');
	}

	if(page.indexOf('links.html') > -1)
	{
		toggle_menu('sm_links');
	}
}

function toggle_menu(menu)
{
		collapse_menus();

		switch(menu)
		{
			case 'sm_home':
				document.getElementById('a_home').style.border = 'none';
				document.getElementById('a_home').style.background = '#0088ff';
				document.getElementById('a_home').style.color = '#ffffff';
				document.getElementById('sm_home').style.display = 'block';
				break;
			case 'sm_madenglish':
				document.getElementById('a_home').style.border = 'none';
				document.getElementById('a_madenglish').style.background = '#0088ff';
				document.getElementById('a_madenglish').style.color = '#ffffff';
				document.getElementById('a_madenglish').style.border = 'none';
				document.getElementById('sm_madenglish').style.display = 'block';
				break;
			case 'sm_products':
				document.getElementById('a_madenglish').style.border = 'none';
				document.getElementById('a_products').style.background = '#0088ff';
				document.getElementById('a_products').style.color = '#ffffff';
				document.getElementById('a_products').style.border = 'none';
				document.getElementById('sm_products').style.display = 'block';
				break;
			case 'sm_training':
				document.getElementById('a_products').style.border = 'none';
				document.getElementById('a_training').style.background = '#0088ff';
				document.getElementById('a_training').style.color = '#ffffff';
				document.getElementById('a_training').style.border = 'none';
				document.getElementById('sm_training').style.display = 'block';
				break;
			case 'sm_gdl':
				document.getElementById('a_training').style.border = 'none';
				document.getElementById('a_gdl').style.background = '#0088ff';
				document.getElementById('a_gdl').style.color = '#ffffff';
				document.getElementById('a_gdl').style.border = 'none';
				document.getElementById('sm_gdl').style.display = 'block';
				break;
			case 'sm_links':
				document.getElementById('a_training').style.border = 'none';
				document.getElementById('a_links').style.border = 'none';
				document.getElementById('sm_links').style.display = 'block';
				break;
		}
}

function collapse_menus()
{
	document.getElementById('a_home').style.background = '#ffffff';
	document.getElementById('a_madenglish').style.background = '#ffffff';
	document.getElementById('a_products').style.background = '#ffffff';
	document.getElementById('a_training').style.background = '#ffffff';
	document.getElementById('a_gdl').style.background = '#ffffff';
	document.getElementById('a_links').style.background = '#ffffff';

	document.getElementById('a_home').style.color = '#000000';
	document.getElementById('a_madenglish').style.color = '#000000';
	document.getElementById('a_products').style.color = '#000000';
	document.getElementById('a_training').style.color = '#000000';
	document.getElementById('a_gdl').style.color = '#000000';
	document.getElementById('a_links').style.color = '#000000';

	document.getElementById('a_home').style.borderBottom = '1px solid #e4e4e4';
	document.getElementById('a_madenglish').style.borderBottom = '1px solid #e4e4e4';
	document.getElementById('a_products').style.borderBottom = '1px solid #e4e4e4';
	document.getElementById('a_training').style.borderBottom = '1px solid #e4e4e4';
	document.getElementById('a_gdl').style.borderBottom = '1px solid #e4e4e4';
	document.getElementById('a_links').style.borderBottom = '1px solid #e4e4e4';

	document.getElementById('sm_home').style.display = 'none';
	document.getElementById('sm_madenglish').style.display = 'none';
	document.getElementById('sm_products').style.display = 'none';
	document.getElementById('sm_training').style.display = 'none';
	document.getElementById('sm_gdl').style.display = 'none';
	document.getElementById('sm_links').style.display = 'none';
}

function select_submenu(menu_id, submenu_id, links)
{
	if(menu_id != '')
	{
		var menu = document.getElementById(menu_id);
		menu.style.background = '#ffffff';
		menu.style.color = '#000000';
		menu.style.borderTop = '1px solid #e4e4e4';
	}

	if(submenu_id != '')
	{
		var submenu = document.getElementById(submenu_id);
		submenu.style.background = '#0088ff';
		submenu.style.color = '#ffffff';
		submenu.style.textDecoration = 'none';
	}

	if(links != '')
	{
		document.getElementById('submenu2').innerHTML = links;
		document.getElementsByTagName('h1')[0].style.marginBottom = '30px';
	}
	
	document.getElementById('submenu2').style.display = 'block';
}