/*!
 * Tiny Scrollbar 1.65
 * http://www.baijs.nl/tinyscrollbar/
 *
 * Copyright 2010, Maarten Baijs
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-2.0.php
 *
 * Date: 10 / 05 / 2011
 * Depends on library: jQuery
 *
 */
function Scrollbar(root, options){
        var oSelf = this;
        var oWrapper = root;
        var s = options.selectors;
        var oViewport = {obj: jQuery(s.viewport, root)};
        var oContent = {obj: jQuery(s.overview, root)};
        var oScrollbar = {obj: jQuery(s.scrollbar, root)};
        var oTrack = {obj: jQuery(s.track, oScrollbar.obj)};
        var oThumb = {obj: jQuery(s.thumb, oScrollbar.obj)};
        var oArrowAdv = {obj: jQuery(s.adv, oScrollbar.obj)};
        var oArrowRet = {obj: jQuery(s.ret, oScrollbar.obj)};
        var sAxis = options.axis == 'x', sDirection = sAxis ? 'left' : 'top', sSize = sAxis ? 'Width' : 'Height', sCssSize = sSize.toLowerCase();
        var iScroll, iPosition = {start: 0, now: 0}, iMouse = {};
        var sUseArrows = options.useArrows;

        function initialize() {
                oSelf.update();
                setEvents();
                return oSelf;
        }
        this.update = function(sScroll){
                oViewport[options.axis] = oViewport.obj[0]['offset'+ sSize];
                oContent[options.axis] = oContent.obj[0]['scroll'+ sSize];
                oContent.ratio = oViewport[options.axis] / oContent[options.axis];
                oScrollbar.obj.toggleClass('disable', oContent.ratio >= 1);
                oArrowAdv[options.axis] = sUseArrows ? parseFloat(oArrowAdv.obj.css(sCssSize)):0;
                oArrowRet[options.axis] = sUseArrows ? parseFloat(oArrowRet.obj.css(sCssSize)):0;
                oArrowAdv.obj.toggle(sUseArrows);
                oArrowRet.obj.toggle(sUseArrows);
                oTrack[options.axis] = options.size == 'auto' ? (oViewport[options.axis] - oArrowAdv[options.axis] - oArrowRet[options.axis]) : options.size;
                oThumb[options.axis] = Math.min(oTrack[options.axis], Math.max(0, ( options.sizethumb == 'auto' ? (oTrack[options.axis] * oContent.ratio) : options.sizethumb )));
                oScrollbar.ratio = options.sizethumb == 'auto' ? (oContent[options.axis] / oTrack[options.axis]) : (oContent[options.axis] - oViewport[options.axis]) / (oTrack[options.axis] - oThumb[options.axis]);
                iScroll = (sScroll == 'relative' && oContent.ratio <= 1) ? Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll)) : 0;
                iScroll = (sScroll == 'bottom' && oContent.ratio <= 1) ? (oContent[options.axis] - oViewport[options.axis]) : isNaN(parseInt(sScroll)) ? iScroll : parseInt(sScroll);
                return setSize();
        };
        function setSize(){
                oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio);
                oContent.obj.css(sDirection, -iScroll);
                iMouse['start'] = oThumb.obj.offset()[sDirection];
                oScrollbar.obj.css(sCssSize, oTrack[options.axis] + oArrowAdv[options.axis] + oArrowRet[options.axis]);
                oTrack.obj.css(sCssSize, oTrack[options.axis]);
                oThumb.obj.css(sCssSize, oThumb[options.axis]);

                return Math.abs(oTrack[options.axis] - oThumb[options.axis]) > 0.5;
        };
        function setEvents(){
                oThumb.obj.bind('mousedown', start);
                oThumb.obj[0].ontouchstart = function(oEvent){
                        oEvent.preventDefault();
                        oThumb.obj.unbind('mousedown');
                        start(oEvent.touches[0]);
                        return false;
                };
                oTrack.obj.bind('mouseup', drag);
                if(options.scroll && this.addEventListener){
                        oWrapper[0].addEventListener('DOMMouseScroll', wheel, false);
                        oWrapper[0].addEventListener('mousewheel', wheel, false );
                }
                else if(options.scroll){oWrapper[0].onmousewheel = wheel;}
                if(sUseArrows){
                    oArrowAdv.obj.bind("click", arrow)
                    oArrowRet.obj.bind("click", arrow)
                }
        };
        function start(oEvent){
                iMouse.start = sAxis ? oEvent.pageX : oEvent.pageY;
                var oThumbDir = parseInt(oThumb.obj.css(sDirection));
                iPosition.start = oThumbDir == 'auto' ? 0 : oThumbDir;
                jQuery(document).bind('mousemove', drag);
                document.ontouchmove = function(oEvent){
                        jQuery(document).unbind('mousemove');
                        drag(oEvent.touches[0]);
                };
                jQuery(document).bind('mouseup', end);
                oThumb.obj.bind('mouseup', end);
                oThumb.obj[0].ontouchend = document.ontouchend = function(oEvent){
                        jQuery(document).unbind('mouseup');
                        oThumb.obj.unbind('mouseup');
                        end(oEvent.touches[0]);
                };
                return false;
        };
        function wheel(oEvent){
            oEvent = jQuery.event.fix(oEvent || window.event);
            var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta/120 : -oEvent.detail/3;
            deltaScroll(iDelta);
            oEvent.preventDefault();
        };
        function arrow(oEvent){
            var iDelta = (oEvent.currentTarget === oArrowAdv.obj[0])? -5:5;
            deltaScroll(iDelta);
        };
        function deltaScroll(iDelta){
            if(!(oContent.ratio >= 1)){
                iScroll -= iDelta * options.wheel;
                iScroll = Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll));
                oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio);
                oContent.obj.css(sDirection, -iScroll);
            }
        };
        function end(oEvent){
                jQuery(document).unbind('mousemove', drag);
                jQuery(document).unbind('mouseup', end);
                oThumb.obj.unbind('mouseup', end);
                document.ontouchmove = oThumb.obj[0].ontouchend = document.ontouchend = null;
                return false;
        };
        function drag(oEvent){
                if(!(oContent.ratio >= 1)){
                        iPosition.now = Math.min((oTrack[options.axis] - oThumb[options.axis]), Math.max(0, (iPosition.start + ((sAxis ? oEvent.pageX : oEvent.pageY) - iMouse.start))));
                        iScroll = iPosition.now * oScrollbar.ratio;
                        oContent.obj.css(sDirection, -iScroll);
                        oThumb.obj.css(sDirection, iPosition.now);
                }
                return false;
        };

        return initialize();
};

