words = [
"I" , "me" , "you" , "us" , "we", 
"cat" , "dog" , "loaf" , "cake" , "fire" , "fish" , "smells" , "music" , 
"biscuits" , "potato" , "table" , "chair" , "mice" , "bend" , "water" , 
"one" , "two" , "three" , "four" , "five" , "all" , "mat" , "goat", "field" , "house" , 
"it" , "that" , "this" , "jumper" , 

"like" , "dislike" , "love" , "hate" , "likes" , "dislikes" , 
"did" , "ran" , "eat" , "ate" , "listen" , "hear" , "chased" , 
"was" , "will", "found" , "sat" , "do" , "slept" , 

"and" , "or" , "is" , "isn't" , "but" , "are" , 
"the" , "the" , "the" , "the" , "the" , "and" , "to" , "for" , "has" , "of" , 

"red" , "blue" , "yellow" , "old" , "new" , "hard" , "soft" , "small", "tiny" , "big" , "huge" , 
"hot" , "warm" , "cold" , "happy" , "sad" , "missing" , "shiny" , "crumpled" , 

"on" , "off" , "near" , "behind" , "away" , "from" , "to" , "above" , "below" , "on" , 
"round", "inside" , "outside" , "over" , "under" , "with" , "using" , 

"a" , "a" , 
"s" , "s" , "'s" , "s" , "ing" , "ing" , 
"!" , "!" , "." , "." , "," , "," , ":" , ":" , "?" , "?"]

bar = document.body

for(i=0; i<words.length; i++) 
{
foo = document.createElement("div")
bar.appendChild(foo)
foo.appendChild(document.createTextNode(words[i]))
foo.setAttribute("id" , "d"+i)
//foo.setAttribute("onclick" , "domove(this)")
foo.setAttribute("onmousedown" , "mouse_down(" + i + ")")
foo.setAttribute("onmouseup"   , "mouse_up(" + i + ")")
//foo.setAttribute("onmouseover" , "mouse_over(" + i + ")")
//foo.setAttribute("onmouseout"  , "mouse_out(" + i + ")")
foo.style.left = Math.round(Math.random()*(document.body.clientWidth -foo.offsetWidth))
foo.style.top  = Math.round(Math.random()*(document.body.clientHeight -(foo.offsetHeight + 30))) + 30
}  
  
function mouse_down(id)
{
//window.status = "mouse-down: " + id
domove(document.getElementById("d" + id))
}

function mouse_up(id)
{
//window.status = "mouse-up: " + id
dontmove()
}
/*
function mouse_over(id)
{
window.status = "mouse-over: " + id
}

function mouse_out(id)
{
window.status = "mouse-out: " + id
} 
 

for(i=0; i<words.length; i++) //>)
{
document.getElementById("d" + i).onclick = "domove(this)"
}
*/
 
x=0 
y=0

function bodymousemove(evt)
{
myEvent = evt

if (!evt) 
{
myEvent = event
}

x = myEvent.clientX
y = myEvent.clientY


minx = moving.offsetWidth - (moving.offsetWidth - xdiff)
miny = moving.offsetHeight -(moving.offsetHeight- ydiff)

maxx = document.body.clientWidth + xdiff - moving.offsetWidth
maxy = document.body.clientHeight +ydiff - moving.offsetHeight

if(x<minx)
{
x=minx	
}

if(y<miny)
{
y=miny	
}


if(x>maxx)
{
x=maxx
}

if(y>maxy)
{
y=maxy
}

mlabel = "X: " + x + " Y: " + y


if(moving != null && moving !="")
{
moving.style.top = y - ydiff
moving.style.left = x - xdiff


mlabel += "  " + moving.offsetWidth + " " + moving.offsetHeight
//mlabel = "X: " + x + " Y: " + y + " " + moving.style.left + "  " + moving.style.top + " " + xdiff + " " + ydiff

}

//window.status = mlabel
}

window.document.onmousemove=bodymousemove
//window.document.onclick = thisclick
window.document.onkeypress = dontmove
moving = null

//mid = " "


function domove(tomove)
{

	/*
if(mid == tomove)
{
//window.status = "Moving stopped"
mid = null
dontmove()
return
}

mid = tomove
*/

if(moving == null || moving =="")
{
moving = tomove
moving.style.backgroundColor = "#CCCCFF";
//window.status = "Moving :" + tomove + " " + x + " " + pxToValue(moving.style.left) + " " + moving.style.left
xdiff = x - pxToValue(tomove.style.left)
ydiff = y - pxToValue(tomove.style.top)
}
}

function pxToValue(thing)
{
rt=""
for(pxtv=0; pxtv<thing.length-2; pxtv++) //>)
rt += thing.charAt(pxtv)

return rt
}

function dontmove()
{



try
{

if(moving != null)
{
moving.style.backgroundColor = "white";
moving = null
//mid = null
//window.status = "No move"
}

}
catch(e)
{
window.alert(e)
}

}



