/* Author: Mark Dalgleish */
(function($){
    var FLINT = {
        rotheLowman: {

            init: function() {
                var self = this;
                $(function(){
                    self.homepageChannels.init();

                    self.positionPageHeaders.init();
                    self.projectSlideshow.init();
                    self.projectThumbnails.init();
                    self.projectFullScreenGallery.init();

                    self.decodeEmails.init();
                    self.miniGalleries.init();
                    self.expandableProfiles.init();
                    self.publicationMasonry.init();
                });
            },



            analytics: {
                virtualPage: function(pageUrl) {
                    if (typeof(_gaq) !== 'undefined') {
                        _gaq.push(['_trackPageview', pageUrl]);
                    }
                }
            },



            homepageChannels: {
                init: function() {
                    var self = this;

                    this.$container = $('#homepage-project-selector');

                    if (this.$container.length === 0) {
                        return;
                    }

                    this.$channels = this.$container.find('div.channels img');
                    this.$activeChannel = this.$channels.first();
                    this.zIndex = 1;

                    $(window).load(function(){
                        self.$activeChannel.fadeIn();
                        self.reposition();
                        self.loadHiddenImages();
                        self.cycleImages();
                        $(window).resize($.proxy(self.reposition, self));
                    });
                    this.$channels.click(function(){
                        self.goToProject($(this).data('project-url'));
                    });
                },
                loadHiddenImages: function() {
                    var self = this,
                        $hiddenImages = this.$channels.filter('[data-src]');
                    for (var i = 0; i < $hiddenImages.length; i++) {
                        (function(i){
                            setTimeout(function(){
                                var $hiddenImage = $hiddenImages.eq(i);
                                $hiddenImage.attr('src',$hiddenImage.attr('data-src')).height('auto');
                            }, (i + 1) * 2000);
                        })(i);
                    }
                },
                cycleImages: function() {
                    setInterval($.proxy(this.next, this), 6 * 1000);
                },
                next: function() {
                    var $next = this.$activeChannel.next();

                    if ($next.length === 1) {
                        this.activateChannel($next.index())
                    } else {
                        this.activateChannel(0);
                    }
                },
                activateChannel: function(index) {
                    var self = this,
                        $old = this.$activeChannel,
                        $new = this.$channels.eq(index).hide();

                    $new.css('z-index', this.zIndex++).fadeIn(2000, 'easeInOutExpo', function() {
                        $old.css('z-index', 1);
                        $new.css('z-index', 2);
                        self.zIndex = 3;
                    });

                    this.reposition();
                    
                    this.$activeChannel = $new;
                },
                reposition: function() {
                    var self = this;

                    this.$channels.each(function(){
                        var $img = $(this);

                        $img.height('auto');

                        if ($img.height() < self.$container.height()) {
                            $img.height(self.$container.height());
                        }

                        $img.css({
                            marginTop: ($img.height() / 2) * -1,
                            top: $img.parent().height() / 2
                        });
                    });
                },
                goToProject: function(url) {
                    var dir = url.match(/.*?\//)[0].replace('/', '');
                    window.location.href = dir + '#' + url;
                }
            },



            positionPageHeaders: {
                init: function() {
                    var self = this,
                        $header = $('div.page-header');

                    if ($header.length === 0) {
                        return;
                    }

                    this.$img = $header.find('img');

                    $header.imagesLoaded(function() {
                        //setTimeout fixes IE9 bug
                        setTimeout(function(){
                            self.$img.css('top', '50%');

                            self.reposition();
                            $(window).resize($.proxy(self.reposition, self));
                        }, 1);
                    });
                },
                reposition: function() {
                    this.$img.css('margin-top', this.$img.height() / 2 * -1);
                }
            },



            decodeEmails: {
                init: function(context) {
                    var self = this;

                    //Decode plain text email addresses
                    $('span.email-address-encoded', context || document).each(function() {
                        var $this = $(this),
                            text = $this.text();

                        if (text.indexOf('{email:') === 0) {
                            text = text.replace('{email:','').replace('}','');
                            $this.text(self.decodeBase64(text)).removeClass('email-address-encoded');
                        }
                    });

                    //Decode email links
                    $('a', context || document).each(function(){
                        var $this = $(this),
                            href = $this.attr('href');

                        if (href.indexOf('mailto:{email:') === 0) {
                            href = href.replace('mailto:{email:','').replace('}','');
                            $this.attr('href', 'mailto:' + self.decodeBase64(href));
                        }
                    });
                },
                decodeBase64: function(input) {
                    var keyStr = "ABCDEFGHIJKLMNOP" +
                       "QRSTUVWXYZabcdef" +
                       "ghijklmnopqrstuv" +
                       "wxyz0123456789+/" +
                       "=";
                    var output = "";
                     var chr1, chr2, chr3 = "";
                     var enc1, enc2, enc3, enc4 = "";
                     var i = 0;

                     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
                     var base64test = /[^A-Za-z0-9\+\/\=]/g;
                     if (base64test.exec(input)) {
                        return;
                     }
                     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

                     do {
                        enc1 = keyStr.indexOf(input.charAt(i++));
                        enc2 = keyStr.indexOf(input.charAt(i++));
                        enc3 = keyStr.indexOf(input.charAt(i++));
                        enc4 = keyStr.indexOf(input.charAt(i++));

                        chr1 = (enc1 << 2) | (enc2 >> 4);
                        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                        chr3 = ((enc3 & 3) << 6) | enc4;

                        output = output + String.fromCharCode(chr1);

                        if (enc3 != 64) {
                           output = output + String.fromCharCode(chr2);
                        }
                        if (enc4 != 64) {
                           output = output + String.fromCharCode(chr3);
                        }

                        chr1 = chr2 = chr3 = "";
                        enc1 = enc2 = enc3 = enc4 = "";

                     } while (i < input.length);

                     return unescape(output);
                  }
            },



            projectSlideshow: {
                init: function(options) {
                    this.$elem = $('#project-slideshow');
                    this.$infoSection = this.$elem.parent().find('section.info-section');
                    this.$description = this.$infoSection.find('div.more-info');

                    if (this.$elem.length === 0) {
                        return;
                    }

                    this.reset();
                    this.handleEvents();

                    if (typeof options === 'undefined' || (typeof options !== 'undefined' && options.isAjaxLoad !== true)) {
                        this.loadFromHash();
                    }
                },
                loadProject: function(url, callback) {
                    var self = this,
                        id = url.match(/(project\/)([0-9]*)/)[2];

                    if (this.isLoading === true) {
                        if (typeof(callback) === 'function') {
                            callback();
                        }
                        return;
                    }
                    this.isLoading = true;

                    this.$elem = $('#project-slideshow');
                    if (this.$elem.length === 0) {
                        this.$elem = $('<div id="project-slideshow"></div>').insertAfter('#header');
                    }

                    window.location.hash = url;

                    $.get('rest/restProject/?projectId=' + id).success(function(data){
                        FLINT.rotheLowman.analytics.virtualPage('/' + url);

                        var populate = function() {
                            self.$elem.html(innerShiv(data, false));

                            self.$elem.slideDown(800, 'easeInOutExpo', function(){
                                self.isLoading = false;

                                if (typeof(callback) === 'function') {
                                    callback();
                                }
                            });
                            self.init({isAjaxLoad:true});
                        }
                        
                        if (self.$elem.height() === 0) {
                            self.$elem.hide();

                            $('html,body').animate({
                                scrollTop: 0
                            }, 600, 'easeInOutExpo', function() {
                                populate();
                            });
                        } else {
                            $('html,body').animate({
                                scrollTop: 0
                            }, 600, 'easeInOutExpo', function() {
                                self.$elem.slideUp(800, 'easeInOutExpo', function(){
                                    populate();
                                })
                            });
                        }
                    });

                },
                reset: function() {
                   var self = this;

                    this.$holder = this.$elem.find('div.holder');
                    this.$currentNumber = this.$elem.find('div.info-row span.current-number');
                    this.$activeMedia = this.$holder.children(':first');
                    this.$next = this.$holder.siblings('a.next');
                    this.$prev = this.$holder.siblings('a.prev');

                    this.$holder.children('.image-box').each(function(){
                        var $img = $(this).children('img').css('opacity', 0);

                        $img.imagesLoaded(function(){
                            //setTimeout fixes IE9 bug
                            setTimeout(function(){
                                $img.animate({
                                    opacity: 1
                                }, 800, 'easeInOutExpo');
                            }, 1);
                        })
                    });

                    return this;
                },
                handleEvents: function() {
                    var self = this;

                    this.$elem
                        .undelegate('a.prev', 'click.projectslideshow')
                        .undelegate('a.next', 'click.projectslideshow')
                        .undelegate('a.zoom', 'click.projectslideshow')
                        .undelegate('a.image-box', 'mouseleave.projectslideshow')
                        .undelegate('a.image-box', 'mouseleave.projectslideshow')
                        .delegate('a.prev', 'click.projectslideshow', function(event) {
                            event.preventDefault();
                            self.prev();
                        })
                        .delegate('a.next', 'click.projectslideshow', function(event) {
                            event.preventDefault();
                            self.next();
                        })
                        .delegate('img', 'click.projectslideshow', function(event) {
                            event.preventDefault();
                            self.activateMedia($(this).parent().index());
                        })
                        .delegate('a.zoom', 'click.projectslideshow', function(event) {
                            event.preventDefault();
                            self.zoom(event);
                        })
                        .delegate('.image-box', 'mouseenter.projectslideshow', function(){
                            $(this).addClass('hover');
                        })
                        .delegate('.image-box', 'mouseleave.projectslideshow', function(){
                            $(this).removeClass('hover');
                        });

                    this.$infoSection
                        .delegate('a.more', 'click.projectslideshow', function(event){
                            event.preventDefault();
                            self.toggleMoreInfo($(this));
                        });

                    $(document)
                        .unbind('keydown.projectslideshow')
                        .bind('keydown.projectslideshow', function(event){
                            var key = event.which;
                            if (key === 37) { //Left
                                self.prev();
                            } else if (key === 39) { //Right
                                self.next()
                            }
                        });

                    $(window).bind('hashchange', function(e) {
                        self.loadFromHash();
                    });

                    return this;
                },
                loadFromHash: function() {
                    if (window.location.hash.indexOf('/project/') > -1) {
                        this.loadProject(window.location.hash.replace('#',''));
                    }
                },
                toggleMoreInfo: function($link) {
                    if (this.$description.is(':visible')) {
                        $link.removeClass('less').text('More');

                        $('html,body').animate({
                            scrollTop: 0
                        }, 1000, 'easeInOutExpo');

                        this.$description.slideUp(1000, 'easeInOutExpo');
                    } else {
                        $link.addClass('less').text('Less');

                        $('html,body').animate({
                            scrollTop: this.$infoSection.position().top - $('#header').outerHeight() - 100
                        }, 1000, 'easeInOutExpo');
                        
                        this.$description.slideDown(1000, 'easeInOutExpo');
                    }
                },
                prev: function() {
                    var $prev = this.$activeMedia.prev();
                    if ($prev.length === 1) {
                        this.activateMedia($prev.index());
                    }
                },
                next: function() {
                    var $next = this.$activeMedia.next();
                    if ($next.length === 1) {
                        this.activateMedia($next.index());
                    }
                },
                activateMedia: function(index) {
                    this.$currentNumber.text(index + 1);
                    this.$activeMedia = this.$holder.children().eq(index);

                    var contentWidth = 0;
                    this.$holder.children('.image-box').each(function() {
                        contentWidth += $(this).outerWidth() + 1;
                    });
                    contentWidth -= 1;

                    var position = this.$activeMedia.position().left,
                        windowWidth = $(window).width();

                    if (contentWidth - position < windowWidth && contentWidth > windowWidth) {
                        position = contentWidth - windowWidth;
                        this.$next.hide();
                    } else {
                        this.$next.show();
                    }

                    if (index === 0) {
                        this.$prev.hide();
                    } else {
                        this.$prev.show();
                    }

                    if ($(window).scrollTop() > 0 && $('html').is(':animated') === false && $('body').is(':animated') === false) {
                        $('html,body').animate({
                            scrollTop: 0
                        }, 600, 'easeInOutExpo');
                    }

                    this.$holder.stop(true).animate({
                        left: position * -1
                    }, 600, 'easeInOutExpo');
                },
                zoom: function(event) {
                    var index = $(event.target).parent().index();
                    FLINT.rotheLowman.projectFullScreenGallery.show(index);
                }
            },



            projectFullScreenGallery: {
                init: function() {
                    var self = this;

                    this.$elem = $('div.full-screen-gallery');
                    if (this.$elem.length === 0) {
                        return;
                    }

                    this.$inner = this.$elem.children();
                    this.$thumbnailWrapper = this.$elem.find('div.gallery-thumbnails').hide();
                    this.$thumbnailActiveIndicator = this.$elem.find('div.thumbnail-active-indicator');
                    this.$mediaWrapper = this.$elem.find('div.media-wrapper').hide();
                    this.$activeMedia =this.$mediaWrapper.children(':first');
                    this.$caption = this.$elem.find('div.caption');
                    this.$currentNumber = this.$elem.find('span.current-number');
                    this.$currentCaption = this.$elem.find('span.current-caption');
                    this.$next = this.$elem.find('a.next');
                    this.$prev = this.$elem.find('a.prev');
                    this.$close = this.$elem.find('a.close');

                    this.handleEvents();

                    this.positionElements();
                    this.loadImages();

                    return this;
                },
                show: function(index) {
                    var self = this;

                    this.init();

                    this.activateMedia(index);
                    this.$mediaWrapper.children(':not(:eq('+index+'))').hide();
                    this.$mediaWrapper.children('.caption').show();

                    this.$elem.fadeIn(600, 'easeInOutExpo', function() {
                        self.$mediaWrapper.fadeIn(400, 'easeInOutExpo', function() {
                            var $navButtons;
                            if (index === 0 || typeof index === 'undefined') {
                                $navButtons = self.$elem.find('.next');
                            } else {
                                $navButtons = self.$elem.find('.next, .prev');
                            }
                            $navButtons.fadeIn(200, 'easeInOutExpo', function() {
                                self.$thumbnailWrapper.fadeIn(400, 'easeInOutExpo', function() {
                                    self.slideThumbnailActiveIndicator(index, true);
                                });
                            });
                        });
                        self.positionElements();
                    });

                    return this;
                },
                hide: function() {
                    this.$elem.fadeOut(1000, 'easeInOutExpo');
                    return this;
                },
                _debounce: function (func, threshold, execAsap) {
                      var timeout;

                      return function debounced () {
                          var obj = this, args = arguments;
                          function delayed () {
                              if (!execAsap)
                                  func.apply(obj, args);
                              timeout = null;
                          };

                          if (timeout)
                              clearTimeout(timeout);
                          else if (execAsap)
                              func.apply(obj, args);

                          timeout = setTimeout(delayed, threshold || 100);
                      };
                  },
                handleEvents: function() {
                    var self = this;
                    this.$elem
                        .undelegate('a.prev', 'click.fullscreengallery')
                        .undelegate('a.next', 'click.fullscreengallery')
                        .undelegate('a.close', 'click.fullscreengallery')
                        .undelegate('.thumbnail-box', 'click.fullscreengallery')
                        .undelegate('.close-gallery', 'click.fullscreengallery')
                        .delegate('a.prev', 'click.fullscreengallery', function(event) {
                            event.preventDefault();
                            self.prev();
                        })
                        .delegate('a.next', 'click.fullscreengallery', function(event) {
                            event.preventDefault();
                            self.next();
                        })
                        .delegate('a.close', 'click.fullscreengallery', function(event) {
                            event.preventDefault();
                            event.stopPropagation();
                            self.hide();
                        })
                        .delegate('.thumbnail-box', 'click.fullscreengallery', function(){
                            self.activateMedia($(this).index());
                        });

                    $(document)
                        .unbind('keydown.fullscreengallery') //Remove the event handler if it already exists
                        .bind('keydown.fullscreengallery', function(event){
                            var key = event.which;
                            if (key === 37) { //Left
                                self.prev();
                            } else if (key === 39) { //Right
                                self.next()
                            } else if (key === 27) { //Esc
                                self.hide();
                            }
                        });

                    $(window)
                        .unbind('resize.fullscreengallery') //Remove the event handler if it already exists
                        .unbind('orientationchange.fullscreengallery')
                        .bind('resize.fullscreengallery', $.proxy( this.positionElements, this ) )
                        .bind('resize.fullscreengallery', $.proxy( this._debounce( this.loadImages, 500 ), this) )
                        .bind('orientationchange.fullscreengallery', $.proxy( this.positionElements, this ) )
                        .bind('orientationchange.fullscreengallery', $.proxy( this._debounce( this.loadImages, 500 ), this) );
                },
                positionElements: function() {
                    var $window = $(window),
                        winWidth = $window.width(),
                        winHeight = $window.height(),
                        wrapperWidth = winWidth - 140,
                        wrapperHeight = winHeight - this.$thumbnailWrapper.height() - 90;
                    
                    this.$mediaWrapper.css({
                        height: wrapperHeight,
                        marginLeft: (wrapperWidth / 2) * -1,
                        width: wrapperWidth
                    });

                    if (($.browser.msie === true && parseInt($.browser.version) < 7) || typeof(window.onorientationchange) !== 'undefined') {
                        this.$elem.height($(document).height());
                        this.$inner.height($(window).height());
                    }

                    $window.scrollTop(0);
                },
                loadImages: function() {
                    var $window = $(window),
                        winWidth = $window.width(),
                        winHeight = $window.height(),
                        wrapperWidth = winWidth - 140,
                        wrapperHeight = winHeight - this.$thumbnailWrapper.height() - 90;
                    
                    this.$mediaWrapper.find('.media-box[data-image-url]').each(function() {
                        var $this = $(this);
                        $this.css('background-image', 'url(admin-resources/image-tools.php?c=0&q=80&w=' + wrapperWidth + '&h=' + wrapperHeight + '&src=' + $this.data('image-url') + ')');
                    });

                    this.updateCaption();
                },
                slideThumbnailActiveIndicator: function(index, reset) {
                    var $activeThumbnail = this.$thumbnailWrapper.children().eq(index),
                        width = $activeThumbnail.width(),
                        marginLeft = $activeThumbnail.position().left - ($(window).width() / 2)

                    if (reset === true) {
                        this.$thumbnailActiveIndicator.css({
                            marginLeft: 0,
                            width: 0
                        })
                    }

                    this.$thumbnailActiveIndicator.stop(true).animate({
                        marginLeft: marginLeft,
                        width: width
                    }, 600, 'easeInOutExpo');
                },
                prev: function() {
                    var $prev = this.$activeMedia.prev();
                    if ($prev.length === 1) {
                        this.activateMedia($prev.index());
                    }
                },
                next: function() {
                    var $next = this.$activeMedia.next();
                    if ($next.length === 1 && $next.is(':not(.caption)')) {
                        this.activateMedia($next.index());
                    }

                    return this;
                },
                activateMedia: function(index) {
                    this.$mediaWrapper.children().stop(true, true);
                    this.$activeMedia.fadeOut(600, 'easeInOutExpo');

                    this.$activeMedia = this.$mediaWrapper.children().eq(index).fadeIn(600, 'easeInOutExpo');

                    if (this.$activeMedia.nextAll('.media-box').length === 0) {
                        this.$next.hide();
                        this.$prev.show();
                    } else if (index === 0 || typeof index === 'undefined' || this.$activeMedia.prevAll('.media-box').length === 0) {
                        this.$next.show();
                        this.$prev.hide();
                    } else {
                        this.$next.show();
                        this.$prev.show();
                    }

                    this.slideThumbnailActiveIndicator(index);

                    this.updateCaption();

                    return this;
                },
                updateCaption: function() {
                    var self = this;

                    this.$caption.stop(true,true).fadeOut(300, 'easeInOutExpo', function(){
                        self.$currentNumber.text(self.$activeMedia.index() + 1);
                        self.$currentCaption.text(self.$activeMedia.data('media-caption'));

                        self.$caption.fadeIn(300, 'easeInOutExpo');
                    });
                }
            },



            projectThumbnails: {
                init: function() {
                    var self = this;

                    this.$elem = $('#project-thumbnails');

                    if (this.$elem.length === 0) {
                        return;
                    }

                    this.handleEvents();

                    self.reposition();
                },
                handleEvents: function() {
                    var self = this;

                    this.$elem
                        .delegate('a[data-category-id]', 'click', function(event){
                            event.preventDefault();
                            var $this = $(this),
                                id = $this.attr('data-category-id'),
                                subId = $this.attr('data-subcategory-id');

                            $this.parents('div.categories-block:first').find('a.active').removeClass('active');
                            $this.addClass('active');

                            self.loadThumbnails(id, subId);
                        })
                        .delegate('a[data-project-id]', 'click', function(event){
                            event.preventDefault();
                            var $this = $(this);

                            if ($this.hasClass('loading')) {
                                return;
                            }

                            $this.addClass('loading').find('div.loading-bg').height($this.outerHeight());

                            FLINT.rotheLowman.projectSlideshow.loadProject($this.attr('href'), function(){
                                $this.removeClass('loading');
                            });
                        })
                        .delegate('a.back', 'click', function(event){
                            event.preventDefault();
                            self.scrollToTop();
                        });

                    return this;
                },
                loadThumbnails: function(categoryId, subCategoryId) {
                    var self = this,
                        $menu = this.$elem.children('div.categories-block'),
                        $backToTop = this.$elem.children('a.back'),
                        $projectLinks = this.$elem.find('a[data-project-id]'),
                        url = 'rest/restProjects/' + (typeof(categoryId) !== '0' ? '?projectCategoryId=' + categoryId : '') + (typeof(subCategoryId) !== 'undefined' ? '&projectSubCategoryId=' + subCategoryId : '');

                    $projectLinks.fadeOut(400, 'easeInOutExpo');
                    $backToTop.fadeOut(500, 'easeInOutExpo', function() {
                        $projectLinks.remove();
                        $.get(url, function(data){
                            if ($.trim(data).length === 0) {
                                return;
                            }

                            var $newProjectLinks = $(data).hide();

                            $menu.after($newProjectLinks);

                            $('html,body').animate({
                                scrollTop: self.$elem.offset().top - $('#header').height() - 20
                            }, 600, 'easeInOutExpo');

                            $backToTop.fadeIn(400, 'easeInOutExpo');
                            $newProjectLinks.fadeIn(400, 'easeInOutExpo');

                            setTimeout(function(){
                                self.reposition();
                            }, 1);
                        });
                    });
                },
                reposition: function() {
                    if (this.$elem.hasClass('masonry')) {
                        this.$elem.masonry('destroy');
                    }
                    this.$elem.masonry();
                },
                scrollToTop: function() {
                    $('html,body').animate({
                        scrollTop: 0
                    }, 1000, 'easeInOutExpo');
                }
            },



            miniGalleries: {
                init: function() {
                    var MiniGallery = function($gallery) {
                        return this.init($gallery);
                    }
                    MiniGallery.prototype = {
                        init: function($gallery) {
                            this.$gallery = $gallery;
                            this.$imageSlider = this.$gallery.find('div.image-slider');
                            this.$activeImage = this.$imageSlider.children().first();
                            this.$imageTitle = this.$gallery.find('p.image-title');
                            this.$status = this.$gallery.find('span.current-number');
                            this.$prev = this.$gallery.find('a.prev').hide();
                            this.$next = this.$gallery.find('a.next');
                            this.totalImages = this.$imageSlider.children().length;
                            
                            this.handleEvents();
                        },
                        handleEvents: function() {
                            this.$gallery
                                .delegate('a.prev', 'click', $.proxy(this.prev, this))
                                .delegate('a.next', 'click', $.proxy(this.next, this));
                        },
                        next: function(event) {
                            event.preventDefault();

                            var $next = this.$activeImage.next();

                            if ($next.length === 1) {
                                this.activateImage($next.index());
                            }
                        },
                        prev: function(event) {
                            event.preventDefault();
                            
                            var $prev = this.$activeImage.prev();

                            if ($prev.length === 1) {
                                this.activateImage($prev.index());
                            }
                        },
                        activateImage: function(index) {
                            var $new = this.$imageSlider.children().eq(index);

                            this.$imageSlider.stop(true).animate({
                                left: $new.position().left * -1
                            }, 1000, 'easeInOutExpo');

                            this.$imageTitle.text($new.attr('title'));
                            this.$status.text(index + 1);

                            if (index === 0) {
                                this.$prev.hide();
                                this.$next.show();
                            } else if (index === this.totalImages - 1) {
                                this.$next.hide();
                                this.$prev.show();
                            } else {
                                this.$next.show();
                                this.$prev.show();
                            }

                            this.$activeImage = $new;
                        }
                    };

                    $('div.minigallery').each(function(){
                        new MiniGallery($(this));
                    });
                }
            },



            expandableProfiles: {
                init: function() {
                    $('article.profile').each(function(){
                        var $profile = $(this);

                        $profile.find('a.open-close').click(function(event){
                            event.preventDefault();
                            $profile.toggleClass('block-active');
                        });
                    });
                }
            },



            publicationMasonry: {
                init: function() {
                    var $publications = $('div.publications');

                    $publications.imagesLoaded(function() {
                        //setTimeout fixes IE9 bug
                        setTimeout(function(){
                            $publications.each(function(){
                                $(this).masonry({
                                    columnWidth: 225,
                                    gutterWidth: 20
                                });
                            });
                        }, 1);
                    });
                }
            }


        }
    };

    if (typeof window.FLINT === 'undefined' || typeof window.FLINT.rotheLowman === 'undefined') {
        window.FLINT = FLINT;

        FLINT.rotheLowman.init();
    }
})(jQuery);
