Date.prototype.addDays = function(count) { this.setDate(this.getDate() + count); return this; }
Date.prototype.addWorkDays = function(count) {
    for (var i=0;i<=count;i++) {
        this.setDate(this.getDate() + 1);
        while (this.getDay() == 0 || this.getDay() == 6) this.setDate(this.getDate() + 1);
    }
    return this;
}
Date.prototype.getCopy = function() { return new Date(this.getTime()); }

var calendar = {
    
    element: null,
    elmCity: null,
    elmDetail: null,
    elmTreatment: null,
    elmPhysician: null,
    elmDays: null,
    
    loading: 'Beschikbare tijden worden opgehaald...',
    nwpatient: 'Nieuwe patient',
    data: {
        "Amsterdam": null,
        "Bussum": null,
        "Rijswijk": null,
        "Utrecht": null
    },
    activeCity: null,
    activeTreatment: null,
    activeDates: null,
    shortDay: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
    longDay: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
    months: ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
    
    pages: [],
    selectedDate: null,
    selectedDaypart: null,

    init: function($element) {
        var self = this;
        self.element = $element;
        $(self.element).html('<div class="city"><select id="calendar_city" name="calendar_city"></select></div><div class="detail"></div><a id="showPopup" style="display: none;" class="iframe" href="#">#</a>');
        self.elmCity = $('.city select', this.element);
        self.elmDetail = $('.detail', this.element);
        $('.date a', self.elmDetail).live('click', function() {
            if (!$(this).closest('div').hasClass('disabled')) {
                self.selectedDaypart = $(this).html();
                self.selectedDate = $(this).closest('.date').data('date');
                if (self.elmPhysician.val() == self.nwpatient) 
                    $('a#showPopup').attr('href', 'http://www.annatommie.nl/annatommie/nl-NL/_info/Afspraak+maken.aspx');
                else
                    $('a#showPopup').attr('href', 'http://www.annatommie.nl/annatommie/nl-NL/_info/Bestaande+patient.aspx');
                $('a#showPopup').click();
            }
            return false;
        });
        $('.navnext', self.element).live('click', function() {
            self.navNext();
            return false;
        });
        $('.navback', self.element).live('click', function() {
            self.navBack();
            return false;
        });
        self.elmCity.change(function() {
            self.changeCity(self.elmCity.val());
        });
        $('a#showPopup').fancybox({
            overlayShow: true,
            hideOnOverlayClick: false,
            hideOnContentClick: false,
            frameWidth: 700,
            frameHeight: 525
        });
        $.each(self.data, function(index) {
            self.elmCity.append('<option value="' + index + '">' + index + '</option>');
        });
        self.changeCity(self.elmCity.val());
    },
    
    initTreatment: function(data) {
        var self = this;
        self.activeCity = data;
        self.elmDetail.html('<div class="treatment"><select id="calendar_treatment" name="calendar_treatment"></select></div><div class="physician"><select id="calendar_physician" name="calendar_physician"></select></div><div class="days"></div><div class="navigation"><a href="#" class="navnext">meer data</a><a href="#" class="navback">terug</a></div>');
        self.elmTreatment = $('.treatment select', this.element);
        self.elmPhysician = $('.physician select', this.element);
        self.elmDays = $('.days', this.element);
        $.each(data, function(index) {
            self.elmTreatment.append('<option value="' + index + '">' + index + '</option>');
        });
        self.elmTreatment.change(function() {
            self.initPhysician(self.activeCity[self.elmTreatment.val()]);
        });
        self.elmPhysician.change(function() {
            self.initDates(self.activeTreatment[self.elmPhysician.val()]);
        });
        self.initPhysician(data[self.elmTreatment.val()]);
    },
    
    initPhysician: function(data) {
        var self = this;
        self.activeTreatment = data;
        self.elmPhysician.html('<option value="' + calendar.nwpatient + '">' + calendar.nwpatient + '</option><optgroup label="Uw behandelaar"></optgroup>');
        var og = $('optgroup', self.elmPhysician);
        $.each(data, function(index) {
            if (index != calendar.nwpatient) og.append('<option value="' + index + '">' + index + '</option>');
        });
        self.initDates(data[self.elmPhysician.val()]);
    },
    
    initDates: function(data) {
        var self = this;
        self.pages = [];
        self.activeDates = data;
        var fromDate = new Date().addWorkDays(4);
        self.pages[self.pages.length] = fromDate;
        self.showDates(data, fromDate);
    },
    
    showDates: function(data, fromDate) {
        var self = this;
        var count = 0;
        var lastMonth = -1;
        var doShow = function() {
            $('.date,.month', self.elmDays).remove();
            if (data) {
                var date = self.getNextDate(data, fromDate);
                while (date && (count < 4)) {
                    if (date.getMonth() != lastMonth) {
                        lastMonth = date.getMonth();
                        self.addMonth(date);
                    }
                    self.addDate(date.getCopy(), self.getDateObject(data, date));
                    date = self.getNextDate(data, date.addDays(1));
                    count++;
                }
                self.pages[self.pages.length] = date;
                if (date) {
                    $('.navnext', self.element).css('display', 'block');
                } else {
                    $('.navnext', self.element).css('display', 'none');
                }
                $('.navback', self.element).css('display', (self.pages.length > 2 ? 'inline' : 'none'));
            }
        }
        if ($('.date,.month', self.elmDays).length > 0) {
            self.elmDays.fadeOut(200, doShow).fadeIn(200);
        } else {
            doShow();
        }
    },
    
    addMonth: function(date) {
        var self = this;
        self.elmDays.append('<div class="month">' + self.months[date.getMonth()] + '</div>');
    },
    
    addDate: function(date, dateObj) {
        var self = this;
        var elmDate = $('<div class="date"><div class="day"></div><div class="morning"><a href="#">ochtend</a></div><div class="afternoon"><a href="#" class="afternoon">middag</a></div></div>');
        $(elmDate).data('date', date);
        $('.day', elmDate).html(self.shortDay[date.getDay()] + ' ' + date.getDate());
        if (!dateObj[0]) $('.morning', elmDate).addClass('disabled');
        if (!dateObj[1]) $('.afternoon', elmDate).addClass('disabled');
        self.elmDays.append(elmDate);
    },
    
    getNextDate: function(data, date) {
        var self = this;
        var count = date.getCopy();
        var month; var day;
        while (count.getMonth() - date.getMonth() < 3) {
            if (self.getDateObject(data, count)) return count;
            count.addDays(1);
        }
        return null;
    },
    
    getDateObject: function(data, date) {
        var month = data['m' + (date.getMonth() + 1)];
        if (!month) return null;
        var result = month['d' + date.getDate()];
        if (!result) return null;
        if (!result[0] && !result[1]) return null;
        return result;
    },
    
    changeCity: function(city) {
        var self = this;
        var change = function() {
            alert(self.data[city]);
        }
        if (self.data[city]) 
            self.initTreatment(self.data[city]);
        else {
            self.showLoading();
            $.getJSON('/annatommie/data.ashx?locatie=' + city, function(data) {
                self.combineDates(data);
                self.initTreatment(self.data[city] = data);
            });
        } 
    },
    
    combineDates: function(data) {
        var city, newp, month, day;
        $.each(data, function(index, value) {
            city = value;
            newp = {};
            $.each(city, function(index, value) {
                $.each(value, function(index, value) {
                    if (!newp[index]) newp[index] = {};
                    month = newp[index];
                    $.each(value, function(index, value) {
                        if (!month[index]) month[index] = [0, 0];
                        month[index][0] = month[index][0] | value[0];
                        month[index][1] = month[index][1] | value[1];
                    });
                });
            });
            city[calendar.nwpatient] = newp;
        });
    },
    
    navBack: function() {
        this.pages.length -= 2;
        this.showDates(this.activeDates, this.pages[this.pages.length - 1]);
    },
    
    navNext: function() {
        this.showDates(this.activeDates, this.pages[this.pages.length - 1]);
    },
    
    showLoading: function() {
        this.elmDetail.html('<div class="loading"><img src="/annatommie/images/calendar-loading.gif" /><br />' + this.loading + '</div>');
    },
    
    formReady: function(doc) {
        var self = this;
        $('.FormFieldLocatie input', doc).attr('disabled', 'disabled').val(self.elmCity.val());
        $('.FormFieldBehandeling input', doc).attr('disabled', 'disabled').val(self.elmTreatment.val() + ' (' + self.elmPhysician.val() + ')');
        $('.FormFieldDatum input', doc).attr('disabled', 'disabled').val(self.fullDate(self.selectedDate) + ' in de ' + self.selectedDaypart);
        $('.FormFieldNaam input', doc).focus();
    },
    
    fullDate: function(date) {
        return this.longDay[date.getDay()] + ' ' + date.getDate() + ' ' + this.months[date.getMonth()] + ' ' + date.getFullYear();
    }
    
}

