

var preloaded = new Array();

function preload(image)
{
	var i = preloaded.length;
	preloaded[i] = new Image();
	preloaded[i].src = image;
}

function showArrow(top)
{
	document.getElementById('arrow').style.visibility='visible';
	document.getElementById('arrow').style.top=top+"px";
}

function hideArrow()
{
	document.getElementById('arrow').style.visibility='hidden';
}

/**Image Rotation Scripts*/

var rots = new Array();
/*
Format of Rots:
0 - alpha image
1 - beta image
2 - frequency of change
3 - speed of trans
4 - array of image alt pairs
5 - current image index
6 - visible image (a or b : 0 = a visible, 1 = b visible)
7 - timer finished
*/

/**Add an image rotation*/
function addRot(name,top,left,width,height,wait,transpeed,alt)
{
document.write("<img id='"+name+"_a' style='position:absolute;top:"+top+"px;left:"+left+"px;width:"+width+"px;height:"+height+"px;' alt='"+alt+"' title='"+alt+"' />");
document.write("<img id='"+name+"_b' style='position:absolute;top:"+top+"px;left:"+left+"px;width:"+width+"px;height:"+height+"px;filter:alpha(opacity=0);moz-opacity:0;opacity:0;khtml-opacity:0;' alt='"+alt+"' title='"+alt+"' />");	
rots[name] = new Array(document.getElementById(name+"_a"),document.getElementById(name+"_b"),wait,transpeed,new Array(),0,0,0);
}

function imageLoaded(name)
{
	var r = rots[name];
	r[5]++;
	if((r[7] == 1) && (r[5] == r[4].length))
	{
		r[5] = 0;
		rotate(name);
	}
}

/**Add an image for the rotation specified*/
function addRotImg(name,imgSrc)
{
	var imgs = rots[name][4];
	var image = new Image();
	image.onLoad = imageLoaded(name);
	image.src = imgSrc;
	imgs[imgs.length] = image;
	if(imgs.length == 1)
		rots[name][0].src = image.src;
}

/**Start the image rotation*/
function startRotation(name)
{
	var r = rots[name];
	r[7] = 1;
	if(r[5] == r[4].length)
		rotate(name);
}



function rotate(name)
{
	var r = rots[name];
	r[5]++;
	if(r[5] >= r[4].length)
		r[5] = 0;
	if(r[6] == 1)
	{
		//load an image into a;
		r[0].src = r[4][r[5]].src;
		
		//make b vanish
		doFade(99,0,name+"_b",(-1*r[3]));

		r[6] = 0;
	}
	else
	{
		//load an image into b
		r[1].src = r[4][r[5]].src;

		//make b appear
		doFade(0,99,name+"_b",r[3])

		r[6] = 1;
	}
	setTimeout("rotate('"+name+"')", r[2]);
}



function doFade(val,targ,id,delta)
{
	val += delta;
	
	var obj = document.getElementById(id).style;
    obj.filter = "alpha(opacity="+val+")"; 
	obj.opacity = (val / 100);
    obj.MozOpacity = (val / 100);
    obj.KhtmlOpacity = (val / 100);
	
	if(val != targ)
		setTimeout("doFade("+val+", "+targ+", '"+id+"', "+delta+")",1);
}

/**End Image Rotation Scripts*/

var popups = new Array()

function show(id)
{
	popups[id] = 1;
	document.getElementById(id).style.visibility='visible';
}

function hide(id)
{
	popups[id] = 0;
	setTimeout("actuallyHide('"+id+"')",200);
}

function actuallyHide(id)
{
	if(popups[id] == 0)
		document.getElementById(id).style.visibility='hidden';
}

function jumpTo(county)
{
	setCounties(document.getElementById('counties'),"");
	var c = document.getElementById('counties')
	for(var i = 0; i < c.options.length; i++)
		if(c.options[i].value == county)
		{
			c.selectedIndex = i;
			break;
		}
	setTowns(document.getElementById("towns"),"",document.getElementById("counties").value);
}

function jumpTown(town)
{
	setCounties(document.getElementById('counties'),"");
	setTowns(document.getElementById('towns'),"","");
	var c = document.getElementById('towns')
	for(var i = 0; i < c.options.length; i++)
		if(c.options[i].value == town)
		{
			c.selectedIndex = i;
			break;
		}
}

function getSearchParameter(id)
{
	var buf = "";
	var loc = location.search.indexOf(id);
	if(loc == -1)
		return buf;
	loc += id.length+1;
	while((loc < location.search.length) && (location.search.charAt(loc) != '&'))
	{
		buf += location.search.charAt(loc);
		loc++;
	}
	buf = buf.split('%20');
	loc = 1;
	var sb = ""+buf[0];
	while(loc < buf.length)
	{
		sb += " "+buf[loc]
		loc++;
	}
	return sb;
}

function setDropdownSelect(id, value)
{
	if(value == "")
		return;
	obj = document.getElementById(id);
	for(var i = 0; i < obj.options.length; i++)
	{
		if(obj.options[i].value == value)
		{
			obj.selectedIndex = i;
			return;
		}
	}
}