/*  
        Based on the algorithm animatedLot.js by Martin Wurzinger ((c) 2001, wurzi@utanet.at)
        Alterations by Christian P. Praher Praher KEG
*/
		
	/* Paramter */
	var s		= 70;	//	+/- Abweichung (Sinus)
	var currentPos	= 0;	//	Aktuell berechnete X-Position des Plumbs
        var rpOffset    = -30; //reference Point Offset; Wenn der Endpunkt des Lots (am Ende der Bewegung) vom statischen reference point abweicht
                                //Wenn über dem reference point noch irgendein design element ist, in das das lot nicht "hineinfahren" soll
        var plumbHeight = 20; //height of the plumb
	var newXCoordinate = false;
	
	function initPlumb() {
                document.getElementById("plumb").style.left = document.getElementById("rp").offsetLeft - 6;
                //posInvisiblePlumbLine();
		move(0);
	}
	
	function move(current) {	
		currentPos = document.getElementById("rp").offsetTop + rpOffset - s  + Math.sin(current/s) * s;

                //the highest point of the plumb (just below the search field)
                //getting higher than this point would result in a strange look
                var plumbUpperBound = document.getElementById("plumbUpperBound").offsetTop;

                if (currentPos < plumbUpperBound) {
                    currentPos = plumbUpperBound;
                }

                
                document.getElementById("plumb").style.top = currentPos + "px";

                //the invisible (white) line below the plumb 
                posInvisiblePlumbLine();


                current += 3;

		
		
		if (newXCoordinate) {
			newXCoordinate = false;
			initPlumb();
		} else {
                        var timerPlumb = setTimeout( "move(" + current + ")", 35);
		}
	}

        //for positioning the invisible plumbLine 
        function posInvisiblePlumbLine() {
            //space between plumb and reference point. This is what the size of the invisible line has to be
            var spacePlumbRP = document.getElementById("rp").offsetTop + rpOffset - document.getElementById("plumb").offsetTop;
            document.getElementById("plumbInvisibleLine").style.height = spacePlumbRP + "px";

            //it is located exactly under the plumb (plumbPos + plumbHeight)
            document.getElementById("plumbInvisibleLine").style.top = document.getElementById("plumb").offsetTop + plumbHeight;

            //it's left offset is exactly the one of the reference point
            document.getElementById("plumbInvisibleLine").style.left = document.getElementById("rp").offsetLeft;            
        }
	
	function newAdjust() {
		newXCoordinate = true;
	}

        window.onresize = newAdjust;