﻿// Ponnahdusikkuna:
var popwin=null;
// Hakutoiminnon status:
var searchready=false;
// Pomppivat elementit:
var bouncing=new Array();

function picpop(id,x,y) {
 if (popwin && !popwin.closed) {popwin.close();};
 popwin=window.open('picpop.php?id='+id+'&x='+x+'&y='+y,'','width='+x+',height='+y+',scrollbars=no,resizable=no,menubar=no,status=no,directories=no,location=no,toolbar=no');
 };

function initsearch(txt) {
 o=document.hakulomake.haku;
 o.style.color='#AAAAAA';
 o.value=txt;
 o.blur();
 };

function clearsearch() {
 o=document.hakulomake.haku;
 o.style.color='#000000';
 o.value='';
 return true;
 };

function findPosAndSize(o) {
 var curLeft=curTop=width=height=0;
 if (o.offsetWidth) {width=o.offsetWidth};
 if (o.offsetHeight) {height=o.offsetHeight};
 if (o.offsetParent) {
  curLeft=o.offsetLeft;
  curTop=o.offsetTop;
  while (o=o.offsetParent) {
   curLeft+=o.offsetLeft;
   curTop+=o.offsetTop;
   };
  };
 return {'left':curLeft, 'top':curTop, 'width':width, 'height':height};
 };

function bounce(id,endpoint,speed,gravity,elasticity,delay) {
 var o=document.getElementById(id);
 var ps=findPosAndSize(o);
 var speed=speed+gravity;
 var newtop=Math.min(endpoint,ps.top+Math.round(speed));
 o.style.top=newtop+'px';
 if (newtop==endpoint) {
  speed=-speed*elasticity;
  if (newtop==ps.top) {
   bouncing[id]=false;
   return true;
   };
  };
 bouncing[id]=setTimeout("bounce('"+id+"',"+endpoint+","+speed+","+gravity+","+elasticity+","+delay+")",delay);
 return false;
 };

function drop(id,endpoint,speed,gravity,elasticity,delay) {
 if (bouncing[id]) {clearTimeout(bouncing[id]);};
 bouncing[id]=bounce(id,endpoint,speed,gravity,elasticity,delay);
 return true;
 };