var hotspots = {

    setup: function() {
        $('#klachten_map a').hover(function() {
            hotspots.movein(this);
        }, function() {
            hotspots.moveout(this);
        });
        hotspots.helper = document.createElement('div');
        $(hotspots.helper).addClass('hotspots_helper').css('position', 'absolute').css('display', 'none');
        $(document.body).prepend(hotspots.helper);
    },
    
    movein: function(element) {
        var int = hotspots._getInt(element.id);
        var pos = $(element).offset();
        var width = $(element).width();
        $(hotspots.helper).html(hotspots._getText(int)).css('left', (pos.left + width + 5) + 'px').css('top', (pos.top + 5) + 'px').css('display', 'block');
    },
    
    moveout: function(element) {
        $(hotspots.helper).css('display', 'none');
    },
    
    click: function(int) {
        window.location.href='/Annatommie/nl-NL/oplossingen.aspx?category=' + hotspots._getCat(int);
    },
    
    _getInt: function(id) {
        return parseInt(id.charAt(id.length - 1));
    },
    
    _getText: function(int) {
        switch(int) {
            case 1: return 'Hand en pols';
            case 2: return 'Schouder';
            case 3: return 'Elleboog';
            case 4: return 'Heup';
            case 5: return 'Knie';
            case 6: return 'Voet';
        }
    },
    
    _getCat: function(int) {
        switch(int) {
            case 1: return '40848760864571392.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
            case 2: return '40848761110822913.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
            case 3: return '40848762113753088.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
            case 4: return '40848762407616513.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
            case 5: return '40848761763594241.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
            case 6: return '40848762746535937.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0';
        }
    }

}

