﻿Type.registerNamespace("QArt");

//Constructor met parameters
/*QArt.PanelSlide = function(slidePanel1, slidePanel2) {
this._slidePanel1 = slidePanel1;
this._slidePanel2 = slidePanel2;
   
}*/
//voorbeelden van functies
/*getFirstName: function() {
return this._firstName;
},

getLastName: function() {
return this._lastName;
},

getName: function() {
return this._firstName + ' ' + this._lastName;
},
*/

QArt.PanelSlide = function() {
    this._slideIntervalId = null;
    this._leftTmp = 0;
    this._topTmp = 0;
    this._element = null;
    this._left = 0;
    this._top = 0;
    this._startLeft = 0;
    this._startTop = 0;
    this._deltaLeft = 100;
    this._deltaTop = 60;
    this._doLeft = false;
    this._panelWidth = 710;
    this._panelHeight = 600;
}
QArt.PanelSlide.prototype = {

    startSlide: function(varname, id, startLeft, left, startTop, top) {
        this._element = document.getElementById(id);
        this._doLeft = startLeft != left;

        this._left = left;
        this._top = top;
        this._startLeft = startLeft;
        this._startTop = startTop;
        this._leftTmp = startLeft;
        this._topTmp = startTop;
        this._element.style.left = startLeft + "px";
        this._element.style.top = startTop + "px";
        //if(this._doLeft) alert(varname + " l" + left + " sl" + startLeft );
        clearInterval(this._slideIntervalId);
        this.disableScrollBars();
        var thisObj = this;
        this._slideIntervalId = setInterval(function() { thisObj.slide() }, 25);

    },

    slide: function() {
        //als deze == misschien wat naukeuriger mag, 
        //anders moeten de doorgegeven waarden een veelvoud zijn van de delta
        if (this._doLeft) {

            if (this._leftTmp >= this._left - (this._deltaLeft / 4) && this._leftTmp <= this._left + (this._deltaLeft / 4)) {
                clearInterval(this._slideIntervalId);
                this.enableScrollBars();
                this._leftTmp = this._left;
            }
            else {
                var left = this._startLeft > this._left;
                var a = Math.abs(this._leftTmp % this._panelWidth);
                if (a == 0) a = this._panelWidth;

                var b = this._panelWidth / 12;
                if ((!left && this._left > 0) || (left && this._left < 0)) b += this._panelWidth - a;
                else b += a;

                var percent = (this._deltaLeft * (b / this._panelWidth));
                var delta;
                if (percent < this._deltaLeft) {
                    delta = percent;
                } else {
                    delta = this._deltaLeft;
                }

                if (left) {
                    delta = -delta;
                }

                this._leftTmp = this._leftTmp + delta;

            }
            this._element.style.left = this._leftTmp + "px";
        } else {
            //voor top
            if (this._topTmp >= this._top - (this._deltaTop / 4) && this._topTmp <= this._top + (this._deltaTop / 4)) {
                clearInterval(this._slideIntervalId);
                this.enableScrollBars();
                this._topTmp = this._top;
            }
            else {
                var up = this._startTop > this._top;
                var a = Math.abs(this._topTmp % this._panelHeight);
                if (a == 0) a = this._panelHeight;

                var b = this._panelHeight / 10;
                if ((!up && this._top > 0) || (up && this._top < 0)) b += this._panelHeight - a;
                else b += a;

                var percent = (this._deltaTop * (b / this._panelHeight));
                var delta;
                if (percent < this._deltaTop) {
                    delta = percent;
                } else {
                    delta = this._deltaTop;
                }

                if (up) {
                    delta = -delta;
                }

                this._topTmp = this._topTmp + delta;
            }
            this._element.style.top = this._topTmp + "px";
        }
    },

    disableScrollBars: function() {
        var aElements = this._element.getElementsByTagName("div");
        for (var i = 0; i < aElements.length; i++) {
            if (aElements[i].className.match('scroll') || aElements[i].className.match('noscroll')) {
                aElements[i].className = 'noscroll';
            }
        }
    },



    enableScrollBars: function() {
        var aElements = this._element.getElementsByTagName("div");
        for (var i = 0; i < aElements.length; i++) {
            if (aElements[i].className.match('scroll') || aElements[i].className.match('noscroll')) {
                aElements[i].className = 'scroll';
            }
        }
    },


    dispose: function() {
        //alert('bye ' + this.getName());
    }



}
QArt.PanelSlide.registerClass('QArt.PanelSlide', null, Sys.IDisposable);


var panelSlideAnimation = new QArt.PanelSlide();
var panelSlideAnimation2 = new QArt.PanelSlide();


//Sys.Application.add_load(ApplicationLoadHandler);

//function ApplicationLoadHandler() {
//    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
//	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
//    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
//}

//function beginRequest(sender, args) {
//    
//}

//function endRequest(sender, args) {
//	panelSlideAnimation.startSlide('panelSlideAnimation','slider', 600);
//    panelSlideAnimation2.startSlide('panelSlideAnimation2','slider2', 0);
//}
//function pageLoaded(sender, args) {

//}

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

