/* Javascript code to replace headers with images */
function im_rp_init()
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = '/scotland/music/scotlandsmusic/images/fir_assumptions.gif?'+suffix;
	test.onload = imageReplacement;
}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('h1'));
	replaceThem(document.getElementsByTagName('h2'));
	replaceThem([document.getElementById("listen_again_a"),document.getElementById("next_episode_a"),document.getElementById("prev_episode_a")]);
	if(isSafari()){
		// shove the bottom classes down a bit.
		var p_tags = document.getElementsByTagName("p");
		for(var i=0;i<p_tags.length;i++){
			if(p_tags[i].className == "bottom_430" || p_tags[i].className == "bottom_210"){
				p_tags[i].style.bottom = "-30px";
			}
		}
	}
}

function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if(!x[i]){
			continue;
		}
		if (x[i].parentNode.id)
		{
			var y = replace.cloneNode(true);
			y.src = '/scotland/music/scotlandsmusic/images/' + x[i].parentNode.id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			y.style.width = "auto";
			y.style.height = "auto";
			x[i].replaceChild(y,x[i].firstChild);
			y.onload=function(){
				this.width = this.width;
				this.height = this.height;
				this.style.width = "auto";
				this.style.height = "auto";
			}
		}
	}
}
function isSafari(){
	if(navigator.vendor){
		if(navigator.vendor.indexOf("Apple") != -1){
			return true;
		} else {
			return false;
		}
	}
}