var banner = {

    text: [],
    b: 0,
    interval: null,
    
    start: function() {
        /*if (window.location.search.substring(1) == 'editbanner') {
            $('#home_banner,#home_banner3').css('display', 'block');
        } else {
            banner.text[0] = $('#home_banner .ContentItemText').html();
            banner.text[1] = $('#home_banner2 h2').html();
            //banner.text[2] = $('#home_banner3 .ContentItemText').html();
            banner.interval = window.setInterval(banner.change, 5000);
        }*/
    },
    
    change: function() {
        banner.b += 1;
        if (banner.b >= banner.text.length) banner.b = 0;
        var txt = $('#home_banner .ContentItemText');
        txt.fadeOut(750, function() {
            txt.html(banner.text[banner.b]).fadeIn(750);
        });
    }
}

function toggle(id) {
    $('#' + id).toggleClass('oplossing_selected');
}

function map(int) {
    hotspots.click(int);
}

$(document).ready(function() {
    /* $('#scroller').jScrollPane({ showArrows: true, scrollbarWidth: 17, arrowSize: 17 }); */

    if ($('#home_banner').length > 0) banner.start();
    hotspots.setup();

    var agenda = $('#featuresbar #agenda .calendar');
    if (agenda.length > 0) calendar.init(agenda);
    
    $('#featuresbar .collapseTitle').click(function() {
        var self = this;
        $('#featuresbar .collapseBox').hide(800);
        $('#afspraak .collapseTitle').show(800);
        window.setTimeout(function() {
            $(self).next('.collapseBox').show(800);
            if ($(self).closest('#afspraak').length > 0) {
                $(self).hide(800);
            }
        }, 200);
    });
    
    $('.PersonPopupDetail').hover(function() {
        var self = this;
        $('.FullName', this).fadeIn(300);
    }, function() {
        $('.FullName', this).fadeOut(800);
    });
    var $persona = $('.PersonPopupDetail a');
    if ($persona.length > 0) $('.PersonPopupDetail a').fancybox();
});


