//jquery.bind
;/**
 * @author trixta
 */
(function($){

$.bind = function(object, method){
    var args = Array.prototype.slice.call(arguments, 2);
    return function() {
        var args2 = [this].concat(args, $.makeArray( arguments ));
        return method.apply(object, args2);
    };
};
})(jQuery);
;

//jquery.imgpreload
;/**
 * @author alexander.farkas
 *
 * Usage Example:
 *
 *

$('#photo-index a').each(function(){
    $.imgPreLoad.add($(this).attr('href'));
});

 */
(function($){
    $.imgPreLoad = (function(){
        var srcList = [],
            ready = false,
            started = false,
            loaded = false;

        function loadImg(src, callback){
            var img = new Image();

            img.src = src;
            if(!img.complete){
                $(img)
                    .bind('load error readystatechange', callback);
            } else {
                callback.call(img, {type: 'cacheLoad'});
            }
        }

        function loadNextImg(){
            if(srcList.length && ready){
                started = true;
                var src = srcList.shift();
                loadImg(src, loadNextImg);
            } else {
                started = false;
            }
        }

        function pause(){
            started = false;
            ready = false;
        }

        function restart(){
            if(loaded) {
                ready = true;
                loadNextImg();
            }
        }

        function loadNow(src, callback){
            pause();
            var fn =    function(e){
                (callback && callback(this, e));
                restart();
            };
            loadImg(src, fn);
        }

        return {
            add: function(src,  priority){
                if(priority){
                    srcList.unshift(src);
                } else {
                    srcList.push(src);
                }
                if(ready && !started){
                    loadNextImg();
                }
            },
            loadNow: loadNow,
            ready: function(){
                loaded = true;
                ready = true;
                loadNextImg();
            }
        };
    })();
    $(window).bind('load', $.imgPreLoad.ready);
})(jQuery);


;

//jquery.objscale
;/**
 * @author alexander.farkas
 */
/**
* JS-Singelton-Klasse um Objekte (zum Beispiel Bilder) zu skalieren
* @id objScaleModule
* @alias $.objScale
* @alias jQuery.objScale
*/

/**
 * Berechnet die Höhe und Breite von DOM-Objekten
 *
 * @id getDim
 * @method
 * @alias $.objScale.getDim
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein Objekt mit den Eigenschaften width und height.
 * @return {Object} gibt ein Objekt mit höhe und Breite zurück. Beispiel. {height: 200, width: 300}
 */
/**
 * Berechnet eine verhältnismäßige Skalierung eines Objekts.<br>
 * siehe auch: $.objScale.scaleHeightTo und $.objScale.scaleWidthTo
 *
 * @id scaleTo
 * @method
 * @alias $.objScale.scaleTo
 * @see #scaleHeightTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein Objekt welches skaliert werden soll.
 * @param {Number} num num erwartet die neue Grösse, welche das Objekt haben soll (Breite oder Höhe)
 * @param {String} side gibt an welche Seite (Höhe oder Breite) man im 2. Parameter angegeben hat
 * @return {Number} gibt die neue Länge zurück (Wenn man unter num/side 'width' angegeben hat, wird die Höhe zurückgeliefert).
 */
/**
 * Skaliert die Höhe eines Objekts und gibt die verhältnismäßige Breite zurück.<br>
 * (Shorthand für $.objScale.scaleTo(obj, num, 'height');)
 *
 * @id scaleHeightTo
 * @method
 * @alias $.objScale.scaleHeightTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein Objekt welches skaliert werden soll.
 * @param {Number} num num erwartet die neue Höhe, welche das Objekt haben soll
 * @return {Number} gibt die neue Breite zurück
 */
/**
 * Skaliert die Breite eines Objekts und gibt die verhältnismäßige Höhe zurück.<br>
 * (Shorthand für $.objScale.scaleTo(obj, num, 'width');)
 *
 * @id scaleWidthTo
 * @method
 * @alias $.objScale.scaleWidthTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein Objekt welches skaliert werden soll.
 * @param {Number} num num erwartet die neue Breite, welche das Objekt haben soll
 * @return {Number} gibt die neue Höhe zurück
 */

/**
 * Skaliert die Breite eines Objekts und gibt die verhältnismäßige Höhe zurück.<br>
 * (Shorthand für $.objScale.scaleTo(obj, num, 'width');)
 *
 * @id scaleWidthTo
 * @method
 * @alias $.objScale.scaleWidthTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein Objekt welches skaliert werden soll.
 * @param {Number} num num erwartet die neue Breite, welche das Objekt haben soll
 * @return {Number} gibt die neue Höhe zurück
 */
