/*
function parsi_tyyppi(tulos)
 {
 url = location.href;
  if(url.match(tulos+"=.*"))
  tulos = url.match(tulos+"=.*")[0].split("=");
  else
  return false;
 return true;
}
if(parsi_tyyppi("testiurlit"))
{
*/
if(location.href.match(/helsinki.fi\/bin/i))
{
}
else
{
var loadmethod = "ye_old"; /* ye_olde = synkronisesti kaistaa haaskaten */
var abortx = "n";


//osoite-ehdot, matchiin osuvat ovat sisaisia linkkeja
function dmatch(urlx)
{
	if (urlx.match(/kansalliskirjasto.fi|nationallibrary.fi|nationalbiblioteket.fi|javascript|mailto:|helsinki.fi\/fi\/materiaalipankki|test.it.hels|lib.helsinki.fi|helsinki.fi\/bin/i))
	{
	return false;
	}
	else
	{
	return true;
	}
}

//palvelusivupohjat
palv = document.getElementsByTagName("LINK");
debug = "";
poffset = 0;
poffset2 = 0;
var iecheck = 0;
	for (i = 0; palv.length > i; i++)
	{
		if(palv[i].href.match(/css\/kk\/kanava_/i))
		{
		
		i = palv.length;
		poffset = 1;
		}
	}



//leivanmurupolku
var ajax = 0;
var ajaxcrumb = "on"; // aseta "off" jos haluat keventää..
var etusivu = "Etusivu";
xx = document.getElementsByName("DC.Title");
var tsup2 = "empty";
test2 = document.getElementsByTagName("div");
for (x = 0; test2.length > x; x++)
{
	if(!test2[x].id && test2[x].parentNode.id == "navigation_block" && location.pathname.match(/teksti\/index/) == null) 
	{
	//var tsup = test2[x-1].childNodes[0].innerHTML;
	var tsup = test2[x-1].innerHTML;	
		
		for(z = 0; test2[x].childNodes.length > z; z++)
		{
			if(test2[x].childNodes[z].tagName == "UL")
			{
				for(g = 0; test2[x].childNodes[z].childNodes.length > g; g++)
				{
				if(test2[x].childNodes[z].childNodes[g].tagName == "LI")
				{
					if(test2[x].childNodes[z].childNodes[g].firstChild.firstChild == null)
					{
					tsup2=test2[x].childNodes[z].childNodes[g].innerHTML;
					}
				//alert(test2[x].childNodes[z].childNodes[g].firstChild.tagName);
				}
				  if(test2[x].childNodes[z].childNodes[g].tagName == "UL")
				 {
				 //firefox
				 //tsup2 = test2[x].childNodes[z].childNodes[g].previousSibling.previousSibling.firstChild.innerHTML;
				 tsup2 = test2[x].childNodes[z].childNodes[g].previousSibling.previousSibling.innerHTML;
				 	
				 	if(poffset == "1") //palvelupohjat ff
				 	{
				 	iecheck = 1;
				 	//alert(tsup2);
				 	//debug = "x"+test2[x].childNodes[z].childNodes[g].childNodes[1].innerHTML;
				 	//alert(test2[x].childNodes[z].childNodes[g].childNodes[g].previousSibling.previousSibling.innerHTML);
				 		for(p = 0; test2[x].childNodes[z].childNodes[g].childNodes.length > p; p++)
				 		{
				 			//alert(test2[x].childNodes[z].childNodes[g].childNodes[p].innerHTML);
				 			if(test2[x].childNodes[z].childNodes[g].childNodes[p].tagName == "UL")
				 			{
				 			
				 				if(test2[x].childNodes[z].childNodes[g].childNodes[p].previousSibling.previousSibling.firstChild.tagName == "A" && location.pathname.split("/").length == 6)
				 				{
				 				debug2 = test2[x].childNodes[z].childNodes[g].childNodes[p].previousSibling.previousSibling.innerHTML;
				 				tsup2 += " > " + debug2;
				 				//debug = test2[x].childNodes[z].childNodes[g].childNodes[p].previousSibling.previousSibling.firstChild.tagName;
				 				//debug = test2[x].childNodes[z].childNodes[g].childNodes[p].lastChild;
				 				
				 				}
				 			}
				 		}
				 	}
				 }
				
				 if(test2[x].childNodes[z].childNodes[g].innerHTML && iecheck == 0)
				 {
				 //ie
				 	if(test2[x].childNodes[z].childNodes[g].innerHTML.match(/UL class/i))
				 	{
				 	tsup3 = test2[x].childNodes[z].childNodes[g].firstChild.innerHTML;
				 	//tsup2 = test2[x].childNodes[z].childNodes[g].firstChild.innerHTML;
				 	tsup2 = "<a href='"+test2[x].childNodes[z].childNodes[g].firstChild.href+"'>"+test2[x].childNodes[z].childNodes[g].firstChild.innerHTML+"</a>";
				 		if(!tsup3)
				 		{
				 		tsup2 = xx[0].content;
				 		}
				 		else
				 		{
				 		}
				 		if(poffset == "1")
				 		{
				 		
				 			for(pp = 0; test2[x].childNodes[z].childNodes[g].childNodes.length > pp; pp++)
				 			{
				 				if(test2[x].childNodes[z].childNodes[g].childNodes[pp].innerHTML)
				 					if(test2[x].childNodes[z].childNodes[g].childNodes[pp].innerHTML.match(/UL class/i))
				 					{
				 					//debug = test2[x].childNodes[z].childNodes[g].childNodes[pp].innerHTML;
				 					//alert(test2[x].childNodes[z].childNodes[g].childNodes[pp].innerHTML);
				 						for(pb = 0; test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes.length > pb; pb++)
				 						{
				 							if(test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes[pb].innerHTML)
				 							{
				 								if(test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes[pb].innerHTML.match(/UL class/i))
				 								{
				 									if(location.pathname.split("/").length == 6)
				 									{
				 									//alert(test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes[pb].firstChild.innerHTML);
				 									//alert(tsup2);
				 									tsup2 += " > " + "<a href='"+ test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes[pb].firstChild.href + "'>" + test2[x].childNodes[z].childNodes[g].childNodes[pp].childNodes[pb].firstChild.innerHTML + "</a>";
				 									}
				 									
				 									
				 								}
				 								
				 							}
				 						
				 						}
				 					}
				 			}
				 		}
				 	}
				 }


				}
			//tsup2 = z + test2[x].childNodes[1].childNodes[z-2].innerHTML;
			//alert(tsup2);
			//z = test2[x].childNodes[1].childNodes.length;
			//alert("osui"+z+test2[x].childNodes[z].className);
			}
		}

	}
}

vika = document.getElementsByTagName("li");

	for(z = 0; vika.length > z; z++)
	{
		if(vika[z].getAttribute("class") == "nav_selected_sub" || vika[z].getAttribute("className") == "nav_selected_sub")
		{
		var lisataan = "eix";
		}

	}

	//jos ja kun, niin kovin harvoin, tehdaan ajaxilla
	function loadXMLDoc(url) 
	{

		if (navigator.userAgent.match("Mozilla/4.0") != null)
		{
		//ei ajax kutsuja ie:lle toistaseksi
		abortx = "y";
		return;
		}
		else
		{
		}

		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  	
 		}


		if(loadmethod == "ye_olde")
		{
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		//document.getElementById('test').innerHTML=xmlhttp.responseText;

			if(xmlhttp.status != "404")
			{
			var tmp = xmlhttp.responseText;
			/*alert(tmp.length + tmp.replace(/\n|\t/gi,""))*/
			/*alert(tmp.length / 1024 + " KiloBytes"+"\n"+"56K modeemilla (keskim. 4kt/s) latautuu: "+tmp.length / 1024 / 4 +" sekuntia"
			+"\n"+"Hitaimmalla ADSL-nopeudella (25kt/s) latautuu: "+tmp.length / 1024 / 25 +" sekuntia");*/
			var x = tmp.match(/<meta name="DC.Title" content=".*/);
			var x = x[0].split('"');
			return x[3];
			}
		}

		else
		{
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
			
		xmlhttp.onreadystatechange=function()
				{
				if(xmlhttp.readyState==3)
  				{
				
			
					if(xmlhttp.responseText.match(/<meta name="DC.Title" content=".*/)[0])
					{
			
					var tmp = xmlhttp.responseText;
					xmlhttp.abort();
			
					//alert(tmp.length + tmp.replace(/\n|\t/gi,""));
					/*alert(tmp.length / 1024 + " KiloBytes"+"\n"+"56K modeemilla (keskim. 4kt/s) latautuu: "+tmp.length / 1024 / 4 +" sekuntia"
					+"\n"+"Hitaimmalla ADSL-nopeudella (25kt/s) latautuu: "+tmp.length / 1024 / 25 +" sekuntia");*/

					var x = tmp.match(/<meta name="DC.Title" content=".*/);
					var x = x[0].split('"');
					document.getElementById("ajax").innerHTML = x[3];
					//alert(x[3]);	
			
					}
			
		
				
		
				}
		
				else
				{

					if(xmlhttp.readyState == 4 && xmlhttp.status == 404)
					{
					b = document.getElementById("bread");
					b.style.display="none";
					document.getElementById("main").removeChild(b);
					}
				}
		
	
			}
	
		}
	}

	


	if (location.pathname.split("/").length > 2+poffset && tsup2 == "empty" && ajaxcrumb == "on" && location.pathname.match(/teksti\/index/) == null) // tuotanntossa -1
	{
		
		
		
		if(location.pathname.split("/")[3+poffset] == null && location.pathname.split("/")[2+poffset])
		{
		getsivu = location.pathname.split("/")[1]+".html";
		var ajax = 1;
		}
		else
		{
			if(poffset == 1)
			{
			poffset2 = 1;
			}
		getsivu = location.pathname.split("/")[1+poffset-poffset2]+"/"+location.pathname.split("/")[2+poffset-poffset2]+".html";
		}


		if(loadmethod == "ye_olde")
		{
		tsup2= '<a href="/'+getsivu+'">'+loadXMLDoc(getsivu)+'</a>';
	
		}
		else
		{
			if(location.pathname.match(/tapahtumat|uutiset|ajankohtaista|sivukartta/) == null)
			{
				if(navigator.userAgent.match("Mozilla/4.0") == null)
				{				
				tsup2= '<a href="'+getsivu+'">'+'<span id="ajax">loading...</span>'+'</a>';
				loadXMLDoc(getsivu);
				}
				else
				{
					//mystiset ie-saadot
					if(poffset == 0 && location.pathname.split("/").length == 3 && location.href.match(/zyxxy/))
					{
					//alert(location.pathname.split("/").length);
					tsup2 = ".";
					}
					if(poffset == 1 && location.pathname.split("/").length == 4 && location.href.match(/zyxxy/))
					{
					tsup2 = ".";
					}
					if(poffset == 1 && location.pathname.split("/").length == 5 && location.href.match(/zyxxy/))
					{
					//tsup2 = ".";
					}
				}
				
			}
			else
			{
			/*tsup2 = xx[0].content;
			xx[0].content = "";*/		
			}
		}
	}


	
		


	if(lisataan != "ei" && tsup2 != "empty")
	{
	
		if(tsup2 == xx[0].content || tsup2 == xx[0].content+" ")
		{
		xx[0].content = "";
		}
		else
		{
			if(ajax == "1")
			{
			tsup2 = "";
			}
			else
			{
			tsup2 += " >";
			}
		}
	

		if(abortx == "n")
		{	
		pohja = document.getElementById("left_column");
		var eltsu = document.createElement("div");

			if(location.hostname == "www.kansalliskirjasto.fi")
			{
			etusivu = "Etusivu";
			}
			else if (location.hostname == "www.nationalbiblioteket.fi")
			{
			etusivu = "Förstasida";
			}
			else
			{
			etusivu = "Home";
			}

		/*katkaisu*/
		kokoteksti = tsup.replace(/<[^>]+>/ig,"").replace(/\t/ig,"").length + tsup2.replace(/<[^>]+>/ig,"").length + xx[0].content.length + etusivu.length;
			if(kokoteksti >= 90)
			{
			tmp = kokoteksti - xx[0].content.length;
			tmp2 = 89 - tmp;
			xx[0].content = xx[0].content.substr(0,tmp2);
			xx[0].content += "&hellip;";
			}
			else
			{
			}
			etusivu = etusivu.replace("ö","&ouml;");
			
		eltsu.innerHTML="<span id='bread'><a href='http://"+location.host+"'>"+etusivu+"</a> &gt; "+tsup + " &gt; "+tsup2+" " + xx[0].content + debug + "</span>";
		eltsu.style.color="gray";
		eltsu.style.fontSize="xx-small";
		eltsu.style.position="absolute";
		eltsu.style.left="250px";
		eltsu.style.top="100px";
		eltsu.style.height="20px";
		eltsu.style.width="510px";
		document.getElementById("main").insertBefore(eltsu,pohja)
		z=vika.length;
		}
	}

//end of
urlit = document.getElementsByTagName("a");
var ux;
for (x = 0; urlit.length > x; x++)
{
//document.write(urlit[x].href);
	if(urlit[x].href && urlit[x].innerHTML != " " && location.pathname != "/index.html" && urlit[x].parentNode.id != "nav_contact" && urlit[x].childNodes[0].tagName != "IMG" && urlit[x].childNodes[0].tagName != "DIV")
	{
		if(dmatch(urlit[x].href))
		{
		//urlit[x].style.color="#9799ff"
		//urlit[x].parentNode.style.listStyleImage="url(http://www.helsinki.fi/fi/imgs/link_external_small.gif)";
		urlit[x].innerHTML += "&raquo;";
			if(urlit[x].parentNode.parentNode.id == "left_column" && urlit[x].parentNode.id != "nav_contact")
			{
			//urlit[x].innerHTML +=" (" + urlit[x].href + ") ";
			}
		}
		if(urlit[x].getAttribute("target") == "_blank")
		{
			if(urlit[x].attachEvent )
			{
			urlit[x].onmouseover =  function(){this.style.borderBottom="1px solid";};
			urlit[x].onmouseout =  function(){this.style.borderBottom="none";};
			}
			else
			{			
			urlit[x].setAttribute("onmouseover", 'this.style.borderBottom="1px solid";');
			urlit[x].setAttribute("onmouseout", 'this.style.borderBottom="none";');
			//urlit[x].title="Linkki avautuu uuteen ikkunaan"
			}
		}
	}
}
}
//}