function showPopbox() {
    if (window.location.search.substring(1) == 'edit') {
        $('#popbox').css('display', 'block');
        $('#home_left').css('display', 'none');
        $('#home_right').css('display', 'none');
        $('#footer').css('display', 'none');
        $('#corporate').css('display', 'none');
    } else {
        if (window.location.search.substring(1) == 'popbox') {
            if (readCookie('nopopbox') != 1) {
                $('#popboxlink').fancybox({'hideOnContentClick': false}).click();
                $('.popboxhide,.popboxhidelink').click(function() {
                    $('#popboxlink').fancybox.close();
                    createCookie('nopopbox', '1', 730);
                });
                $('.popboxitem').hover(function() {
                    $('.popboxitem').removeClass('active');
                    $(this).addClass('active');
                }, function() {
                    $(this).removeClass('active');
                }).click(function() {
                    var self = this;
                    $(self).removeClass('active');
                    window.setTimeout(function() {
                        $(self).addClass('active');
                        window.setTimeout(function() {
                            $(self).removeClass('active');
                            window.setTimeout(function() {
                                $(self).addClass('active');
                            }, 100);
                        }, 100);
                    }, 100);
                    switch (this.id) {
                        case 'popboxNL':
                            $('#popboxlink').fancybox.close();
                            break;
                        case 'popboxInfo':
                            window.location.href = 'http://www.annatommie.info';
                            break;
                        case 'popboxTV':
                            alert('Binnenkort online!');
                            break;
                    }
                });
            }
        }
    }
}