/**
 * Zentriert ein kleineres Objekt in einem Grösseren.<br>
 * siehe auch: $.objScale.constrainObjTo();
 *
 * @id centerObjTo
 * @method
 * @alias $.objScale.centerObjTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  welches zentriert werden soll.
 * @param {Object} container erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  in welches das andere Objekt zentriert werden soll
 * @param {Object, Options} opts stellt Optionen bereit so kann angegeben werden, ob es einen Mindest nach oben bzw. links geben soll (margin: [10, false]) und, ob vertical und / oder horizontal zentriert werden soll<br><br>
 * Beispiel:<br>
 * $.objScale.centerObjTo(img, container, {margin: [10, 0], horizontal: false};<br>
 * Es soll nur vertical und nicht horizontal zentriert werden, ausserdem soll der Mindestabstand nach oben 10 Einheiten betragen<br><br>
 * $.objScale.centerObjTo(img, container, {margin: [false, 0]};<br>
 * Es soll vertical und horizontal zentriert werden, ausserdem soll der Mindestabstand nach links 0 Einheiten betragen und nach oben existiert keine Mindestbeschränkung (Es können negative Werte auftreten).<br><br>
 * defaults: {margin: [0, 0], vertical: true, horizontal: true}
 * @return {Object} gibt ein Objekt mit top und left Eigenschaften zurück
 */
/**
 * Zentriert ein Objekt in einem anderen Objekt. Ist das zu skalierende Objekt grösser, wird es zusätzlich verkleinert.<br>
 * siehe auch: $.objScale.centerObjTo(); und $.objScale.scaleObjTo();
 * @id constrainObjTo
 * @method
 * @alias $.objScale.constrainObjTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  welches angepasst und zentriert werden soll.
 * @param {Object} container erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  in welches das andere Objekt zentriert werden soll
 * @param {Object, Options} opts stellt Optionen bereit so kann angegeben werden, ob es einen Mindestabstand nach oben bzw. links geben soll (margin: [10, false], padding: [10, 0]) und ob vertical und / oder horizontal zentriert werden soll<br><br>
 * Unterschied zwischen padding und margin: Die margin- und padding-Angaben werden für die evtl. Verkleinerung des Objekts berücksichtigt. Bei einer möglichen Zentrierung wird dagegen ausschließlich der margin-Wert berücksichtigt. Das padding-Array darf daher nur Zahlen enthalten, das margin-Array darf daneben noch den booleschen Wert false enthalten.
 * Beispiel:<br>
 * $.objScale.constrainObjTo(img, container, {margin: [10, 0], horizontal: false};<br>
 * Es soll nur vertical und nicht horizontal zentriert werden, ausserdem soll der Mindestabstand nach oben 10 Einheiten betragen<br><br>
 * defaults: {margin: [0, 0], padding: [0, 0], vertical: true, horizontal: true}
 * @return {Object} gibt ein Objekt mit width, height, top und left Eigenschaften zurück
 */
/**
 * Skaliert ein Objekt, so dass es perfekt in ein anderes Objekt passt und zentriert es. (Ist es kleiner, wird es vergrössert bzw. ist grösser, wird es verkleinert).<br>
 * siehe auch: $.objScale.centerObjTo(); und $.objScale.constrainObjTo();
 * @id scaleObjTo
 * @method
 * @alias $.objScale.scaleObjTo
 * @param {Object} obj obj erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  welches skaliert und zentriert werden soll.
 * @param {Object} container erwartet ein DOM-Objekt, ein jQuery-Objekt oder ein anderes Objekt mit Höhen und Breiten-Eigenschaften,  in welches das andere Objekt zentriert/skaliert werden soll
 * @param {Object, Options} opts stellt Optionen bereit so kann angegeben werden, ob es einen Mindestabstand nach oben bzw. links geben soll (margin: [10, false], padding: [10, 0]), ob vertical und / oder horizontal zentriert werden soll. Die scaleToFit-Eigenschaft gibt an, ob bei unterschiedlichen Seitenverhältnissen das innere Objekt vollständig zu sehen sein soll oder ob es das äußere Objekt vollständig ausfüllen soll<br><br>
 * Unterschied zwischen padding und margin: Die margin- und padding-Angaben werden für die evtl. Skalierung des Objekts berücksichtigt. Bei einer möglichen Zentrierung wird dagegen ausschließlich der margin-Wert berücksichtigt. Das padding-Array darf daher nur Zahlen enthalten, das margin-Array darf daneben noch den booleschen Wert false enthalten.
 * Beispiel:<br>
 * $.objScale.scaleObjTo(img, container, {margin: [10, 0], horizontal: false};<br>
 * Es soll nur vertical und nicht horizontal zentriert werden, ausserdem soll der Mindestabstand nach oben 10 Einheiten betragen<br><br>
 * defaults: {margin: [false, false], padding: [0, 0], scaleToFit: false, vertical: true, horizontal: true}
 * @return {Object} gibt ein Objekt mit width, height, top und left Eigenschaften zurück
 */
