/*
	(c) 2007 Navin Kumar <n@vain.in>
	If you want to use this, please send me a mail!
*/
/*
	parameters:
		p is a json:
		id: either the object to swish or the id
		startSize: font size to start with
		endSize: font size to end at
		maxSize: the max an element is
		timerMs: timer Milliseconds
		fontStep: step in font point sizes
		direction: 0=left to right, 1 = right to left;
*/
//function swish(id, startSize,endSize,maxSize,fontStep,timerMs)
function swish(p)
{
	var id = p.id;
	var sS = p.startSize?p.startSize:14;
	var eS = p.endSize?p.endSize:p.startSize;
	var mS = p.maxSize?p.maxSize:25;
	var step= p.fontStep?p.fontStep:3;
	var tms = p.timerMs?p.timerMs:10;
	var dir = p.direction?p.direction:0;
	var thi=typeof(id)=="string"?document.getElementById(id):id;
	

	var s = thi.innerHTML;
	if(s.match("<"))return;
	var nue="";
	for (var ii=0;ii<s.length;ii++)
	{
		nue += "<span>" + s.charAt(ii) + "</span>";
	}
	thi.innerHTML=nue + "&nbsp;";
	var als=thi.getElementsByTagName("span");
	for (var i=als.length-1;i>=0;i--)
	{
		als[i].style.left=als[i].offsetLeft;
		als[i].style.position="absolute";
	}
	ani();
	//duly split up:)
	function ani(){
	var ix=0;
	var alls = thi.getElementsByTagName("span");
	if(dir==1){
		ix=alls.length-1;
	}
	var si = sS;
	setSize();
	var inc=true;
	function setSize(){
		var o=alls[ix];
		if(inc){
			si = si+step;
			if(si>=mS)inc=false;	
		}else{
			si= si-step;
		}
		o.style.fontSize=si +"pt";
		if(si!=eS){
			setTimeout(setSize,tms);
		}
		else{
			nextix();
		}

	function nextix(){
		if(dir==0){
		if(ix < alls.length-1){
			ix++;
			inc=true;
			setSize();
			return;
			}
		}
		if(dir==1){
			if(ix > 0){
			ix--;
			inc=true;
			setSize();
			return;
			}
		}

			thi.innerHTML = thi.innerHTML.replace(/<[^<]+>/g,"");
			thi.innerHTML = thi.innerHTML.replace(/&nbsp;$/,"");

	}

	}
}

}
