function player(url,layout, txt, info) {
	if (layout)
		layout = '&layout=' + layout;
	if (txt)
		txt = '&txt=' + txt;
	if (info)
		info = '&info=' + info;
 	var player_win = window.open('http://www.yle.fi/radiopeili/peiliplayer.php?url=' + url + layout + txt + info,'player','width=400,height=175');
	player_win.focus();
}

function wplayer(url,layout, txt, info) {
 	var player_win = window.open(url,'player','width=400,height=175');
	player_win.focus();
}

function nop() {
}

function news(page) {
 	var news_win = window.open(page,'news','width=700,height=430,resizable=yes');
	news_win.focus();
}

function displayDetails(id, caller) {
	var elem = document.getElementById(id);
	var poselem = document.getElementById(caller);
	var imgelem = document.getElementById(id + '_bottom');
	if (!elem || !poselem) return false;
	var positions = findPos(poselem);
	elem.style.top = positions[1];
	elem.style.display = (elem.style.display == 'block') ? 'none' : 'block';
	if (!elem.style.display) return true;
	var imgpositions = findPos(imgelem);
	var newTop = parseInt(elem.style.top.replace('px', '')) - (imgpositions[1] - parseInt(elem.style.top.replace('px', ''))) - 40;
	if (newTop < 100) {
		elem.style.top = positions[1]+8;
		var imgelemtop = document.getElementById(id + '_top');
		imgelemtop.className = 't2';
		imgelem.className = 'b2';
	} else {
		elem.style.top = newTop;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function switchView(id) {
	var elem = document.getElementById('div_' + id);
	if (!elem) return false;
	var disp = elem.style.display = elem.style.display == '' ? 'none' : '';
	var elem = document.getElementById('btn_txt_' + id);
	if (!elem) return false;
	elem.innerHTML = disp == '' ? '<img src="images/div-close2.gif" height="12" width="12" alt="" /> sulje näkymä' : '<img src="images/div-open.gif" height="12" width="12" alt="" /> avaa näkymä';
}

function calcApplicationHeight(element, min_height) {
	//find the height of the internal page
	var content_height = document.getElementById(element).contentWindow.document.body.scrollHeight;
	//change the height of the iframe
	document.getElementById(element).height = content_height > min_height ? content_height : min_height;
}