/* Scroller */
(function($){$.event.special.mousewheel={setup:function(){var handler=$.event.special.mousewheel.handler;if($.browser.mozilla)
$(this).bind('mousemove.mousewheel',function(event){$.data(this,'mwcursorposdata',{pageX:event.pageX,pageY:event.pageY,clientX:event.clientX,clientY:event.clientY});});if(this.addEventListener)
this.addEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=handler;},teardown:function(){var handler=$.event.special.mousewheel.handler;$(this).unbind('mousemove.mousewheel');if(this.removeEventListener)
this.removeEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=function(){};$.removeData(this,'mwcursorposdata');},handler:function(event){var args=Array.prototype.slice.call(arguments,1);event=$.event.fix(event||window.event);$.extend(event,$.data(this,'mwcursorposdata')||{});var delta=0,returnValue=true;if(event.wheelDelta)delta=event.wheelDelta/120;if(event.detail)delta=-event.detail/3;event.data=event.data||{};event.type="mousewheel";args.unshift(delta);args.unshift(event);return $.event.handle.apply(this,args);}};$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel");},unmousewheel:function(fn){return this.unbind("mousewheel",fn);}});})(jQuery);jQuery(function($){var eventName='emchange';$.em=$.extend({version:'1.0',delay:200,element:$('<div />').css({left:'-100em',position:'absolute',width:'100em'}).prependTo('body')[0],action:function(){var currentWidth=$.em.element.offsetWidth/100;if(currentWidth!=$.em.current){$.em.previous=$.em.current;$.em.current=currentWidth;$.event.trigger(eventName,[$.em.current,$.em.previous]);}}},$.em);$.fn[eventName]=function(fn){return fn?this.bind(eventName,fn):this.trigger(eventName);};$.em.current=$.em.element.offsetWidth/100;$.em.iid=setInterval($.em.action,$.em.delay);});(function($){$.jScrollPane={active:[]};$.fn.jScrollPane=function(settings)
{settings=$.extend({},$.fn.jScrollPane.defaults,settings);var rf=function(){return false;};return this.each(function()
{var $this=$(this);var paneEle=this;var currentScrollPosition=0;var paneWidth;var paneHeight;var trackHeight;var trackOffset=settings.topCapHeight;if($(this).parent().is('.jScrollPaneContainer')){currentScrollPosition=settings.maintainPosition?$this.position().top:0;var $c=$(this).parent();paneWidth=$c.innerWidth();paneHeight=$c.outerHeight();$('>.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap',$c).remove();$this.css({'top':0});}else{$this.data('originalStyleTag',$this.attr('style'));$this.css('overflow','hidden');this.originalPadding=$this.css('paddingTop')+' '+$this.css('paddingRight')+' '+$this.css('paddingBottom')+' '+$this.css('paddingLeft');this.originalSidePaddingTotal=(parseInt($this.css('paddingLeft'))||0)+(parseInt($this.css('paddingRight'))||0);paneWidth=$this.innerWidth();paneHeight=$this.innerHeight();var $container=$('<div></div>').attr({'className':'jScrollPaneContainer'}).css({'height':paneHeight+'px','width':paneWidth+'px'});if(settings.enableKeyboardNavigation){$container.attr('tabindex',settings.tabIndex);}
$this.wrap($container);$(document).bind('emchange',function(e,cur,prev)
{$this.jScrollPane(settings);});}
trackHeight=paneHeight;if(settings.reinitialiseOnImageLoad){var $imagesToLoad=$.data(paneEle,'jScrollPaneImagesToLoad')||$('img',$this);var loadedImages=[];if($imagesToLoad.length){$imagesToLoad.each(function(i,val){$(this).bind('load readystatechange',function(){if($.inArray(i,loadedImages)==-1){loadedImages.push(val);$imagesToLoad=$.grep($imagesToLoad,function(n,i){return n!=val;});$.data(paneEle,'jScrollPaneImagesToLoad',$imagesToLoad);var s2=$.extend(settings,{reinitialiseOnImageLoad:false});$this.jScrollPane(s2);}}).each(function(i,val){if(this.complete||this.complete===undefined){this.src=this.src;}});});};}
var p=this.originalSidePaddingTotal;var realPaneWidth=paneWidth-settings.scrollbarWidth-settings.scrollbarMargin-p;var cssToApply={'height':'auto','width':realPaneWidth+'px'}
if(settings.scrollbarOnLeft){cssToApply.paddingLeft=settings.scrollbarMargin+settings.scrollbarWidth+'px';}else{cssToApply.paddingRight=settings.scrollbarMargin+'px';}
$this.css(cssToApply);var contentHeight=$this.outerHeight();var percentInView=paneHeight/contentHeight;if(percentInView<.99){var $container=$this.parent();$container.append($('<div></div>').addClass('jScrollCap jScrollCapTop').css({height:settings.topCapHeight}),$('<div></div>').attr({'className':'jScrollPaneTrack'}).css({'width':settings.scrollbarWidth+'px'}).append($('<div></div>').attr({'className':'jScrollPaneDrag'}).css({'width':settings.scrollbarWidth+'px'}).append($('<div></div>').attr({'className':'jScrollPaneDragTop'}).css({'width':settings.scrollbarWidth+'px'}),$('<div></div>').attr({'className':'jScrollPaneDragBottom'}).css({'width':settings.scrollbarWidth+'px'}))),$('<div></div>').addClass('jScrollCap jScrollCapBottom').css({height:settings.bottomCapHeight}));var $track=$('>.jScrollPaneTrack',$container);var $drag=$('>.jScrollPaneTrack .jScrollPaneDrag',$container);var currentArrowDirection;var currentArrowTimerArr=[];var currentArrowInc;var whileArrowButtonDown=function()
{if(currentArrowInc>4||currentArrowInc%4==0){positionDrag(dragPosition+currentArrowDirection*mouseWheelMultiplier);}
currentArrowInc++;};if(settings.enableKeyboardNavigation){$container.bind('keydown.jscrollpane',function(e)
{switch(e.keyCode){case 38:currentArrowDirection=-1;currentArrowInc=0;whileArrowButtonDown();currentArrowTimerArr[currentArrowTimerArr.length]=setInterval(whileArrowButtonDown,100);return false;case 40:currentArrowDirection=1;currentArrowInc=0;whileArrowButtonDown();currentArrowTimerArr[currentArrowTimerArr.length]=setInterval(whileArrowButtonDown,100);return false;case 33:case 34:return false;default:}}).bind('keyup.jscrollpane',function(e)
{if(e.keyCode==38||e.keyCode==40){for(var i=0;i<currentArrowTimerArr.length;i++){clearInterval(currentArrowTimerArr[i]);}
return false;}});}
if(settings.showArrows){var currentArrowButton;var currentArrowInterval;var onArrowMouseUp=function(event)
{$('html').unbind('mouseup',onArrowMouseUp);currentArrowButton.removeClass('jScrollActiveArrowButton');clearInterval(currentArrowInterval);};var onArrowMouseDown=function(){$('html').bind('mouseup',onArrowMouseUp);currentArrowButton.addClass('jScrollActiveArrowButton');currentArrowInc=0;whileArrowButtonDown();currentArrowInterval=setInterval(whileArrowButtonDown,100);};$container.append($('<a></a>').attr({'href':'javascript:;','className':'jScrollArrowUp','tabindex':-1}).css({'width':settings.scrollbarWidth+'px','top':settings.topCapHeight+'px'}).html('Scroll up').bind('mousedown',function()
{currentArrowButton=$(this);currentArrowDirection=-1;onArrowMouseDown();this.blur();return false;}).bind('click',rf),$('<a></a>').attr({'href':'javascript:;','className':'jScrollArrowDown','tabindex':-1}).css({'width':settings.scrollbarWidth+'px','bottom':settings.bottomCapHeight+'px'}).html('Scroll down').bind('mousedown',function()
{currentArrowButton=$(this);currentArrowDirection=1;onArrowMouseDown();this.blur();return false;}).bind('click',rf));var $upArrow=$('>.jScrollArrowUp',$container);var $downArrow=$('>.jScrollArrowDown',$container);}
if(settings.arrowSize){trackHeight=paneHeight-settings.arrowSize-settings.arrowSize;trackOffset+=settings.arrowSize;}else if($upArrow){var topArrowHeight=$upArrow.height();settings.arrowSize=topArrowHeight;trackHeight=paneHeight-topArrowHeight-$downArrow.height();trackOffset+=topArrowHeight;}
trackHeight-=settings.topCapHeight+settings.bottomCapHeight;$track.css({'height':trackHeight+'px',top:trackOffset+'px'})
var $pane=$(this).css({'position':'absolute','overflow':'visible'});var currentOffset;var maxY;var mouseWheelMultiplier;var dragPosition=0;var dragMiddle=percentInView*paneHeight/2;var getPos=function(event,c){var p=c=='X'?'Left':'Top';return event['page'+c]||(event['client'+c]+(document.documentElement['scroll'+p]||document.body['scroll'+p]))||0;};var ignoreNativeDrag=function(){return false;};var initDrag=function()
{ceaseAnimation();currentOffset=$drag.offset(false);currentOffset.top-=dragPosition;maxY=trackHeight-$drag[0].offsetHeight;mouseWheelMultiplier=2*settings.wheelSpeed*maxY/contentHeight;};var onStartDrag=function(event)
{initDrag();dragMiddle=getPos(event,'Y')-dragPosition-currentOffset.top;$('html').bind('mouseup',onStopDrag).bind('mousemove',updateScroll);if($.browser.msie){$('html').bind('dragstart',ignoreNativeDrag).bind('selectstart',ignoreNativeDrag);}
return false;};var onStopDrag=function()
{$('html').unbind('mouseup',onStopDrag).unbind('mousemove',updateScroll);dragMiddle=percentInView*paneHeight/2;if($.browser.msie){$('html').unbind('dragstart',ignoreNativeDrag).unbind('selectstart',ignoreNativeDrag);}};var positionDrag=function(destY)
{$container.scrollTop(0);destY=destY<0?0:(destY>maxY?maxY:destY);dragPosition=destY;$drag.css({'top':destY+'px'});var p=destY/maxY;$this.data('jScrollPanePosition',(paneHeight-contentHeight)*-p);$pane.css({'top':((paneHeight-contentHeight)*p)+'px'});$this.trigger('scroll');if(settings.showArrows){$upArrow[destY==0?'addClass':'removeClass']('disabled');$downArrow[destY==maxY?'addClass':'removeClass']('disabled');}};var updateScroll=function(e)
{positionDrag(getPos(e,'Y')-currentOffset.top-dragMiddle);};var dragH=Math.max(Math.min(percentInView*(paneHeight-settings.arrowSize*2),settings.dragMaxHeight),settings.dragMinHeight);$drag.css({'height':dragH+'px'}).bind('mousedown',onStartDrag);var trackScrollInterval;var trackScrollInc;var trackScrollMousePos;var doTrackScroll=function()
{if(trackScrollInc>8||trackScrollInc%4==0){positionDrag((dragPosition-((dragPosition-trackScrollMousePos)/2)));}
trackScrollInc++;};var onStopTrackClick=function()
{clearInterval(trackScrollInterval);$('html').unbind('mouseup',onStopTrackClick).unbind('mousemove',onTrackMouseMove);};var onTrackMouseMove=function(event)
{trackScrollMousePos=getPos(event,'Y')-currentOffset.top-dragMiddle;};var onTrackClick=function(event)
{initDrag();onTrackMouseMove(event);trackScrollInc=0;$('html').bind('mouseup',onStopTrackClick).bind('mousemove',onTrackMouseMove);trackScrollInterval=setInterval(doTrackScroll,100);doTrackScroll();return false;};$track.bind('mousedown',onTrackClick);$container.bind('mousewheel',function(event,delta){delta=delta||(event.wheelDelta?event.wheelDelta/120:(event.detail)?-event.detail/3:0);initDrag();ceaseAnimation();var d=dragPosition;positionDrag(dragPosition-delta*mouseWheelMultiplier);var dragOccured=d!=dragPosition;return!dragOccured;});var _animateToPosition;var _animateToInterval;function animateToPosition()
{var diff=(_animateToPosition-dragPosition)/settings.animateStep;if(diff>1||diff<-1){positionDrag(dragPosition+diff);}else{positionDrag(_animateToPosition);ceaseAnimation();}}
var ceaseAnimation=function()
{if(_animateToInterval){clearInterval(_animateToInterval);delete _animateToPosition;}};var scrollTo=function(pos,preventAni)
{if(typeof pos=="string"){$e=$(pos,$this);if(!$e.length)return;pos=$e.offset().top-$this.offset().top;}
ceaseAnimation();var maxScroll=contentHeight-paneHeight;pos=pos>maxScroll?maxScroll:pos;$this.data('jScrollPaneMaxScroll',maxScroll);var destDragPosition=pos/maxScroll*maxY;if(preventAni||!settings.animateTo){positionDrag(destDragPosition);}else{$container.scrollTop(0);_animateToPosition=destDragPosition;_animateToInterval=setInterval(animateToPosition,settings.animateInterval);}};$this[0].scrollTo=scrollTo;$this[0].scrollBy=function(delta)
{var currentPos=-parseInt($pane.css('top'))||0;scrollTo(currentPos+delta);};initDrag();scrollTo(-currentScrollPosition,true);$('*',this).bind('focus',function(event)
{var $e=$(this);var eleTop=0;while($e[0]!=$this[0]){eleTop+=$e.position().top;$e=$e.offsetParent();}
var viewportTop=-parseInt($pane.css('top'))||0;var maxVisibleEleTop=viewportTop+paneHeight;var eleInView=eleTop>viewportTop&&eleTop<maxVisibleEleTop;if(!eleInView){var destPos=eleTop-settings.scrollbarMargin;if(eleTop>viewportTop){destPos+=$(this).height()+15+settings.scrollbarMargin-paneHeight;}
scrollTo(destPos);}})
if(location.hash&&location.hash.length>1){setTimeout(function(){scrollTo(location.hash);},$.browser.safari?100:0);}
$(document).bind('click',function(e)
{$target=$(e.target);if($target.is('a')){var h=$target.attr('href');if(h&&h.substr(0,1)=='#'&&h.length>1){setTimeout(function(){scrollTo(h,!settings.animateToInternalLinks);},$.browser.safari?100:0);}}});function onSelectScrollMouseDown(e)
{$(document).bind('mousemove.jScrollPaneDragging',onTextSelectionScrollMouseMove);$(document).bind('mouseup.jScrollPaneDragging',onSelectScrollMouseUp);}
var textDragDistanceAway;var textSelectionInterval;function onTextSelectionInterval()
{direction=textDragDistanceAway<0?-1:1;$this[0].scrollBy(textDragDistanceAway/2);}
function clearTextSelectionInterval()
{if(textSelectionInterval){clearInterval(textSelectionInterval);textSelectionInterval=undefined;}}
function onTextSelectionScrollMouseMove(e)
{var offset=$this.parent().offset().top;var maxOffset=offset+paneHeight;var mouseOffset=getPos(e,'Y');textDragDistanceAway=mouseOffset<offset?mouseOffset-offset:(mouseOffset>maxOffset?mouseOffset-maxOffset:0);if(textDragDistanceAway==0){clearTextSelectionInterval();}else{if(!textSelectionInterval){textSelectionInterval=setInterval(onTextSelectionInterval,100);}}}
function onSelectScrollMouseUp(e)
{$(document).unbind('mousemove.jScrollPaneDragging').unbind('mouseup.jScrollPaneDragging');clearTextSelectionInterval();}
$container.bind('mousedown.jScrollPane',onSelectScrollMouseDown);$.jScrollPane.active.push($this[0]);}else{$this.css({'height':paneHeight+'px','width':paneWidth-this.originalSidePaddingTotal+'px','padding':this.originalPadding});$this[0].scrollTo=$this[0].scrollBy=function(){};$this.parent().unbind('mousewheel').unbind('mousedown.jScrollPane').unbind('keydown.jscrollpane').unbind('keyup.jscrollpane');}})};$.fn.jScrollPaneRemove=function()
{$(this).each(function()
{$this=$(this);var $c=$this.parent();if($c.is('.jScrollPaneContainer')){$this.css({'top':'','height':'','width':'','padding':'','overflow':'','position':''});$this.attr('style',$this.data('originalStyleTag'));$c.after($this).remove();}});}
$.fn.jScrollPane.defaults={scrollbarWidth:10,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false,tabIndex:0,enableKeyboardNavigation:true,animateToInternalLinks:false,topCapHeight:0,bottomCapHeight:0};$(window).bind('unload',function(){var els=$.jScrollPane.active;for(var i=0;i<els.length;i++){els[i].scrollTo=els[i].scrollBy=null;}});})(jQuery);
