var t
var ipos
var isize
var place = 0
var curChoice = ""
var curOpt = ""
var LinkDiv = 0

var trainl = 0
var traindivl = 0
var trainp = 0
var traing = 1
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0
var trainpush = 0
var traininc = 0
trainmove = 2

var _startX = 0;            // mouse starting positions
var _startY = 0;
var _offsetX = 0;           // current element offset
var _offsetY = 0;
var _dragElement;           // needs to be passed from OnMouseDown to OnMouseMove
var _oldZIndex = 0;         // we temporarily increase the z-index during drag

InitDragDrop();

window.addEventListener('DOMMouseScroll', Wheel, false)

function getEvent(e)
{
  if(!e)
    return window.event
  return e;
}

function Wheel(event)
{
	var delta = 0;
	if (!event)
	{
		event = window.event;
	}
	if (event.wheelDelta)
	{
		delta = event.wheelDelta/120;
		if (window.opera)
		{
			delta = -delta;
		}
	}
	else if (event.detail) 
	{
		delta = -event.detail/3;
	}
	event.returnValue = false;
	if (delta == 1)
	{
		place -= 50
	}
	else if (delta == -1)
	{
		place -= (0-50)
	}
	if (place < 10)
	{
		place = 10
	}
	else if (place > 530)
	{
		place = 530
	}
	document.getElementById("scroll").style.top = place + "px"
	Scroll()
}

function InitDragDrop()
{
    document.onmousedown = OnMouseDown;
    document.onmouseup = OnMouseUp;
}

function OnMouseDown(e)
{
    // IE is retarded and doesn't pass the event object
    if (e == null) 
        e = window.event; 
    // IE uses srcElement, others use target
    var target = e.target != null ? e.target : e.srcElement;
    // for IE, left click == 1
    // for Firefox, left click == 0
    if ((e.button == 1 && window.event != null || 
        e.button == 0) && 
        target.className == 'drag')
    {
        // grab the mouse position
        _startX = e.clientX;
        _startY = e.clientY;
        
        // grab the clicked element's position
        _offsetX = ExtractNumber(target.style.left);
        _offsetY = ExtractNumber(target.style.top);
        // bring the clicked element to the front while it is being dragged
        _oldZIndex = target.style.zIndex;
        target.style.zIndex = 10000;
        // we need to access the element in OnMouseMove
        _dragElement = target;
        // tell our code to start moving the element with the mouse
        document.onmousemove = OnMouseMove;
        // cancel out any text selections
        document.body.focus();
        // prevent text selection in IE
        document.onselectstart = function () { return false; };
        // prevent IE from trying to drag an image
        target.ondragstart = function() { return false; };
        // prevent text selection (except IE)
        return false;
    }
		/*else
		{
			if (navigator.appName == "Netscape" && e.which == 3)
			{
				alert("Thank you for visiting My Mobile Ride!");
				return false;
			} 
	    if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2)
			{
				alert("Thank you for visiting My Mobile Ride!");
				return false;
			}
		}*/
}

function OnMouseMove(e)
{
    if (e == null) 
        var e = window.event; 
    // this is the actual "drag code"
		thisunit = (_offsetY + e.clientY - _startY)
		if (thisunit < 10)
		{
			thisunit = 10
		}
		if (thisunit > 530)
		{
			thisunit = 530
		}
    _dragElement.style.top = thisunit + 'px';
		place = thisunit
		Scroll()
}

function OnMouseUp(e)
{
    if (_dragElement != null)
    {
        _dragElement.style.zIndex = _oldZIndex;

        // we're done with these events until the next OnMouseDown
        document.onmousemove = null;
        document.onselectstart = null;
        _dragElement.ondragstart = null;

        // this is how we know we're not dragging      
        _dragElement = null;
    }
}

function ExtractNumber(value)
{
    var n = parseInt(value);
	
    return n == null || isNaN(n) ? 0 : n;
}

// this is simply a shortcut for the eyes and fingers
function $(id)
{
    return document.getElementById(id);
}

function Scroll()
{
	height = document.getElementById("iscroll").offsetHeight
	area = height - document.getElementById("oscroll").offsetHeight
	if (place < 10)
	{
		pos = 10
	}
	else if (place > 540)
	{
		pos = 540
	}
	pos = Math.ceil((((place - 10) / 5.2) / (0-100)) * area)
	document.getElementById("iscroll").style.top = pos + "px"
}

function Train()
{
	if (traing == 1)
	{
		trainp -= trainmove
		if (trainp <= (0 - trainl) && trainmove > 0)
		{
			trainp = traindivl
		}
		if (trainp > traindivl && trainmove < 0)
		{
			trainp = (0 - trainl)
		}
		document.getElementById("Train").style.left = trainp + "px"
	}
	t = setTimeout("Train()",15)
}

