﻿
function growWidth(sender, startWidth, endWidth, steps, intervals, power, AfterAnimate) {
    if (sender.animation) {
        window.clearInterval(sender.animation);
    }

    var actualStep = 0;

    sender.animation = window.setInterval(function() {
        sender.currentWidth = ease(startWidth, endWidth, steps, actualStep, power);

        setWidth(sender, sender.currentWidth);

        if (++actualStep > steps) {
            window.clearInterval(sender.animation);
            if (AfterAnimate) {
                eval(AfterAnimate);
            }
        }
    }, intervals);
}


function growHeight(sender, startHeight, endHeight, steps, intervals, power, AfterAnimate) {
    if (sender.animation) {
        window.clearInterval(sender.animation);
    }

    var actualStep = 0;

    sender.animation = window.setInterval(function() {
        sender.currentHeight = ease(startHeight, endHeight, steps, actualStep, power);

        setHeight(sender, sender.currentHeight);

        if (++actualStep > steps) {
            window.clearInterval(sender.animation);
            if (AfterAnimate) {
                eval(AfterAnimate);
            }
        }
    }, intervals);
}

function growUp(sender, startTop, startHeight, endHeight, steps, intervals, power, AfterAnimate) {
    if (sender.animation) {
        window.clearInterval(sender.animation);
    }

    var actualStep = 0;

    sender.animation = window.setInterval(function() {
        sender.currentHeight = ease(startHeight, endHeight, steps, actualStep, power);

        setHeight(sender, sender.currentHeight);
        setTop(sender, startTop, sender.currentHeight);
        
        if (++actualStep > steps) {
            window.clearInterval(sender.animation);
            if (AfterAnimate) {
                eval(AfterAnimate);
            }
        }
    }, intervals);
}
function ease(minValue, maxValue, totalSteps, actualStep, power) {
    var delta = maxValue - minValue;
    var steps = minValue + (Math.pow(((1 / totalSteps) * actualStep), power) * delta);

    return Math.ceil(steps);
}

function setHeight(sender, height) {
    sender.style.height = String(height) + "px";

}
function setTop(sender, startTop, height) {
    sender.style.top = startTop - parseInt(height) + "px";

}

function setWidth(sender, width) {
    sender.style.width = String(width) + "px";
}

function flipscreen(openpage, language, LanguageChange) {

    if (language) {
        gotoPage = "top.document.getElementById('content_frame').src='subpage.php?content=" + openpage + "&open=1&language=" + language + "';";
        if (LanguageChange) {
            gotoPage = gotoPage + "top.document.getElementById('logo').src = 'img/" + language + "/logo.gif';";
        }
    }
    else {
        gotoPage = "top.document.getElementById('content_frame').src='subpage.php?content=" + openpage + "&open=1';";
    }
    growHeight(top.document.getElementById("content"), 615, 0, 50, 1, 2, gotoPage);

}

function CMS(language, xmlfile, xmltag, xmltagid, xmlsubtag) {
    cmswndw = window.open("edittext.php?language=" + language + "&xmlfile=" + xmlfile + "&xmltag=" + xmltag + "&xmltagid=" + xmltagid + "&xmlsubtag=" + xmlsubtag, "CMS", "width=600, height=400, location=0,status=0, scrollbars=1");
    cmswndw.focus();
}

function showscroll(scroll_target, scrollLineHeight) {
        document.write("<table style='width:100%;' cellpadding='0' cellspacing='2' border=0>");
        document.write('   <tr onmouseover="scroll_up(\'' + scroll_target + '\', false);" onmouseout="stopScroll(timerUp);">');
        document.write("      <td style='cursor:pointer;background-image:url(img/up.png);background-repeat:no-repeat;background-position: center bottom;'>");
        document.write("&nbsp;");
        document.write("      </td>");
        document.write("   </tr>");
        document.write("   <tr style='height:" + scrollLineHeight + "px;'>");
        document.write("      <td style='vertical-align:top;background-image:url(img/line.png);background-repeat:repeat-y;background-position: center center;'>");
        document.write("<img id='scrollImage'  src='img/scrolltile.png' style='vertical-align:top;'>");
        document.write("      </td>");
        document.write("   </tr>");
        document.write('   <tr onmouseover="scroll_down(\'' + scroll_target + '\', false);" onmouseout="stopScroll(timerDown);">');
        document.write("      <td  style='cursor:pointer;background-image:url(img/down.png);background-repeat:no-repeat;background-position: center top;'>");
        document.write("&nbsp;");
        document.write("      </td>");
        document.write("   </tr>");
        document.write("</table>");
}

function scroll_up(id, onceOnly) {
    step = 10;

    document.getElementById(id).scrollTop -= step;

    setScrollImage(calculatieScrollPos(id, step));

    if (onceOnly == false) {
        window.timerUp = setTimeout("scroll_up('" + id + "')", 10);
    }
}
function scroll_down(id, onceOnly) {
    step = 10;

    document.getElementById(id).scrollTop += step;

    setScrollImage(calculatieScrollPos(id, step));

    if (onceOnly == false) {
        window.timerDown = setTimeout("scroll_down('" + id + "')", 10);
    }
}

function calculatieScrollPos(id, stepHeight) {

    // Height of scrollarea out of sight
    y1 = document.getElementById(id).scrollHeight - parseInt(document.getElementById(id).style.height);
    
    //  Number of steps to scroll untill end
    stepCount = Math.round(y1 / stepHeight);
    
    // Calculate current position
    currPos = (document.getElementById(id).scrollTop / stepHeight);
    
    // Calculate step size
    stepSize = parseInt(document.getElementById(id).style.height) / stepCount;
    
    newPos = stepSize * currPos;
    
    return Math.round(newPos);
    
}

function setScrollImage(ypos) {
    if (document.getElementById('scrollImage')) {
        document.getElementById('scrollImage').style.paddingTop = ypos + "px";
    }
}

function stopScroll(id) {
    clearTimeout(id);
}


/** Event handler for mouse wheel event.
*/
function wheel(event) {
    var delta = 0;
    if (!event) /* For IE. */
        event = window.event;
    if (event.wheelDelta) { /* IE/Opera. */
        delta = event.wheelDelta / 120;
        /** In Opera 9, delta differs in sign as compared to IE.
        */
        if (window.opera)
            delta = -delta;
    } else if (event.detail) { /** Mozilla case. */
        /** In Mozilla, sign of delta is different than in IE.
        * Also, delta is multiple of 3.
        */
        delta = -event.detail / 3;
    }
    /** If delta is nonzero, handle it.
    * Basically, delta is now positive if wheel was scrolled up,
    * and negative, if wheel was scrolled down.
    */
    //alert(window.scrollarea);
    if (delta < 0) {
        document.getElementById(window.scrollarea).scrollTop += 26;
        scroll_down(window.scrollarea, true);

    }
    else {
        document.getElementById(window.scrollarea).scrollTop -= 26;
        scroll_up(window.scrollarea, true);
    }
    /** Prevent default actions caused by mouse wheel.
    * That might be ugly, but we handle scrolls somehow
    * anyway, so don't bother here..
    */
     if (event.preventDefault)
           event.preventDefault();
     event.returnValue = false;
    
}

function setWheelScroll(scrollArea) {
    if (window.addEventListener) {
        window.addEventListener('DOMMouseScroll', wheel, false);
    }
    window.scrollarea = scrollArea;
    window.onmousewheel = document.onmousewheel = wheel;
}

function unsetWheelScroll() {
    if (window.removeEventListener) {
        window.removeEventListener('DOMMouseScroll', wheel, false);
    }
    window.onmousewheel = document.onmousewheel = '';
}
