/* Palvelukohtaisia funktioita *//* tähän tiedostoon palvelukohtaisia scriptejä */


/* huone-esittely popup*/
var huoneIkkuna = null;
function avaahuone(url)
{
  if (huoneIkkuna) huoneIkkuna.close();
  huoneIkkuna = window.open(url,'Vanajanlinna','width=520,height=440');
  
}

/* kuvagalleria-popup*/
var galleriaIkkuna = null;
function avaakuva(url)
{
  if (galleriaIkkuna) galleriaIkkuna.close();
  galleriaIkkuna = window.open(url,'Vanajanlinna','width=520,height=440');
  
}


/* kv-kuvagalleria-popup*/
var galleryIkkuna = null;
function avaagallery(url)
{
  if (galleryIkkuna) galleryIkkuna.close();
  galleryIkkuna = window.open(url,'Vanajanlinna','width=620,height=540');
  
}

/* koskenparras-kuvat*/
var kuvaPopup = null;
function avaakp(url)
{
  if (kuvaPopup) kuvaPopup.close();
  kuvaPopup = window.open(url,'Koskenparras','width=521,height=493');
  
}

/* englannin huonekuva pop up */
var kuvaPopup = null;
function avaaEn(url)
{
  if (kuvaPopup) kuvaPopup.close();
  kuvaEn = window.open(url,'englanti','width=521,height=493');

}

/* Metsänvartijatila-kuvat*/
var kuvaPopup = null;
function avaamvt(url)
{
  if (kuvaPopup) kuvaPopup.close();
  kuvaPopup = window.open(url,'metsanvartija_tila','width=519,height=492');
  
}

function gotoAndPlay(frameLabel)
{
  
   var frames = [];
   
   frames["VL-alku"] = 119;
   frames["KP"] = 350;
   frames["MVT"] = 339;
   
   if ((mc = window.document.flash))
   {
      mc.GotoFrame(frames[frameLabel]);
      mc.Play();
      return false;
   }

   return true;
}

/* panoraama */
 function openURLShow(name,url,width,height,toolbar,location,
                     directories,status,menubar,scrollbars,
                     resizable,copyhistory){
  cad ="toolbar="+toolbar +","
  cad+="location="+location+","
  cad+="directories="+directories+","
  cad+="status="+status+","
  cad+="menubar="+menubar+","
  cad+="scrollbars="+scrollbars+","
  cad+="scrollbars="+scrollbars+","
  cad+="resizable="+resizable+","
  cad+="copyhistory="+copyhistory+","
  cad+="width="+width+","
  cad+="height="+height
  window.open(url,name,cad)
}

/* ohjelmapalvelut sivu */

vaihda = vaihdateksti = function (id)
   {
      var edel = document.getElementById("edellinen").innerHTML;
      if (edel != "") document.getElementById(edel).style.display= 'none';
      document.getElementById("edellinen").innerHTML = id;
      var obj = document.getElementById(id)
       if (obj.style.display == 'inline')  obj.style.display = 'none';
       else obj.style.display = 'inline';
   } 
 
 
/* DHTML - valilkko */    
document.menus = [];

function Menu (root_id) {
  this.root = document.getElementById(root_id);
  this.setup(this.root);
  
  configureFlashes();
}

var depth = 1;

Menu.prototype.setup = function (r) {
  var c = r.childNodes;

  for (var i = 0; i < c.length; i++) {
    if (c[i].tagName == "A" && c[i].parentNode.tagName == "LI") {
    	
      var ancestor = c[i].parentNode.parentNode;
      //if(ancestor.tagName == 'UL' && ancestor.className == 'dhtmlActive') {
        c[i].onmouseover = mMouOvrItm;
        c[i].onmouseout = mMouOutItm;
        c[i].getParents = mGetParents;
      //}
      
      var pli = c[i].parentNode; 
      for (var j = 0; j < pli.childNodes.length; j++) {
        if (pli.childNodes[j].tagName == "UL") {
        	
          if(pli.childNodes[j].className == 'dhtmlActive') {
            c[i].m = pli.childNodes[j];
            c[i].m.p = c[i];
            c[i].m.style.visibility = "hidden";
            c[i].m.onmouseover = mMouOvrMnu;
            c[i].m.onmouseout = mMouOutMnu;
            c[i].ptr = document.menus.length;

            c[i].hide = mHide;
            document.menus.push(c[i]);
            break;
		  }
		  
        }
      }
    }
    this.setup( c[i] );
  }
}

function mMouOvrItm() {
  if (this.parentNode.className) {  
    this.parentNode.classNameOrig = this.parentNode.className;
    }
  
    if (this.tOut) clearTimeout(this.tOut);

    var p = this.getParents();

    for (var i = 0; i < document.menus.length; i++) {
      var h = true;
      for (var j = 0; j < p.length; j++)
      	if (p[j] == document.menus[i].m) h = false;
      if (h) document.menus[i].hide();
    }

    if (this.m) { 
      this.m.style.visibility = "visible";
      swfHide();
     }
}