function TrainInit()
{
	trainl = document.getElementById("Train").offsetWidth
	trainpush = Math.floor(trainl / 100)
	traindivl = document.getElementById("TrainDiv").offsetWidth
	traininc = Math.floor(traindivl / 100)
	Train()
}

function TrainStop(e)
{
	traing = 0
}

function TrainGo()
{
	traing = 1
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return tempX
}

function MouseMove(e)
{
	var startx = tempX
	var endx = getMouseXY(e)
	var swidth = document.getElementById("TrainDiv").offsetWidth
	var twidth = document.getElementById("Train").offsetWidth
	if (startx < endx)
	{
		var mpct = Math.ceil(((endx - startx) / swidth) * 100) / 100
		var xpush = mpct * twidth
		trainp -= xpush
		trainmove = 2
	}
	else if (endx < startx)
	{
		var mpct = Math.ceil(((startx - endx) / swidth) * 100) / 100
		var xpush = mpct * twidth
		trainp -= (0-xpush)
		trainmove = -2
	}
	document.getElementById("Train").style.left = trainp + "px"
}

function AddLink()
{
	if (LinkDiv == 0)
	{
		document.getElementById("AddLink").style.width = "auto"
		document.getElementById("AddLink").style.height = "auto"
		document.getElementById("AddLink").style.visibility = "visible"
		LinkDiv = 1
	}
	else
	{
		document.getElementById("AddLink").style.width = "0px"
		document.getElementById("AddLink").style.height = "0px"
		document.getElementById("AddLink").style.visibility = "hidden"
		LinkDiv = 0
	}
}

function DoAlt(Alt)
{
	document.getElementById("altdiv").innerHTML = Alt
}

function ClearAlt()
{
	document.getElementById("altdiv").innerHTML = ""
}

function OverVid(num)
{
  var Vid = "Vid" + num
	document.getElementById(Vid).SetControllerVisible(true)
}

function OutVid(num)
{
  var Vid = "Vid" + num
	document.getElementById(Vid).SetControllerVisible(false)
}

function CheckForm()
{
	var UN = document.getElementById("jUN").value
	var PW = document.getElementById("jPW").value
	var PW2 = document.getElementById("jPW2").value
	var First = document.getElementById("First").value
	var Last = document.getElementById("Last").value
	var Email = document.getElementById("Email").value
	
	if (UN != "" && PW != "" && First != "" && Last != "" && Email != "")
	{
		document.getElementById("submit").disabled = ""
		document.getElementById("submit").value = "Continue"
		if (PW != PW2)
		{
			document.getElementById("submit").disabled = "disabled"
			document.getElementById("submit").value = "Passwords Don't Match"
		}
	}
}

function Swap(choice,opt,member)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="IconSwap.php?choice=" + choice + "&opt=" + opt + "&member=" + member + "&sid="+Math.random()
  xmlHttp.onreadystatechange=SwapDone
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function SwapDone() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
	  document.getElementById("IconTable").innerHTML=xmlHttp.responseText
		var mod = "Option" + curOpt
	  document.getElementById(mod).style.border = "solid 2px black";
		curChoice = ""
		curOpt = ""
  }
}

function OptSel(choice,member)
{
	if (curOpt)
	{
		var mod = "Option" + curOpt
	  document.getElementById(mod).style.border = "solid 2px black";
	}
	var target = "Option" + choice
	document.getElementById(target).style.border = "solid 2px yellow";
	curOpt = choice
	if (curChoice)
	{
		Swap(curChoice,curOpt,member)
	}
}

function ChoiceSel(choice,member)
{
	if (curChoice)
	{
		var mod = "Choice" + curChoice
	  document.getElementById(mod).style.border = "solid 2px black";
	}
	var target = "Choice" + choice
	document.getElementById(target).style.border = "solid 2px yellow";
	curChoice = choice
	if (curOpt)
	{
		Swap(curChoice,curOpt,member)
	}
}

function Halt()
{
	clearTimeout(t)
}

function Tester()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
    document.getElementById('container').style.behavior='url(#default#homepage)';
	  document.getElementById('container').setHomePage('http://www.mymobileride.com');
	}
	else
	{
		document.location = "Instructions.php"
	}
}

function Swoop(num)
{
	ipos -= 1
	isize -= (0-2)
	for (i=1;i<=num;i++)
	{
		doid = "I" + i
		document.getElementById(doid).style.left = ipos + "px"
		document.getElementById(doid).style.top = ipos + "px"
		document.getElementById(doid).style.width = isize + "px"
		document.getElementById(doid).style.height = isize + "px"
	}
	if (isize < 75)
	{
		t = setTimeout("Swoop(" + num + ")",20)
	}
}