(function($){
    /**
     * @id objScaleModule
     */
    $.objScale = (function(){

    /**
     * @id getDim
     */
        function getDim(obj){
            var height,
                width,
                ret = (obj.jquery) ?
                        {
                            height: obj.height(),
                            width: obj.width()
                        } :
                        (isFinite(obj.width) && isFinite(obj.height)) ?
                        {width: obj.width, height: obj.height} :
                        getDim($(obj));
            return ret;
        }

        /**
         * @id scaleTo
         */
        function scaleTo(obj, num, side){
            var cur = getDim(obj),
                percentage,
                reverseSide = (side == 'height') ?
                    'width' :
                    'height';

            percentage = cur[side] / num;
            return cur[reverseSide] / percentage;
        }

        /**
         * @id scaleHeightTo
         */
        function scaleHeightTo(obj, height){
            return scaleTo(obj, height, 'height');
        }

        /**
         * @id scaleWidthTo
         */
        function scaleWidthTo(obj, width){
            return scaleTo(obj, width, 'width');
        }

        /**
         * @id constrainObjTo
         */
        function constrainObjTo(obj, container, opts){
            opts = $.extend({
                margin: [0, 0],
                padding: [0, 0]
            }, opts);
            var cur = getDim(obj),
                con = getDim(container),
                maxWidth = con.width - opts.padding[1],
                maxHeight = con.height - opts.padding[0],
                estimatetPer = con.height / con.width,
                curPer = cur.height / cur.width,
                ret = $.extend({},cur);
            if(opts.margin[1]){
                maxWidth -=  opts.margin[1];
            }
            if(opts.margin[0]){
                maxHeight -=  opts.margin[0];
            }
            if(estimatetPer < curPer && maxHeight < cur.height){
                ret.width = scaleTo(obj, maxHeight, 'height');
                ret.height = maxHeight;
            } else if(maxWidth < cur.width){
                ret.width = maxWidth;
                ret.height = scaleTo(obj, maxWidth, 'width');
            }

            ret.widthSubtraction = ret.width - cur.width;
            ret.heightSubtraction = ret.height - cur.height;
            $.extend(ret, centerObjTo(ret, con, opts));
            return ret;
        }

        /**
         * @id centerObjTo
         */
        function centerObjTo(obj, container, opts){
            opts = $.extend({
                margin: [0, 0],
                vertical: true,
                horizontal: true
            }, opts);
            var cur = getDim(obj),
                con = getDim(container),
                ret = {};
            if(opts.vertical){
                ret.top = (con.height - cur.height) / 2;
                if (isFinite(opts.margin[0])) {
                    ret.top = Math.max(ret.top, opts.margin[0]);
                }
            }

            if(opts.horizontal){
                ret.left =  (con.width - cur.width) / 2;
                if(isFinite(opts.margin[1])){
                    ret.left = Math.max(ret.left, opts.margin[1]);
                }
            }
            return ret;
        }

        /**
         * @id scaleObjTo
         */
        function scaleObjTo(obj, container, opts){
            opts = $.extend({
                margin: [false, false],
                padding: [0, 0],
                scaleToFit: false
            }, opts);

            var cur = getDim(obj),
                con = getDim(container),
                curPer = cur.height / cur.width,
                ret = {};

            con.maxHeight = con.height - opts.padding[0];
            con.maxWidth = con.width - opts.padding[1];

            if(opts.margin[0]){
                con.maxHeight -= opts.margin[0];
            }
            if(opts.margin[1]){
                con.maxWidth -= opts.margin[1];
            }

            var estimatetPer = con.maxHeight / con.maxWidth;

            if(opts.scaleToFit !== estimatetPer > curPer){
                ret.width = con.maxWidth;
                ret.height = scaleTo(obj, con.maxWidth, 'width');
            } else {
                ret.width = scaleTo(obj, con.maxHeight, 'height');
                ret.height = con.maxHeight;
            }

            $.extend(ret, centerObjTo(ret, con, opts));
            return ret;
        }

        return {
            scaleWidthTo: scaleWidthTo,
            scaleHeightTo: scaleHeightTo,
            scaleSidesIn: scaleObjTo, /* dep */
            scaleObjTo: scaleObjTo,
            constrainObjTo: constrainObjTo,
            getDim: getDim,
            centerObjTo: centerObjTo
        };
    })();
})(jQuery);
;

//posFixedfix
;/**
 * @author alexander.farkas
 */
/**
 * @author alexander.farkas
 */

var aperto = aperto ||
    {};

aperto.posFixedFix = (function(){
    var doc = document.documentElement || document.body;

    function left(css){
        return doc.scrollLeft + css + 'px';
    }

    function top(css){
        return doc.scrollTop + css + 'px';
    }

    function bottom(css){
        return doc.scrollTop + doc.clientHeight - css + 'px';
    }
    function right(css){
        return doc.scrollLeft + doc.clientWidth - css + 'px';
    }

    return {
        left: left,
        top: top,
        bottom: bottom,
        right: right
    };
})();