module("ui.ScrollGroup")
.require("ui.Core", "ui.Group")
.declare("ui.ScrollGroup").extend("ui.Group")
.as({
    widgetName:"scroll",

    options:{
        view:"%basePath%/resources/views/ScrollGroupView.html",
        layout:"none",
        scroller:{
            axis: 'y', // vertical or horizontal scrollbar? ( x || y ).
            wheel: 40,  //how many pixels must the mouswheel scroll at a time.
            scroll: true, //enable or disable the mousewheel;
            size: 'auto', //set the size of the scrollbar to auto or a fixed number.
            sizethumb: 'auto', //set the size of the thumb to auto or a fixed number.
            useArrows: true, //display arrows on the scrollbar
            selectors:{
                viewport:'.viewport',
                overview:'.overview',
                scrollbar:'.scrollbar',
                track:'.track',
                thumb:'.thumb',
                adv:'.adv',
                ret:'.ret'
            }
        },
        hideOnEmpty:"scrollbar" /*scrollbar | thumb | all*/
    },

    styles:["%basePath%/resources/styles/ui-scroll-group.css"],

    _init:function(){
        this.base();
        this.element.bind("resize",jQuery.proxy(this,"updateScroll"));
    },

    updateScroll: function(){
        if(this.scroller){
            this._showScroll = this.scroller.update();
        }
        this._updateScroll();
    },

    _updateScroll: function(){
        var target;
        switch (this.options.hideOnEmpty) {
                case "scrollbar":
                    target = jQuery(this.options.scroller.selectors.scrollbar,this.element);
                    break;
                case "thumb":
                    target = jQuery(this.options.scroller.selectors.thumb,this.element);
                    break;
                default:
                    target = this.element;
            }

        this._showScroll?target.show():target.hide();
    },

    updateDisplay: function(){
        this.base();
        this.scroller = new Scrollbar(this.element, this.options.scroller);
        this.scroller.update();
        this._updateScroll()
    }
});
// SIG // Begin signature block
// SIG // MIIMzQYJKoZIhvcNAQcCoIIMvjCCDLoCAQExDjAMBggq
// SIG // hkiG9w0CBQUAMGYGCisGAQQBgjcCAQSgWDBWMDIGCisG
// SIG // AQQBgjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIB
// SIG // AAIBAAIBAAIBAAIBADAgMAwGCCqGSIb3DQIFBQAEED/J
// SIG // S59xWnKR4CJoBlOaJaGgggoPMIIE/DCCBGWgAwIBAgIQ
// SIG // ZVIm4bIuGOFZDymFrCLnXDANBgkqhkiG9w0BAQUFADBf
// SIG // MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24s
// SIG // IEluYy4xNzA1BgNVBAsTLkNsYXNzIDMgUHVibGljIFBy
// SIG // aW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcN
// SIG // MDkwNTIxMDAwMDAwWhcNMTkwNTIwMjM1OTU5WjCBtjEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3
// SIG // b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2UgYXQgaHR0
// SIG // cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykwOTEw
// SIG // MC4GA1UEAxMnVmVyaVNpZ24gQ2xhc3MgMyBDb2RlIFNp
// SIG // Z25pbmcgMjAwOS0yIENBMIIBIjANBgkqhkiG9w0BAQEF
// SIG // AAOCAQ8AMIIBCgKCAQEAvmcdtGCqEElvVhd8Zslehg3V
// SIG // 8ayncYOOi4n4iASJFQa6LYQhleTRnFBM+9IivdrysjU7
// SIG // Ho/DCfv8Ey5av4l8PTslHvbzWHuc9AG1xgq4gM6+J3Rh
// SIG // ZydNauXsgWFYeaPgFxASFSew4U00fytHIES53mYkZorN
// SIG // T7ofxTjIVJDhcvYZZnVquUlozzh5DaowqNssYEie16oU
// SIG // AamD1ziRMDkTlgM6fEBUtq3gLxuD3KgRUj4Cs9cr/SG2
// SIG // p1yjDwupphBQDjQuTafOyV4l1Iy88258KbwBXfwxh1rV
// SIG // jIVnWIgZoL818OoroyHnkPaD5ajtYHhee2CD/VcLXUEN
// SIG // Y1Rg1kMh7wIDAQABo4IB2zCCAdcwEgYDVR0TAQH/BAgw
// SIG // BgEB/wIBADBwBgNVHSAEaTBnMGUGC2CGSAGG+EUBBxcD
// SIG // MFYwKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LnZlcmlz
// SIG // aWduLmNvbS9jcHMwKgYIKwYBBQUHAgIwHhocaHR0cHM6
// SIG // Ly93d3cudmVyaXNpZ24uY29tL3JwYTAOBgNVHQ8BAf8E
// SIG // BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJ
// SIG // aW1hZ2UvZ2lmMCEwHzAHBgUrDgMCGgQUj+XTGoasjY5r
// SIG // w8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVyaXNp
// SIG // Z24uY29tL3ZzbG9nby5naWYwHQYDVR0lBBYwFAYIKwYB
// SIG // BQUHAwIGCCsGAQUFBwMDMDQGCCsGAQUFBwEBBCgwJjAk
// SIG // BggrBgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24u
// SIG // Y29tMDEGA1UdHwQqMCgwJqAkoCKGIGh0dHA6Ly9jcmwu
// SIG // dmVyaXNpZ24uY29tL3BjYTMuY3JsMCkGA1UdEQQiMCCk
// SIG // HjAcMRowGAYDVQQDExFDbGFzczNDQTIwNDgtMS01NTAd
// SIG // BgNVHQ4EFgQUl9BrqCZwyKE/lB8ILcQ1m6ShHvIwDQYJ
// SIG // KoZIhvcNAQEFBQADgYEAiwPA3ZTYQaJhabAVqHjHMMaQ
// SIG // PH5C9yS25INzFwR/BBCcoeL6gS/rwMpE53LgULZVECCD
// SIG // bpaS5JpRarQ3MdylLeuMAMcdT+dNMrqF+E6++mdVZfBq
// SIG // vnrKZDgaEBB4RXYx84Z6Aw9gwrNdnfaLZnaCG1nhg+W9
// SIG // SaU4VuXeQXcOWA8wggULMIID86ADAgECAhAjTaBL0kKF
// SIG // PErLmuhhwhm7MA0GCSqGSIb3DQEBBQUAMIG2MQswCQYD
// SIG // VQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4x
// SIG // HzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsx
// SIG // OzA5BgNVBAsTMlRlcm1zIG9mIHVzZSBhdCBodHRwczov
// SIG // L3d3dy52ZXJpc2lnbi5jb20vcnBhIChjKTA5MTAwLgYD
// SIG // VQQDEydWZXJpU2lnbiBDbGFzcyAzIENvZGUgU2lnbmlu
// SIG // ZyAyMDA5LTIgQ0EwHhcNMDkwODI3MDAwMDAwWhcNMTIw
// SIG // OTIwMjM1OTU5WjCByDELMAkGA1UEBhMCVVMxEzARBgNV
// SIG // BAgTCkNhbGlmb3JuaWExEzARBgNVBAcTClNhbiBSYWZh
// SIG // ZWwxFjAUBgNVBAoUDUF1dG9kZXNrLCBJbmMxPjA8BgNV
// SIG // BAsTNURpZ2l0YWwgSUQgQ2xhc3MgMyAtIE1pY3Jvc29m
// SIG // dCBTb2Z0d2FyZSBWYWxpZGF0aW9uIHYyMR8wHQYDVQQL
// SIG // FBZEZXNpZ24gU29sdXRpb25zIEdyb3VwMRYwFAYDVQQD
// SIG // FA1BdXRvZGVzaywgSW5jMIGfMA0GCSqGSIb3DQEBAQUA
// SIG // A4GNADCBiQKBgQC1R1YKdvQF2Rj4+knWfj81afUtVyep
// SIG // GF2P4tcYD53qlYmYi9t9Csc6PMWlUZhMGbOceQKYcBjc
// SIG // mWvyghJnoaEQ6796ZcsLD0pMH2R4SpV/SjxiQ280beig
// SIG // NerJS5X+ftOMCs1qSQ1LXlRFEohaewkNWsIp/+f1Y0vE
// SIG // dGzggnEKOQIDAQABo4IBgzCCAX8wCQYDVR0TBAIwADAO
// SIG // BgNVHQ8BAf8EBAMCB4AwRAYDVR0fBD0wOzA5oDegNYYz
// SIG // aHR0cDovL2NzYzMtMjAwOS0yLWNybC52ZXJpc2lnbi5j
// SIG // b20vQ1NDMy0yMDA5LTIuY3JsMEQGA1UdIAQ9MDswOQYL
// SIG // YIZIAYb4RQEHFwMwKjAoBggrBgEFBQcCARYcaHR0cHM6
// SIG // Ly93d3cudmVyaXNpZ24uY29tL3JwYTATBgNVHSUEDDAK
// SIG // BggrBgEFBQcDAzB1BggrBgEFBQcBAQRpMGcwJAYIKwYB
// SIG // BQUHMAGGGGh0dHA6Ly9vY3NwLnZlcmlzaWduLmNvbTA/
// SIG // BggrBgEFBQcwAoYzaHR0cDovL2NzYzMtMjAwOS0yLWFp
// SIG // YS52ZXJpc2lnbi5jb20vQ1NDMy0yMDA5LTIuY2VyMB8G
// SIG // A1UdIwQYMBaAFJfQa6gmcMihP5QfCC3ENZukoR7yMBEG
// SIG // CWCGSAGG+EIBAQQEAwIEEDAWBgorBgEEAYI3AgEbBAgw
// SIG // BgEBAAEB/zANBgkqhkiG9w0BAQUFAAOCAQEAIfxkh8Fd
// SIG // IHK+qtTf+9Eq5fjkk5gMMTQCOa+2aR7mqDzLfIFRGQzr
// SIG // tcc5/izsb/wPLUwdw1cRpnxO8/qLA2Ol+b99FONTOyyc
// SIG // Y8unwviYhdEjuFmqHkyC5MUYroZEjvTObFkkgN98Y48h
// SIG // C+mG2hdlVKXR0zr9r5q/rmmivVWbojvcYKHoW31O5OcM
// SIG // PsrWuOD305Ygmpck/91iopE3UN4tfeWYhzNj1F6Ai4Xa
// SIG // 5KiaMcs3zmoZ+6SePyI2YUgtff6yvy/rk8KVT41KGD2h
// SIG // fC+QrtVSkoDWP/MDtLjbTPCWElC1NWSEKowRI8t2x594
// SIG // Skjnzu/W5Lh97ixircOuM4IvBzGCAigwggIkAgEBMIHL
// SIG // MIG2MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNp
// SIG // Z24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
// SIG // IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1zIG9mIHVzZSBh
// SIG // dCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhIChj
// SIG // KTA5MTAwLgYDVQQDEydWZXJpU2lnbiBDbGFzcyAzIENv
// SIG // ZGUgU2lnbmluZyAyMDA5LTIgQ0ECECNNoEvSQoU8Ssua
// SIG // 6GHCGbswDAYIKoZIhvcNAgUFAKCBsDAZBgkqhkiG9w0B
// SIG // CQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4w
// SIG // DAYKKwYBBAGCNwIBFTAfBgkqhkiG9w0BCQQxEgQQqkIC
// SIG // aLlTeeDkRoBhixd8ojBUBgorBgEEAYI3AgEMMUYwRKAm
// SIG // gCQAQQB1AHQAbwBkAGUAcwBrACAAQwBvAG0AcABvAG4A
// SIG // ZQBuAHShGoAYaHR0cDovL3d3dy5hdXRvZGVzay5jb20g
// SIG // MA0GCSqGSIb3DQEBAQUABIGAHlA1f2KPj+V2H9AbXHak
// SIG // HklG7COXbGMk+wGLuD2MLJTBcvtuaFjVWO/FY59ynIok
// SIG // k8qzBZcvmnlhUubY3PxJ17CHBm+9cTP48kgntQ0z5ztM
// SIG // q+qbIut9toefpitRl1GvEr2CXt8U39q1d03KbWNumeXz
// SIG // Ikekagrb3Ki5s1XkZMo=
// SIG // End signature block