function mMouOutItm() {
  
  if (this.parentNode.classNameOrig) {
    this.parentNode.className = this.parentNode.classNameOrig;
    this.parentNode.classNameOrig = null;
  }
  if (this.m)
    this.tOut = setTimeout("document.menus["+this.ptr+"].hide()",700);
}

function mMouOvrMnu() {
  if (this.p.tOut) clearTimeout(this.p.tOut);
}

function mMouOutMnu() {
  this.p.onmouseout();
}

function mHide(p) {
  this.m.style.visibility = "hidden";
  if (document.swfOn) clearTimeout(document.swfOn);
  document.swfOn = setTimeout("swfShow()",2000);
}

function mGetParents() {
  var a = [];
  var p = this.parentNode;
  while (p) {
     if (p.tagName=='UL')
     	a.push(p);
     p = p.parentNode;
  }
  return a;
}

// ei käytössä, ks. configureFlashes()
function swfShow() {
 /* var swfs = document.getElementsByTagName('object');
  for(var i = 0; i < swfs.length; i++) {
    swfs[i].style.zIndex = "1";
  }
  */
}
// ei käytössä, ks. configureFlashes()
function swfHide() {
  /*
  if (document.swfOn) clearTimeout(document.swfOn)
  var swfs = document.getElementsByTagName('object');
  for(var i = 0; i < swfs.length; i++) {
    swfs[i].style.zIndex = "-1";
  }
  */
}

/* flashien konfiguroija (DHTML-valikkoa varten) 
 * 
 * asettaa sivun flasheille: 
 *   <param name="wmode" value="opaque">
 *   <embed ...... wmode="opaque">
 */
function configureFlashes()
{  
	var objects = document.getElementsByTagName("object");
	
	if(navigator.appName.indexOf("Microsoft Internet Explorer") == -1 && navigator.appName.indexOf("Opera") == -1)
	{
		for(var i = 0, len = objects.length; i < len; i++) 
		{	
			if(objects[i].id == 'musicPlayer')
			{
				continue;
			}

			var children = objects[i].childNodes;
		
			for(var j = 0, len2 = children.length; j < len2; j++)
			{
				if(children[j].tagName == "EMBED")
				{
					children[j].setAttribute("wmode", "opaque");
				}
			}
	
			var wmodeParam = document.createElement("param");
			wmodeParam.setAttribute("name", "wmode");
			wmodeParam.setAttribute("value", "opaque");

			objects[i].appendChild(wmodeParam);
		}
	}
	else // IE...
	{
		for(var i = 0, len = objects.length; i < len; i++)
		{
			if(objects[i].id == 'musicPlayer')
			{
				continue;
			}

			var inner = objects[i].innerHTML;
			
			var beginEmbed = inner.indexOf("<EMBED");
			var endEmbed = inner.indexOf("</EMBED>");
			
			var embedIsWithoutEndTag = false;
			
			if(beginEmbed == -1)
			{
				beginEmbed = inner.indexOf("<embed");
			}
			
			if(endEmbed == -1)
			{
				endEmbed = inner.indexOf("</embed>");
			}
			if(endEmbed == -1)
			{
				var tmpEmbed = inner.substring(beginEmbed, inner.length);
				endEmbed = tmpEmbed.indexOf(">") + beginEmbed + 1;
				embedIsWithoutEndTag = true;
			}
			else
			{
				endEmbed += 7;
			}
			
			var embed = inner.substring(beginEmbed, endEmbed);

			embed = embed.substring(0, 6) + " wmode=\"opaque\"" + embed.substring(6, embed.length);

			var newInner = inner.substring(0, beginEmbed) + inner.substring(endEmbed, inner.length);
			newInner = newInner.replace("NAME=\"WMode\" VALUE=\"Window\"", "NAME=\"WMode\" VALUE=\"Opaque\"");
			newInner = newInner.replace("name=\"wmode\" value=\"window\"", "NAME=\"WMoode\" VALUE=\"Opaque\"");
			
			if(embedIsWithoutEndTag)
			{
				newInner.replace("</EMBED>", "");
			}
			
			var objectAttributes = objects[i].attributes;
			var attributeString = "";
			
			for(var j = 0, len2 = objectAttributes.length; j < len2; j++)
			{
				if(objectAttributes[j].value != null && objectAttributes[j].value != "null" && objectAttributes[j].value != "")
				{
					attributeString += " " + objectAttributes[j].name + "=\"" + objectAttributes[j].value + "\"";
				}
			}
	
			var div_ = document.createElement("div");
			div_.innerHTML = "<object" + attributeString + "> " + newInner + embed + "</object>";

			var p = objects[i].parentNode;
			p.removeChild(objects[i]);
			p.appendChild(div_);
		}
	}
}