(function($){
    var fixedElems = 0, bodyBgAttach;
    $.fn.removePosFixedFix = function(){
        if ($.browser.msie && $.browser.version < 7 && this[0] && this[0].style && this[0].removeExpression) {

            return this.each(function(){
                var jElm = $(this),
                    origPos = $.data(jElm[0], 'origFixedPos', origPos);
                if(origPos){
                    jElm.css(origPos);
                    this.style.removeExpression('top');
                    this.style.removeExpression('left');
                    $.data(jElm[0], 'origFixedPos', null);
                    fixedElems--;
                }
                if(!fixedElems){
                    $('body').css('backgroundAttachment', bodyBgAttach);
                }
            });
        } else {
            return this;
        }
    };

    $.fn.posFixedFix = function(opts){
        if($.browser.msie && $.browser.version < 7 && this[0] && this[0].style && this[0].setExpression){
            var defaults = {
                top: false,
                bottom: false,
                left: false,
                right: false,
                flicker: false
            };
            if(!opts || typeof opts == "boolean"){
                opts = {
                    flicker: opts
                };
            }
            opts = $.extend(defaults, opts);

            if(!opts.flicker){
                var body = $('body');
                bodyBgAttach = bodyBgAttach ||
                    body.css('backgroundAttachment');
                body.css('backgroundAttachment', 'fixed');
            }
            //adjustPostop
            return this.each(function(){
                var jElm = $(this),
                    css,
                    type,
                    doneSomething = false,
                    origPos = $.data(jElm[0], 'origFixedPos') ||
                        {};
                this.style.position = 'absolute';
                $.each(['top', 'left', 'bottom', 'right'], function(i, item){
                    css = opts[item] ||
                        jElm.css(item);
                    type = item;
                    if(!origPos[type]) {
                        origPos[type] = css;
                    }
                    css = parseFloat(css);
                    if(isFinite(css)){
                        $.data(jElm[0], 'origFixedPos', origPos);
                        if(item == 'bottom'){
                            css += jElm.outerHeight();
                            jElm[0].style.bottom = 'auto';
                            type = 'top';
                        } else if(item == 'right'){
                            css += jElm.outerWidth();
                            jElm[0].style.right = 'auto';
                            type = 'left';
                        }
                        jElm[0].style.setExpression(type, "aperto.posFixedFix."+item+"("+css+")");
                        doneSomething = true;
                    }
                });

                if(doneSomething){
                    fixedElems++;
                }
            });
        } else {
            return this;
        }
    };

})(jQuery);;

//jquery.bgiframe
;/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-07-21 18:44:59 -0500 (Sat, 21 Jul 2007) $
 * $Rev: 26246 $
 *
 * Version 2.1.1
 */