function Center()
{
  Left = ((document.getElementById("Offset").offsetWidth - cwidth) / 2)
  if (Left < 90)
  {
    Left = 90
  }
  document.getElementById("container").style.left = Left + "px"
	document.getElementById("container").style.visibility = "visible"
}

function Go(choice)
{
  document.location = choice
}

function Redct(choice,time)
{
  var t = setTimeout("Go(" + choice + ")",time)
}

function CloseUp(choice)
{
	if (document.getElementById(choice))
	{
		document.getElementById(choice).style.width="0px"
		document.getElementById(choice).style.height="0px"
		document.getElementById(choice).style.visibility="hidden"
		document.getElementById(choice).style.position="absolute"
		document.getElementById(choice).style.top="25px"
	}
}

function ActionShow(choice)
{
	CloseUp("Upload")
	CloseUp("Link")
	CloseUp("Thought")
	CloseUp("Post")
	CloseUp("View")
	CloseUp("Linkto")
	CloseUp("Vote")
	if (document.getElementById(choice))
	{
		document.getElementById(choice).style.width="400px"
		document.getElementById(choice).style.height="auto"
		document.getElementById(choice).style.visibility="visible"
		document.getElementById(choice).style.position="relative"
		document.getElementById(choice).style.top="0px"
	}
}

function DoVote(choice,logged)
{
	if (logged == 1)
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url="Vote.php?choice=" + choice + "&sid="+Math.random()
		xmlHttp.onreadystatechange=VoteShow
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
	else
	{
		document.getElementById("Vote").innerHTML = 'You must be <a href="login.php">logged in</a> to vote.'
	}
	ActionShow("Vote")
}

function VoteShow() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById("Vote").innerHTML=xmlHttp.responseText
  }
}

function Showing(choice,page)
{
	var searchterm = document.getElementById("Search").value
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="Showing.php?choice=" + choice + "&page=" + page + "&set=top&search=" + searchterm + "&sid="+Math.random()
  xmlHttp.onreadystatechange=LoadShow
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
	document.getElementById("botchoice").value=document.getElementById("topchoice").value
	document.getElementById("botpage").value=document.getElementById("toppage").value
	document.getElementById("topchoice").value=choice
	document.getElementById("toppage").value=page
}

function LoadShow() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
	  document.getElementById("peoplebot").innerHTML=document.getElementById("peopletop").innerHTML
    document.getElementById("peopletop").innerHTML=xmlHttp.responseText
  }
}

function Showing2(choice,page,set)
{
	var searchterm = document.getElementById("Search").value
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="Showing.php?choice=" + choice + "&page=" + page + "&set=" + set + "&search=" + searchterm + "&sid="+Math.random()
	if (set == "bot")
	{
    xmlHttp.onreadystatechange=LoadBot
	}
	else
	{
		xmlHttp.onreadystatechange=LoadTop
	}
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
	cinfo = set + "choice"
	pinfo = set + "page"
	document.getElementById(cinfo).value=choice
	document.getElementById(pinfo).value=page
}

function LoadBot() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
	  if (xmlHttp.responseText == "No Results Found")
		{
			choice = document.getElementById("botchoice").value
			Showing2(choice,1,"bot")
		}
		else
		{
	    document.getElementById("peoplebot").innerHTML=xmlHttp.responseText
		}
  }
}

function LoadTop() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
	  if (xmlHttp.responseText == "No Results Found")
		{
			choice = document.getElementById("topchoice").value
			Showing2(choice,1,"top")
		}
		else
		{
	    document.getElementById("peopletop").innerHTML=xmlHttp.responseText
		}
  }
}

function Next(set)
{
	cinfo = set + "choice"
	pinfo = set + "page"
	choice = document.getElementById(cinfo).value
	page = document.getElementById(pinfo).value
  page -= (0-1)
	Showing2(choice,page,set)
}

function Prev(set)
{
	cinfo = set + "choice"
	pinfo = set + "page"
	choice = document.getElementById(cinfo).value
	page = document.getElementById(pinfo).value
	if (page != 1)
	{
		page -= 1
		Showing2(choice,page,set)
	}
}

function IconOut(iid)
{
	ClearAlt()
	/*document.getElementById(iid).style.width = 75
	document.getElementById(iid).style.height = 75
	document.getElementById(iid).style.zIndex = 0*/
}

function IconOver(iid,alt)
{
	DoAlt(alt)
	/*document.getElementById(iid).style.width = 95
	document.getElementById(iid).style.height = 95
	document.getElementById(iid).style.zIndex = 10*/
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    //Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function Start()
{
	if (document.getElementById("flashisin").value)
	{
		ipos = 50
		isize = 0
		var t = setTimeout("Swoop(" + document.getElementById("flashisin").value + ")",1000)
	}
	//setInterval(DoPos(),100)
}