﻿
var speed = 1; //how often the div refreshes to the new height
var incriment = 100;

var iTimer;
var calcHeight;
function toggleDiv(divToShow, imgID)
{
// jos on tumma tausta

	var ExpandImageSrc = '/img/dark_plus.gif'; //image location to display when Div is collapsed
	var CollapseImageSrc = '/img/dark_minus.gif'; //image location to display when Div is Expanded

	var help = document.getElementById(divToShow);
	if(help.style.display != "block") {
		if(imgID){
			document.getElementById(imgID).setAttribute('src',CollapseImageSrc);
		}
		showDiv(divToShow);
		Expand(divToShow);
		sIFR.rollback("h1._rus");
		sIFR.replaceElement("h1._rus", named({sFlashSrc:"sifr/ArnoPro.swf", sColor:"#2e2e2e", sBgColor:"#EEEEEE", nPaddingTop:0, nPaddingBottom:0, sWmode:"transparent", sFlashVars:"textalign=left"}));
	}
	else {
		if(imgID){
			document.getElementById(imgID).setAttribute('src',ExpandImageSrc);
		}
		collapse(divToShow);
	}
}

function Expand(divName) 
{
	var help = document.getElementById(divName);		
	var height = help.offsetHeight;
	if(height < calcHeight){
		help.style.height = height + incriment + "px";
		iTimer = setTimeout( "Expand('" + divName +"')" , speed);
	}
	else{
		clearTimeout(iTimer);
	}	
}		
function collapse(divName) 
{
	var help = document.getElementById(divName);		
	var height = help.offsetHeight;
	if(height > incriment){
		help.style.height = height - incriment + "px";
		iTimer = setTimeout( "collapse('" + divName +"')" , speed);
	}
	else{
		clearTimeout(iTimer);
		help.style.height ="100%";
		help.style.display = "none";
	}	
}		
function showDiv(divName)
{
	var div = document.getElementById(divName);
	div.style.display = "block";
	calcHeight = div.offsetHeight;
	div.style.height = "0px";
}

function swapBgColor(id)
{
	var originalColor = '#f2f2f2';
	
	if(document.getElementById(id).style.backgroundColor == originalColor || document.getElementById(id).style.backgroundColor == '')
		document.getElementById(id).style.backgroundColor = '#dbdbdb';
	else
		document.getElementById(id).style.backgroundColor = '';
	
}
