function roundedCorners() {

 var rounded_elems = ['harmaaPyorTausta', 'sininenPyorTausta', 'oranssiPyorTausta', 'violettiPyorTausta', 'vihreaPyorTausta'];

 for (var j = 0; j < rounded_elems.length; j++) {
 var name = rounded_elems[j];
 var divs = document.getElementsByTagName('p');
 var divs2 = document.getElementsByTagName('span');
 var rounded_divs = [];
 /* First locate all divs with 'rounded' in their class attribute */
 for (var i = 0; i < divs.length; i++) {
   if (check(name, divs[i].className)) {
     rounded_divs[rounded_divs.length] = divs[i];
   }
 }
 for (var i = 0; i < divs2.length; i++) {
   if (check(name, divs2[i].className)) {
     rounded_divs[rounded_divs.length] = divs2[i];
   }
 }
 /* Now add additional divs to each of the divs we have found */
 for (var i = 0; i < rounded_divs.length; i++) {
   var original = rounded_divs[i];
   /* Make it the inner div of the four */
   original.className = original.className.replace(name, '');
   /* Now create the outer-most div */
   var tr = document.createElement('div');
   tr.className = name+'2';
   /* Swap out the original (we'll put it back later) */
   original.parentNode.replaceChild(tr, original);
   /* Create the two other inner nodes */
   var tl = document.createElement('div');
   var br = document.createElement('div');
   /* Now glue the nodes back in to the document */
   tr.appendChild(tl);
   tl.appendChild(br);
   br.appendChild(original);
 }
 }
} 

function check(name, e) {
	if(name == 'harmaaPyorTausta' && /\bharmaaPyorTausta\b/.exec(e)) return true;
	if(name == 'sininenPyorTausta' && /\bsininenPyorTausta\b/.exec(e)) return true;
	if(name == 'oranssiPyorTausta' && /\boranssiPyorTausta\b/.exec(e)) return true;
	if(name == 'violettiPyorTausta' && /\bviolettiPyorTausta\b/.exec(e)) return true;
	if(name == 'vihreaPyorTausta' && /\bvihreaPyorTausta\b/.exec(e)) return true;
	return false;
}

function swap(img) {
	var e = document.getElementById('map');
	e.src = '/media/pictures/' + img;
	return false;
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}

function WindowOnload(f) {
    var prev=window.onload;
    window.onload=function(){ if(prev)prev(); f; }
  }
