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.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 blendimage(divid,imageid,imagefile,millisec)
	{
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//make image transparent
	changeOpac(0,imageid);

	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++)
		{
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
		}
	}

function currentOpac(id,opacEnd,millisec)
	{
	//standard opacity is 100
	var currentOpac = 100;

	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100)
		{
		currentOpac = document.getElementById(id).style.opacity * 100;
		}

	//call for the function that changes the opacity
	opacity(id,currentOpac,opacEnd,millisec)
	}




function opacitySwitch(idout,fadeTime,idin,showTime)
{
	//speed for each frame
	var inspeed = Math.round(showTime / 100);
	var outspeed = Math.round(fadeTime / 100);
	var timer = 0;
	var showOpac=0;
	var fadeOpac=100;
		//debugger;
		for(x=0;x<100;x++)
		{
			setTimeout("changeOpac(" + fadeOpac-- + ",'" + idout + "')",(timer * outspeed));
			setTimeout("changeOpac(" + showOpac++ + ",'" + idin + "')",(timer * inspeed));
			timer++;
		}

}


var ids=null;
var currentmsg=0;
var ftime=0;
var tid=0;
var dtime=null;
var stime=0;

// This function selects the elements identified by an array of ID'showMessagesds and shows each for the given time
// ids= array of id's to display, t1= fadeout/fadein time (ms), t2 = display time for each message. Note visibility of
// first element should always be "visible" (in event of script failure) this element will be visible at least!
function showMessages(i,fadeinTime,fadeoutTime,displayTimes)
{
	ids=i;
	dtime=displayTimes;
	ftime=fadeoutTime;
	stime=fadeinTime;
	for(x=1;x<ids.length;x++)
	{
		var object = document.getElementById(ids[x]).style;
		object.visibility="visible";
		object.opacity = 0;
		object.MozOpacity = 0;
		object.filter = "alpha(opacity=0)";
	}

	tid=window.setTimeout(nextMessage,dtime[currentmsg]);
}

// this function does the actual fade in/out
function nextMessage()
{
	opacitySwitch(ids[currentmsg],ftime,newMessage(),stime);
	tid=window.setTimeout(nextMessage,dtime[currentmsg]);

}

// this funtion increments next message and rotates to start
function newMessage()
{
	currentmsg++;
	if(currentmsg>=ids.length)
		currentmsg=0;

	return ids[currentmsg];
}

function stopMessages()
{
	window.clearTimeout(tid);
}

// this function writes out a link
function link2(url,title)
{
	document.write("<A target='_blank' href='"+url+"'>"+title+"</A>");
}

function setinframe()
{
	if(top.location.href==self.location && (document.frames || document.frames!='undefined') )
		{top.location.href="http://www.aplacefortheheart.co.uk/frame.php?sp="+document.location.pathname;}

}

function email2(name,subject,anchortext)
{
  	document.write("<a href='mailto:"+name+"@"+"aplacefortheheart.co.uk"+"?subject="+subject+"'>"+anchortext+"</a>");
}
