reverseSpin = false;
boxLeft = 10;
boxRight = 20;

function change(param)
{
	sendthis="s"+param;
	spins = 0;
	go=window.setInterval("if (spins < 10) {spin(sendthis); spins++} else { go=clearInterval(go)}",50);
	var areachange=param+"_info";
	toggleArea(areachange);
}

function spin(idname)
{
	if (reverseSpin == false)
	{
		boxLeft++;
		boxRight--;


		if (boxLeft == 15)
		{
			reverseSpin = true;
			if (getWhatIfuckingWant(idname, 'sign2').style.display == "none")
			{
				getWhatIfuckingWant(idname, 'sign1').style.display = "none";
				getWhatIfuckingWant(idname, 'sign2').style.display = "";
			}
			else
			{
				getWhatIfuckingWant(idname, 'sign2').style.display = "none";
				getWhatIfuckingWant(idname, 'sign1').style.display = "";
			}
		}
	}
	else
	{
		boxLeft--;
		boxRight++;

		if (boxLeft == 10)
		{
			reverseSpin = false;
		}
	}

	getWhatIfuckingWant(idname, 'left').style.left = boxLeft + "px";
	getWhatIfuckingWant(idname, 'right').style.left = boxRight + "px";
}


var theFile
var theTarget
function readFile(url, target)
{
	theFile=null
	theTarget=target
	// Real browser
	if (window.XMLHttpRequest)
	{
		theFile=new XMLHttpRequest()
	}
	// IE
	else if (window.ActiveXObject)
	{
		theFile=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (theFile!=null)
	{
		theFile.onreadystatechange=state_Change
		theFile.open("POST",url,true);
		theFile.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
		post=target.substr(0,target.length-5) //theFile.send('id='+post);
		theFile.send(post+'=')
	}
	else
	{
		document.getElementById(target).innerHTML="<h2>Your Browser does not support the XMLHTTP feature.</h2>";
	}
}



function state_Change()
{
	// if theFile shows "loaded"
	if (theFile.readyState==4)
	{
		// if "OK"
		if (theFile.status==200)
		{
			//alert('it workded '+theTarget)
			//document.getElementById(theTarget).innerHTML=theFile.responseText
			document.getElementById(theTarget).innerHTML="<div class=\"t\"></div><div class=\"m\">"+theFile.responseText+"</div><div class=\"b\"></div>"
		}
		else
		{
			alert(target);
			document.getElementById(theTarget).innerHTML="<h2>Problem retrieving data:</h2><h4>" + theFile.statusText + "</h4>";
		}
	}
}




//js spinner crap






iddiv = new Array();

function toggleArea(id) {
	if (document.getElementById(id).style.display=="") {
		if(!iddiv[id]) {
			iddiv[id] = document.getElementById(id).innerHTML;
			document.getElementById(id).innerHTML = '';
			document.getElementById(id).style.display = "none";
		}
		else {
			document.getElementById(id).innerHTML = '';
			document.getElementById(id).style.display = "none";
		}
		//it's collapsed now
	}
	else {
		if(!iddiv[id]) {
			//we need to go find it
			//theLen= id.length-5
			//readFile("reader.php?"+id.substr(0,theLen), id)
			readFile("reader.php", id)
			document.getElementById(id).innerHTML = '<br />Loading...<br /><br />';
			document.getElementById(id).style.display = "";
		}
		else {
			document.getElementById(id).innerHTML = iddiv[id];
			document.getElementById(id).style.display = "";
			iddiv[id] = false;
		}
		//it's expanded now
	}
}

		

function getElementByClass(classname){ 
	var temparray=new Array() 
	var rootobj=document.getElementsByTagName("*")
	var inc=0 
	var rootlength=rootobj.length 
	for (i=0; i < rootlength; i++){ 
		if (rootobj[i].className==classname) temparray[inc++]=rootobj[i] 
	} 
	return temparray 
}

function getWhatIfuckingWant(idname, classname){
	var iWant=new String();
	var rootobj=document.getElementById(idname).getElementsByTagName("*");
	var inc=0;
	var rootlength=rootobj.length;
	for (i=0; i < rootlength; i++){ 
		if (rootobj[i].className==classname) iWant=rootobj[i];
	}

	return iWant;
}



//LOAD SHIT AND SOME FUNNY FUNCTION


function load()
{
	if (document.getElementsByTagName('input')[0])
	{
		document.getElementsByTagName('input')[0].focus();
	}
	boxLeft = 10;
	boxRight = 20;
	reverseSpin = false;
	//inc=0;
	//var ElementByClass=getElementByClass('sign2');
	//while (ElementByClass[inc]) 
	//{
	//	ElementByClass[inc].style.display = "none";
	//	inc++;
	//}
	//inc=0;

	//var theBoxes=getElementByClass('spinner');
	//timeout=50;
	//while (theBoxes[inc])
	//{
	//	var areachange=theBoxes[inc].id.substr(1)+"_info";
	//	toggleArea(areachange);
	//	spins = 0;
	//	setTimeout(dudrenov(change, theBoxes[inc].id.substr(1)), timeout);
	//	timeout = timeout + 650;
	//	inc++;
	//}
}

function dudrenov(funcToCall, param) 
{ 
	return function() {funcToCall(param); }
}