(function($){

/**
 * The bgiframe is chainable and applies the iframe hack to get
 * around zIndex issues in IE6. It will only apply itself in IE6
 * and adds a class to the iframe called 'bgiframe'. The iframe
 * is appeneded as the first child of the matched element(s)
 * with a tabIndex and zIndex of -1.
 *
 * By default the plugin will take borders, sized with pixel units,
 * into account. If a different unit is used for the border's width,
 * then you will need to use the top and left settings as explained below.
 *
 * NOTICE: This plugin has been reported to cause perfromance problems
 * when used on elements that change properties (like width, height and
 * opacity) a lot in IE6. Most of these problems have been caused by
 * the expressions used to calculate the elements width, height and
 * borders. Some have reported it is due to the opacity filter. All
 * these settings can be changed if needed as explained below.
 *
 * @example $('div').bgiframe();
 * @before <div><p>Paragraph</p></div>
 * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
 *
 * @param Map settings Optional settings to configure the iframe.
 * @option String|Number top The iframe must be offset to the top
 *      by the width of the top border. This should be a negative
 *      number representing the border-top-width. If a number is
 *      is used here, pixels will be assumed. Otherwise, be sure
 *      to specify a unit. An expression could also be used.
 *      By default the value is "auto" which will use an expression
 *      to get the border-top-width if it is in pixels.
 * @option String|Number left The iframe must be offset to the left
 *      by the width of the left border. This should be a negative
 *      number representing the border-left-width. If a number is
 *      is used here, pixels will be assumed. Otherwise, be sure
 *      to specify a unit. An expression could also be used.
 *      By default the value is "auto" which will use an expression
 *      to get the border-left-width if it is in pixels.
 * @option String|Number width This is the width of the iframe. If
 *      a number is used here, pixels will be assume. Otherwise, be sure
 *      to specify a unit. An experssion could also be used.
 *      By default the value is "auto" which will use an experssion
 *      to get the offsetWidth.
 * @option String|Number height This is the height of the iframe. If
 *      a number is used here, pixels will be assume. Otherwise, be sure
 *      to specify a unit. An experssion could also be used.
 *      By default the value is "auto" which will use an experssion
 *      to get the offsetHeight.
 * @option Boolean opacity This is a boolean representing whether or not
 *      to use opacity. If set to true, the opacity of 0 is applied. If
 *      set to false, the opacity filter is not applied. Default: true.
 * @option String src This setting is provided so that one could change
 *      the src of the iframe to whatever they need.
 *      Default: "javascript:false;"
 *
 * @name bgiframe
 * @type jQuery
 * @cat Plugins/bgiframe
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 */
$.fn.bgIframe = $.fn.bgiframe = function(s) {
    // This is only for IE6
    if ( $.browser.msie && parseInt($.browser.version) < 7) {
        s = $.extend({
            top     : 'auto', // auto == .currentStyle.borderTopWidth
            left    : 'auto', // auto == .currentStyle.borderLeftWidth
            width   : 'auto', // auto == offsetWidth
            height  : 'auto', // auto == offsetHeight
            opacity : true,
            src     : 'javascript:false;'
        }, s || {});
        var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
            html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
                       'style="display:block;position:absolute;z-index:-1;'+
                           (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
                           'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
                           'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
                           'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
                           'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
                    '"/>';
        return this.each(function() {
            if ( $('> iframe.bgiframe', this).length == 0 )
                this.insertBefore( document.createElement(html), this.firstChild );
        });
    }
    return this;
};

})(jQuery);;

//showbox
;/**
 * @author alexander.farkas
 *
 */
(function($){
    $.aperto = $.aperto ||
        {};

    $.widget('aperto.overlay', {
        _init: function(){
            var o = this.options;
            if(o.bgiframe && $.fn.bgIframe){
                this.element.bgIframe(o.bgiframe);
            }
            if(o.initHide){
                this.element.hide();
            }
            this.reFocusElm = null;
            this.element.attr({
                'aria-hidden': (this.element.is(':visible')) ?
                    'false' :
                    'true'
            });
        },

        overrideAnim: function(anim, animOpts, defaultOpts, fn){
            var self = this, oldComplete;
            animOpts = animOpts ||
                defaultOpts;

            oldComplete = animOpts.complete ||
                function(){};

            animOpts.complete = function(){
                oldComplete.call(self.element[0]);
                fn.call(self);
            };

            this.element[anim](animOpts);
        },

        show: function(anim, animOpts, elm, e){
            var o = this.options;
            anim = anim ||
                o.showAnim;
            if(this.element.is(':visible')){
                return true;
            }
            if(o.posStyle == 'fixed' && $.browser.msie){
                this.element
                    .posFixedFix();
            }
            function show(){
                this.element
                    .css({'display': 'block'})
                    .attr({'aria-hidden': 'false'});
                this.propagate('show', e, elm);
            }
            this.propagate('beforeshow', e, elm);
            if(anim){
                this.overrideAnim(anim, animOpts, o.showOptions, show);
            } else {
                show.call(this);
            }

        },

        hide: function(anim, animOpts, elm, e){
            var o = this.options;
            function hide(){
                this.element
                    .css({'display': 'none'})
                    .attr({'aria-hidden': 'true'});
                if(this.options.posStyle == 'fixed'){
                    this.element
                        .removePosFixedFix();
                }
                this.propagate('hide', e);
            }


            if(!this.element.is(':visible')){
                return true;
            }
            anim = anim ||
                o.hideAnim;
            this.propagate('beforehide');
            if(anim){
                this.overrideAnim(anim, animOpts, o.hideOptions, hide);
            } else {
                hide.call(this);
            }

        },
        ui: function(){
            return {
                instance: this,
                options: this.options
            };
        },
        propagate: function(n, e, elm){
            var args = [e, $.extend(this.ui(), {openedBy: elm})];
            this.element.triggerHandler(this.widgetName + n, args);
        },
        calcDim: {
            view: function(dim){
                return $(window)[dim]();
            },
            doc: function(){
                return $(document)[dim]();
            }
        },
        createDimension: function(dim){
            var o = this.options,
                self = this,
                normal = false,
                oName = dim.toLowerCase(),
                tmp = {},
                ret, calcVal;
            $.each(['normal', 'max', 'min'], function(i, item){
                calcVal = o[oName][item];
                if(calcVal){
                    if(isFinite(calcVal)){
                        tmp[item] = calcVal;
                    } else if(self.calcDim[calcVal]){
                        tmp[item] = self.calcDim[calcVal](oName);
                    }
                } else if(item == 'normal') {
                    tmp.normal =  self.element['inner'+dim]();
                    normal = tmp.normal;
                }
            });

            ret = tmp.normal;
            if(tmp.max){
                ret = Math.min(ret, tmp.max);
            }
            if(tmp.min){
                ret = Math.max(ret, tmp.min);
            }
            ret  = (normal !== ret) ?
                ret :
                false;
            return ret;
        },
        createPosition: function(){
            var self = this,
                o = this.options,
                placePos = o.placePos,
                dimNames = ['Width', 'Height'],
                pos = ['Left', 'Top'],
                ret = {},
                dim,
                view;

            $.each(['horizontal', 'vertical'], function(i, item){
                if(placePos[item]){
                    dim = self.element['outer'+dimNames[i]]();
                    view = $(window)[dimNames[i].toLowerCase()]();
                    ret[pos[i].toLowerCase()] = (view / 2) - (dim / 2);
                    if(o.posStyle == 'absolute'){
                        ret[pos[i].toLowerCase()] +=  $(document)['scroll'+pos[i]]();
                    }

                }
            });

            this.element
                .css(ret);

            return ret;
        }
    });
    $.aperto.overlay.defaults = {
        bgiframe: {},
        showAnim: false,
        showOptions: {},
        hideAnim: false,
        hideOptions: {},
        initHide: true,
/*
width: {
            normal: false,
            min: 200,
            max: false
        },
        height: {
            normal: false,
            min: 200,
            max: false
        },
        placePos: {
            horizontal: true,
            vertical: true
        },
*/
        posStyle: 'absolute'
    };
})(jQuery);
(function($){
    $.fn.overlayAnim = function(){
        return this.each(function(){
            var jElm = $(this);
            if(jElm.is(':hidden')){
                jElm
                    .animate({
                        opacity: 0.8
                    })
                    .css({display: 'block'});
            } else {
                jElm
                    .animate({
                        opacity: 0,
                        complete: function(){
                            jElm.css({display: 'none'});
                        }
                    });
            }
        });
    };
})(jQuery);
/**
 * @author alexander.farkas
 */
(function($){
    $.aperto = $.aperto ||
        {};
    var tabI = ($.browser.msie) ?
        'tabIndex' :
        'tabindex';
    $.widget('aperto.apertoDialog', $.extend({}, $.aperto.overlay.prototype, {
        _init: function(){
            this.element
                .attr({
                    role: 'dialog',
                    tabindex: tabI
                });

            if(!this.element.attr('id')){
                this.element.attr('id', 'dialog-id-'+ new Date().getTime());
            }

            $.aperto.overlay.prototype._init.call(this);

        },
        open: function(anim, animOpts, elm, e){
            var o = this.options,
                self = this;
            /*
this.element.css({
                height: this.createDimension('Height'),
                width: this.createDimension('Width')
            });
            this.createPosition();
*/
            this.reFocusElm = elm;
            this.show(anim, animOpts, elm, e);
            if(o.focusOnOpen && self.element[0].focus){
                setTimeout(function(){
                    self.element[0].focus();
                }, 180);
            }

        },

        close: function(anim, animOpts, elm, e){
            var o = this.options,
                self = this;
            if(o.resetFocusOnClose && this.reFocusElm){

                setTimeout(function(){
                    self.reFocusElm.focus();
                    self.reFocusElm = null;
                }, 180);
            }
            this.hide(anim, animOpts, elm, e);

        }

    }));

    $.aperto.apertoDialog.defaults = $.extend({}, $.aperto.overlay.defaults, {
        focusOnOpen: true,
        resetFocusOnClose: true
    }, true);

    /*
function createDialogControler(elm, obj, fn){
        var jElm = $(elm);
        jElm
            .bind('click', $.bind(obj, fn))
            .attr({
                'aria-haspopup': 'true',
                'aria-describedby': obj.element.attr('id')
            });
    }

    $.aperto.apertoDialog.createToggler = function(elms, obj){
        createDialogControler(this, obj, function(elm, e){
            if(this.element.is(':visible')){
                this.close(null, null, elm, e);
            } else {
                this.reFocusElm = elm;
                this.open(null, null, elm, e);
            }
            return false;
        });
    };

    $.aperto.apertoDialog.createCloser = function(elms, obj){
        createDialogControler(elms, obj, function(elm, e){
            this.close(null, null, elm, e);
            return false;
        });
    };
    $.aperto.apertoDialog.createOpener = function(elms, obj){
        createDialogControler(elms, obj, function(elm, e){
            this.reFocusElm = elm;
            this.open(null, null, elm, e);
            return false;
        });
    };
*/
jQuery.easing.jswing = jQuery.easing.swing;

jQuery.extend( jQuery.easing,
{
    def: 'easeOutQuad',
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    }
});
    $.widget('aperto.showbox', {
        _init: function(){
            var o = this.options,
                self = this,
                uniqueUrls = [],
                lastUrlIndex;

            this.controls = $(o.controls, this.element[0])
                .bind('click', $.bind(this, this.controlClick));

            this.overlay = $('<div id="showbox-overlay"></div>')
                .css({display: 'none'})
                .appendTo('body')
                .overlay({
                    'showAnim': 'overlayAnim',
                    posStyle: 'fixed'
                })
                .bind('click', $.bind(this, this.close) );

            o.showboxStructure = o.showboxStructure
                .replace('{prev}', o.prev)
                .replace('{next}', o.next)
                .replace('{close}', o.close);


            if($.browser.msie && parseInt($.browser.version, 10) < 7){
                this.overlay.bind('resize', $.bind(this, this.overlayResize));
                this.overlayResize();
            }


            this.dialog = $(o.showboxStructure)
                .css({display: 'none'})
                .appendTo('body')
                .apertoDialog({
                    posStyle: o.dialogPosStyle
                });

            this.contentReady = false;
            this.contentHideReady = false;

            this.uniqueUrls = [];

            this.controls.each(function(i){
                var url = $(this).attr('href');
                if($.inArray(url, uniqueUrls) == -1){
                    uniqueUrls.push(url);
                    self.uniqueUrls.push({index: i, url: url});
                    lastUrlIndex = i;
                }
            });

            this.lastUrlIndex = lastUrlIndex;

            $('a.close', this.dialog[0])
                .bind('click', $.bind(this, this.close));
            this.nextControl = $('a.next', this.dialog[0])
                .bind('click', function(e){
                    self.prevNext(1);
                });
            this.prevControl = $('a.prev', this.dialog[0])
                .bind('click', function(e){
                    self.prevNext(-1);
                });

            if(uniqueUrls.length <= 1){
                $('a', this.dialog[0]).filter('.prev, .next').hide();
            }
        },
        overlayResize: function(){
            var css = {
                height: $(window).height(),
                width: $(window).width()
            };
            this.overlay.css(css);
        },
        getIndexByUrl: function(url, dir){
            var found = false,
                self = this;

            $.each(this.uniqueUrls, function(i, item){
                if(item.url == url){
                    if(self.uniqueUrls[i+dir]){
                        found = self.uniqueUrls[i+dir].index;
                    }
                    return false;
                }
            });
            return found;
        },
        prevNext: function(dir){
            var estimatetElement = this.getIndexByUrl(this.indexUrl, dir);

            if(estimatetElement || estimatetElement === 0){
                estimatetElement = $(this.controls[estimatetElement]);
                this.getContents(estimatetElement, estimatetElement.attr('href'));
            }
            return false;
        },
        contentFilter: {
            img: /\.jpg$|\.gif$|\.jpeg$|\.png$/
        },
        getMultiMediaContent: {
            img: function(src, elm){
                var self = this;
                function loaded(img){

                    var dim = $.objScale.getDim(img);
                    self.showOpen.call(self, dim, '<img src="'+src+'" alt="" />', self.text, elm);
                }

                $.imgPreLoad.loadNow(src, loaded);
            }
        },
        fillContent: function(showbox, mm_C, text_C, animate){
            var self = this;
            function fill(){
                var extra = '';

                if(mm_C){
                    mm_C = $(mm_C).stop(true, true).css({opacity: 0});
                }
                $('.multimedia-box', showbox[0]).html(mm_C);
                if(mm_C){
                    $(mm_C).stop(true, true).animate({opacity: 1});
                }
                $('.caption', showbox[0]).html(text_C.caption);
                $('.longdesc', showbox[0]).html(text_C.longdesc);
                $.each(text_C.extra, function(prop, value){
                    extra += '<li class="'+prop+'">'+value+'</li>';
                });
                $('ul.sb-extra', showbox[0]).remove();
                if(extra){
                    $('.text-content', showbox[0]).append('<ul class="sb-extra">'+extra+'</ul>');
                }
            }
            fill();
        },
        deleteContent: function(){
            this.fillContent(this.dialog, '', {caption: '', longdesc: '', extra: ''});
        },
        close: function(){
            this.dialog.apertoDialog('close');
            this.overlay.overlay('hide');
            this.deleteContent();
            $(document).unbind('keydown.apertoDialog');
            return false;
        },
        centerBox: function(elm){
            var o = this.options,
                dimension = $.objScale[(o.constrainToView) ?
                    'constrainObjTo' :
                    'centerObjTo'](elm, $(window), {
                        margin: o.margin, padding: o.padding, vertical: (o.top == 'middle'), horizontal: (o.left == 'center')
                    });

            if(isFinite(o.top)){
                dimension.top = o.top;
            }

            if(isFinite(o.left)){
                dimension.top = o.left;
            }

            if(o.dialogPosStyle == 'absolute'){
                dimension.top += $(document).scrollTop();
                dimension.left += $(document).scrollLeft();
            }
            return dimension;
        },
        showOpen: function(dim, mm_C, text_C, openElement){
            text_C = text_C ||
                this.text;
            var o = this.options,
                self = this,
                center,
                holeDialog = this.dialog.find('*').andSelf(),
                centerBox = holeDialog.filter(o.posBox),
                widthBox = holeDialog.filter(o.widthBox),
                testDiv = $(o.showboxStructure)
                    .css({visibility: 'hidden'})
                    .appendTo('body'),
                holeTestDialog = testDiv.find('*').andSelf(),
                testCenterBox = holeTestDialog.filter(o.posBox),
                testWidthBox = holeTestDialog.filter(o.widthBox);

            function removeHeight(){
                centerBox.css('height', '');
            }

            this.overlay
                .overlay('show');



            //if(o.calcDimension){

            testWidthBox.css('width', dim.width);
            //}
            $('.multimedia-box', testDiv[0]).css('height', dim.height);

            this.fillContent(testDiv, '', text_C);
            center = this.centerBox(testCenterBox, false);

            testDiv.remove();

            if(isFinite(center.heightSubtraction) || isFinite(center.widthSubtraction)){
                dim.width += center.widthSubtraction;
                dim.height += center.heightSubtraction;
                delete center.heightSubtraction;
                delete center.widthSubtraction;
            }
            /*
            if(!o.calcDimension){
                dim = null;
                delete center.width;
                delete center.height;

            }
            */

            if(!this.dialog.is(':hidden')){
                $('.multimedia-box', this.dialog[0]).animate(dim, {
                    duration: 200,
                    easing: 'easeOutQuad'
                });

                widthBox.animate({width: dim.width}, {queue: false, duration: 200, easing: 'easeOutQuad'});
                delete center.width;
                centerBox.animate(center,{
                    duration: 200,
                    complete: function(){
                        self.fillContent.call(self, self.dialog, mm_C, text_C);
                        removeHeight();
                    },
                    queue: false,
                    easing: 'easeOutQuad'
                });
                this.dialog.removeClass('loading');

            } else {
                delete center.height;
                widthBox.css({width: dim.width});
                delete center.width;
                centerBox.css(center);
                this.fillContent(this.dialog, mm_C, text_C);
                if(dim){
                    $('.multimedia-box', this.dialog[0])
                        .css(dim);
                }
                this.dialog.apertoDialog('open', o.openAnim, o.openAnimOpts, openElement);
                $(document).bind('keydown.apertoDialog', function(e){

                    switch(e.keyCode) {
                        case $.ui.keyCode.ESCAPE:
                            self.close();
                            break;
                        case $.ui.keyCode.RIGHT:
                            self.prevNext(1);
                            break;
                        case $.ui.keyCode.LEFT:
                            self.prevNext(-1);
                            break;
                    }

                });
            }
        },
        collectTextContent: function(control){
            var o = this.options,
                parent = control.parents(o.parentContainerSel),
                ret = {extra:{}};
            $(o.extraContentSel,parent[0]).each(function(){
                var jElm = $(this);
                if(jElm.is(o.captionSel)){
                    ret.caption = jElm.html();
                } else if(jElm.is(o.longdescSel)){
                    ret.longdesc = jElm.html();
                } else {
                    ret.extra[this.className.split(' ').join('_')] = jElm.html();
                }
            });
            return ret;
        },
        controlClick: function(elm, e){
            //e.preventDefault();

            var self = this,
                control = $(elm);

            this.overlay
                .overlay('open');
            return this.getContents(control);
        },
        createIndex: function(element){
            this.indexUrl = element.attr('href');

            if(this.getIndexByUrl(this.indexUrl, -1) === false){
                this.prevControl
                    .addClass('disabled');
            } else {
                this.prevControl
                    .removeClass('disabled');
            }

            if(this.getIndexByUrl(this.indexUrl, 1) === false){
                this.nextControl
                    .addClass('disabled');
            } else {
                this.nextControl
                    .removeClass('disabled');
            }

        },
        getContents: function(control){
            var o = this.options,
                self = this,
                testUrl,
                passDefaultAction = true;
            this.dialog.addClass('loading');
            if (!this.dialog.is(':hidden')) {
                this.deleteContent('hide');

            }

            this.contentReady = false;


            this.createIndex(control);

            if(o.getUpDownforContent){
                this.text = this.collectTextContent(control);
            }

            testUrl = this.indexUrl.toLowerCase();

            $.each(this.contentFilter, function(prop, val){
                if(val.test(testUrl)){
                    self.getMultiMediaContent[prop].call(self, self.indexUrl, control);
                    passDefaultAction = false;
                    return false;
                }
            });
            return passDefaultAction;
        }
    });
    $.aperto.showbox.defaults = {
        //Structure
        controls: 'a[rel=showbox]',
        showboxStructure: '<div id="showbox"><div class="controls"><span class="prev-next"><a href="#" class="prev">{prev}</a> <a href="#" class="next">{next}</a></span> <a href="#" class="close">{close}</a></div><div class="content-box"><div class="multimedia-box"></div><div class="text-content"><h2 class="caption"></h2><p class="longdesc"></p></div></div></div>',

        //getContent
        getUpDownforContent: true, //false -> title-Attribut
        parentContainerSel: 'dl',
        captionSel:'dd.caption',
        longdescSel:'dd.longdesc',
        extraContentSel:'dd:not(.zoom)',

        //Localization
        prev: 'previous',
        next: 'next',
        close: 'close',


        //Animation
        //openAnim: false,
        //openAnimOpts: false,


        //position
        dialogPosStyle: 'fixed',
        top: 'middle',
        left: 'center',
        calcDimension: true,
        posBox: '.content-box',
        widthBox: '.content-box',
        constrainToView: true,
        margin: [30, 30],
        padding: [30, 30]

    };
})(jQuery);

