sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function tableruler()
{
 if (document.getElementById && document.createTextNode)
  {
   var tables=document.getElementsByTagName('table');
   for (var i=0;i<tables.length;i++)
   {
    if(tables[i].className=='tekniset_ominaisuudet_taulu')
    {
     var trs=tables[i].getElementsByTagName('tr');
     for(var j=0;j<trs.length;j++)
     {
      if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT')
       {
       trs[j].onmouseover=function(){this.className='ruled';return false}
       trs[j].onmouseout=function(){this.className='testi';return false}
     }
    }
   }
  }
 }
}


function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&document.documentElement.clientHeight) {
      windowHeight=document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function getWindowWidth() {
  var windowWidth=0;
  if (typeof(window.innerWidth)=='number') {
    windowWidth=window.innerWidth;
  }
  else {
    if (document.documentElement&&document.documentElement.clientWidth) {
      windowWidth=document.documentElement.clientWidth;
    }
    else {
      if (document.body&&document.body.clientWidth) {
        windowWidth=document.body.clientWidth;
      }
    }
  }
  return windowWidth;
}

function setHeight() {
  if (document.getElementById) {
	var windowWidth=getWindowWidth();
	if (windowWidth>0) {
	  var masterDiv=document.getElementById('masterdiv');
	  var masterWidth=document.getElementById('footer').offsetWidth;
	  
      if (windowWidth < masterWidth) {
        masterDiv.style.left = '0px';
		masterDiv.style.marginLeft = '0px';
      } else {
		masterDiv.style.left = '50%';
		masterDiv.style.marginLeft = -507+'px';
	  }  
    } 	
  }
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function switchImage(src) {
	imagePreload = new Image(); 
	Element.show('loading');
	Element.hide('switchimage');
	imagePreload.onload = function() {
		dotheswitch(src);
	}
	imagePreload.src = src;
}

function dotheswitch(src) {
		widthCurrent = Element.getWidth('imagecontainer');
		heightCurrent = Element.getHeight('imagecontainer');
	
		var widthNew = imagePreload.width;
		var heightNew = imagePreload.height;
	
		xScale = ( widthNew / widthCurrent) * 100;
		yScale = ( heightNew / heightCurrent) * 100;
		// calculate size difference between new and old image, and resize if necessary
		wDiff = widthCurrent - widthNew;
		hDiff = heightCurrent - heightNew;
		
		if(!( hDiff == 0)){ new Effect.Scale('imagecontainer', yScale, {scaleX: false, duration: 0.5, queue: { position: 'end', scope: 'imgswitch', limit: 2}}); }
		if(!( wDiff == 0)){ new Effect.Scale('imagecontainer', xScale, {scaleY: false, duration: 0.5, queue: { position: 'end', scope: 'imgswitch', limit: 2}, afterFinish: function() {
		
		Element.hide('loading');
		$('switchimage').src = src;
		new Effect.Appear('switchimage', { duration: 1, queue: 'end'});
		}}); 
		} else {
			Element.hide('loading');
			$('switchimage').src = src;
			new Effect.Appear('switchimage', { duration: 1, queue: 'end'});
		}
}

window.onload = function() {
			setHeight();
			externalLinks();
			tableruler();
}
window.onresize = function() {
			setHeight();
}