﻿// 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('pop-'+id+'-'+x+'-'+y,'','width='+x+',height='+y+',scrollbars=no,resizable=no,menubar=no,status=no,directories=no,location=no,toolbar=no');
 };

function getElementsByClassName(className,tag,elm) {
 var testClass=new RegExp("(^|\\s)"+className+"(\\s|$)");
 var tag=tag || "*";
 var elm=elm || document;
 var elements=(tag=="*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
 var returnElements=[];
 var current;
 var length=elements.length;
 for (var i=0; i<length; i++) {
  current=elements[i];
  if (testClass.test(current.className)) {returnElements.push(current);};
  };
 return returnElements;
 };

function initsearch(txt,c) {
 o=document.hakulomake.haku;
 o.style.color=(typeof(c)=='undefined')?'#AAAAAA':c;
 o.value=txt;
 o.blur();
 };

function clearsearch(c) {
 o=document.hakulomake.haku;
 o.style.color=(typeof(c)=='undefined')?'#000000':c;
 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;
 };

