// THIS JAVASCRIPT WAS DEVELOPED SOLELY BY Tony Carbone
//For permission to copy, edit, alter, or re-use this script in any way, please contact tonycarbone@trackking.org
//www.TrackKing.org - the best free horse-racing strategy game on the internet

function clearfield (element,def)
{
	ref=document.getElementById(element)
	if (ref.value==def)
	{
		ref.value=''
	}
	else
	{
		if (ref.value=='')
		{
			ref.value=def
		}
	}
}

function menu_op(el)
{
	document.getElementById('submenu'+el).className='hold'
	direction['hide_submenu'+el]=-2*showspeed
	x='hide_submenu'+el
	slide(x,'r')
}

function menu_cl()
{
	x=this.id
	for (loop=0;loop<menu_items;loop++ )
	{
		if (x!='link'+loop)
		{
			document.getElementById('link'+loop).blur()
			if (document.getElementById('hide_submenu'+loop))
			{
				if(document.getElementById('hide_submenu'+loop).style.right.replace("px","")<max['hide_submenu'+loop])
				{
					document.getElementById('submenu'+loop).className='fold'
					direction['hide_submenu'+loop]=3*showspeed
					slide('hide_submenu'+loop,'r')
				}
			}
		}
	}
}

function slide(element,side)
{
	obj=document.getElementById(element)
	switch (side)
	{
	case "l":
		curmargin=obj.style.left.replace("px","")
		statement="obj.style.left=newmargin+\"px\""
		multiplier=2
		break;
	case "t":
		curmargin=obj.style.top.replace("px","")
		statement="obj.style.top=newmargin+\"px\""
		multiplier=2
		break;
	case "r":
		curmargin=obj.style.right.replace("px","")
		statement="obj.style.right=newmargin+\"px\""
		multiplier=-2
		break;
	}
	if (curmargin<=0)
	{
		curmargin=0
	}
	if (direction[element]==0)
	{
		if (parseInt(curmargin)==max[element])
		{
			direction[element]=-1*multiplier*showspeed
		}
		else
		{
			direction[element]=multiplier*showspeed
		}
	}
	newmargin=parseInt(curmargin)+parseInt(direction[element])
	if (newmargin<0)
	{
		newmargin=0
		direction[element]=0
	}
	else
	{
		if (newmargin>max[element])
		{
			newmargin=max[element]
			direction[element]=0
			len = String(element).length
			numb= String(element).substring(len,len-1)
			document.getElementById('submenu'+numb).className=''
		}
		else
		{
			setTimeout(function(){slide(element,side)},showspeed)
		}
	}
	eval(statement)
}

function bannertext()
{
	showhide('bannertext')
}

function buttonaction(num)
{
	if (document.getElementById('button'+num).src.indexOf('light_but')==-1)
	{
		for (loop=1;loop<6;loop++)
		{
			if(document.getElementById('button'+loop))
			{
				on=document.getElementById('button'+loop)
				if (num==loop)
				{
					on.src="images/light_button.png"
				}
				else
				{
					on.src="images/off_button.png"
				}
			}
		}
		//timeframe=parseInt(max.banner/20)*20
		//slide('banner','t')
		//setTimeout(function(){document.getElementById('displayed').src=document.getElementById('banner_im'+num).src;document.getElementById('bannertext').innerHTML=bantxt[num];slide('banner','t');},timeframe)
		document.getElementById('displayed').src=document.getElementById('banner_im'+num).src
		document.getElementById('bannertext').innerHTML=bantxt[num]
	}
}

function ajphp_fed(source,elementdest) 
{
	document.getElementById(elementdest).innerHTML="<p class='waiting'>Retrieving data, please wait</p>"
	setTimeout(function(){var jsinsert = document.createElement('SCRIPT');jsinsert.type = 'text/javascript';jsinsert.src = source+"&dest="+elementdest;document.body.appendChild(jsinsert)},750)
}

function showhide(elid)
{
	btext=document.getElementById(elid)
	if (btext.style.display=='block')
	{
		btext.style.display='none'
	}
	else
	{
		btext.style.display='block'
	}
}

function replace_body(menuid)
{
	//document.getElementById('maininfo').innerHTML="<p class='waiting'>Retrieving data, please wait</p>"
	var jsinsert = document.createElement('SCRIPT')
	jsinsert.type = 'text/javascript'
	jsinsert.src = "fed_unlog.php?link="+menuid
	document.body.appendChild(jsinsert)
}

function bgmove()
{
	el=document.getElementsByTagName('body')
	el[0].style.backgroundPosition = bgX.toString()+'px '+bgY.toString()+'px'
	bgX=bgX+incX
	if (bgX==18||bgX==322)
	{
		bgX=170
	}
	bgY=bgY+incY
	if (bgY==0||bgY==155)
	{
		bgY=64
	}
}

function Fixtipsize()
{
	//This function is to support wzTip, which seems to have trouble finding the exact size of an embedded image/video which is added dynamically.
	//This routine will resize the tooptip to ensure the contents are displayed, and will slide the tip to the left if it is in danger of going off the screen
	embobj=document.getElementById('innerimg').offsetWidth
	outer=document.getElementById('WzBoDy').offsetWidth
	if (embobj>=outer)
	{
		outbox=document.getElementById('WzBoDy')
		outtitle=document.getElementById('WzTiTl')
		intitle=document.getElementById('WzTiTlTb')
		wholediv=document.getElementById('WzTtDiV')
		outerdiv=document.getElementById('WzTtDiV').style.left.replace("px","")
		newwidth=outer
		while ((embobj+8)>=newwidth)
		{
			newwidth=newwidth+1
			outbox.style.width=newwidth+"px"
			outtitle.style.width=newwidth+"px"
			intitle.style.width=newwidth+"px"
			containersize=newwidth+8
			wholediv.style.width=containersize+"px"
			if ((outerdiv+containersize+10)>=document.body.offsetWidth)
			{
				outerdiv=outerdiv-1
				document.getElementById('WzTtDiV').style.left=outerdiv+"px"
			}
		}
	}
}
