
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - ++resource++collective.collage.megamenu/megamenu.js - */
/* Copied and adapted from http://www.sohtanaka.com/web-design/mega-drop-downs-w-css-jquery/ */

jq(document).ready(function() {

    //Calculate width of all ul's
    (function(jq) {
        jQuery.fn.calcSubWidth = function() {
            // Should receive a .menu-row element
            var rowWidth = 0;
            //Calculate row
            jq(this).find(">ul").each(function() {
                rowWidth += jq(this).width();
            });
            return rowWidth;
        };
    }(jQuery));


    (function(jq) {
        jQuery.fn.resetWidth = function(nesting) {
            // Should receive a .sub element
            // Show the element (opacity = 0) to set widths properly
            if (!nesting) {
                this.css('opacity', 0).show();
            }
            // find all direct-child rows (there could be nested menues)
            var rows = this.find('>.menu-row');
            var biggestRow = 0;
            //Calculate each row
            rows.each(function() {
                // If there are nested menues, reset their widths before
                var me = jq(this);
                var nested = me.find('>ul>li.menu_view_nested-menu');
                nested.each(function() {
                    jq(this).resetWidth(true);
                });
                var rowWidth = me.calcSubWidth();
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            rows.each(function() {
                var columns = jq(this).find('>ul');
                var count = columns.length;
                columns.css('width', biggestRow / count);
            });

            biggestRow += 30; //Set width adding 15 + 15 px (left and right padding)
            this.css({
                'width': biggestRow
            });
            this.find(">.menu-row:last").css({
                'margin': '0'
            });
            if (!nesting) {
                this.hide();
            }
        };
    }(jQuery));

    String.prototype.startsWith = function(text) {
        return this.substring(0, text.length) === text;
    };

    function applySelected() {
        // Get all links and select their parent li-elements 
        // if href matches current URL beginning
        var url = document.location.href;
        jq('#portal-megamenu li.menu_view_menu a').each(function() {
            if (url.startsWith(this.href)) {
                jq(this).closest('li').addClass('selected');
            }
        });
    }

    function megaHoverOver() {
        var me = jq(this);
        // Check if there's another open menu (may be open because of a focused input or button)
        var currentlyActive = me.siblings('.active');
        if (currentlyActive.length > 0) {
            // If found an active menu, hide it
            hideMenu(currentlyActive);
            me.find('a').focus();
        }
        me.removeClass('hover').addClass('active').prev('li').addClass('nextActive');
        me.next('li').addClass('prevActive');
        var sub = me.find('.sub');
        if (sub.length > 0) {
            var shadow = sub.data('shadow');
            if (!shadow) {
                sub.after('<div class="subShadow" style="display: none;"></div>');
                shadow = sub.next('.subShadow');
                sub.data('shadow', shadow);
            }
            sub.stop().fadeTo(50, 1).show();
            shadow.stop().fadeTo(50, 0.6).show();

            var wWidth = jq(window).width();
            sub.css('left', 0);
            var sWidth = sub.width();
            var difWidth = wWidth - (sub.offset().left + sWidth + 19 + 20); //19px = scrollbar + 20px=padding
            var left = 0;
            if (difWidth < 0) {
                left = difWidth;
            }
            sub.css('left', left);
            shadow.css({
                left: left,
                width: sub.outerWidth(),
                height: sub.outerHeight()
            })
        }

    }

    function megaHoverOut() {
        var me = jq(this);
        var focusField = document.activeElement; // :focus in jQuery>=1.6
        if (focusField.nodeType == 1 && focusField.tagName.toLowerCase().match(/^(input|textarea|select|button)$/)) { // focusable form elements
            focusField = jq(focusField);
            if (focusField.closest('li.top-level.active').length > 0) {
                // if focused field is inside the menu, relay the hideMenu on click event
                jq(window).click(function(event) {
                    var target = jq(event.target);
                    // if clicked element is outside the active menu
                    var activeParent = target.closest('li.top-level.active');
                    if (activeParent.length === 0) {
                        // hide it
                        hideMenu(me);
                    }

                });
                return;
            }
        }

        hideMenu(me);
    }

    function hideMenu(me) {
        me = me || jq(this);
        me.removeClass('active').prev('li').removeClass('nextActive');
        me.next('li').removeClass('prevActive');
        var sub = me.find('.sub');
        if (sub.length > 0) {
            var shadow = sub.data('shadow');
            sub.stop().fadeTo(50, 0, function() {
                jq(this).hide();
            });
            if (shadow) {
                shadow.stop().fadeTo(50, 0, function() {
                    jq(this).hide();
                });
            }
        }
    }


    var config = {
        sensitivity: 2,
        // number = sensitivity threshold (must be 1 or higher)    
        interval: 200,
        // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver,
        // function = onMouseOver callback (REQUIRED)    
        timeout: 100,
        // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    var megamenu = jq('#portal-megamenu');
    megamenu.find('li .sub').css({
        'opacity': '0'
    });
    // Bind over/out and click events of li.top-level
    megamenu.find('li.top-level').
    hover(function() {
        jq(this).addClass('hover');
    }, function() {
        jq(this).removeClass('hover');
    }).
    hoverIntent(config).
	// bind click event to show/hide drop-down
    click(function() {
		var me = jq(this);
		if (me.hasClass('active')) {
			hideMenu(me);
		} else {
			jq.proxy(megaHoverOver, me)();
		}
	}).
    // and Bind click event of their links-with-menues to prevent redirection
    find('a').click(function(event) {
        if (jq(this).closest('li').find('.sub').length > 0) {
            event.preventDefault();
        }
    });

    // Preload sub-menues, if there are deferred dropdowns
    var deferred = megamenu.find('a[rel=deferred]');
    if (deferred.length > 0) {
        megamenu.find('a[rel=deferred]').each(function() {
            jq(this).parent().load(this.href, function(response, status, request) {
                // Reset width
                jq(this).resetWidth();
                applySelected();
            });
        });
    } else {
        // If there aren't deferred dropdowns, just reset their widths
        megamenu.find('.sub').each(function() {
            jq(this).resetWidth();
            applySelected();
        });
    }

});

/* - ++resource++collective.collage.megamenu/jquery.hoverIntent.minified.js - */
/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

/* - jquery.tools.min.js - */
// http://www.roxysteeparlour.com/portal_javascripts/jquery.tools.min.js?original=1
(function(b){b.tools=b.tools||{};b.tools.scrollable={version:"1.1.2",conf:{size:5,vertical:false,speed:400,keyboard:true,keyboardSteps:null,disabledClass:"disabled",hoverClass:null,clickable:true,activeClass:"active",easing:"swing",loop:false,items:".items",item:null,prev:".prev",next:".next",prevPage:".prevPage",nextPage:".nextPage",api:false}};var c;function a(o,m){var r=this,p=b(this),d=!m.vertical,e=o.children(),k=0,i;if(!c){c=r}b.each(m,function(s,t){if(b.isFunction(t)){p.bind(s,t)}});if(e.length>1){e=b(m.items,o)}function l(t){var s=b(t);return m.globalNav?s:o.parent().find(t)}o.data("finder",l);var f=l(m.prev),h=l(m.next),g=l(m.prevPage),n=l(m.nextPage);b.extend(r,{getIndex:function(){return k},getClickIndex:function(){var s=r.getItems();return s.index(s.filter("."+m.activeClass))},getConf:function(){return m},getSize:function(){return r.getItems().size()},getPageAmount:function(){return Math.ceil(this.getSize()/m.size)},getPageIndex:function(){return Math.ceil(k/m.size)},getNaviButtons:function(){return f.add(h).add(g).add(n)},getRoot:function(){return o},getItemWrap:function(){return e},getItems:function(){return e.children(m.item)},getVisibleItems:function(){return r.getItems().slice(k,k+m.size)},seekTo:function(s,w,t){if(s<0){s=0}if(k===s){return r}if(b.isFunction(w)){t=w}if(s>r.getSize()-m.size){return m.loop?r.begin():this.end()}var u=r.getItems().eq(s);if(!u.length){return r}var v=b.Event("onBeforeSeek");p.trigger(v,[s]);if(v.isDefaultPrevented()){return r}if(w===undefined||b.isFunction(w)){w=m.speed}function x(){if(t){t.call(r,s)}p.trigger("onSeek",[s])}if(d){e.animate({left:-u.position().left},w,m.easing,x)}else{e.animate({top:-u.position().top},w,m.easing,x)}c=r;k=s;v=b.Event("onStart");p.trigger(v,[s]);if(v.isDefaultPrevented()){return r}f.add(g).toggleClass(m.disabledClass,s===0);h.add(n).toggleClass(m.disabledClass,s>=r.getSize()-m.size);return r},move:function(u,t,s){i=u>0;return this.seekTo(k+u,t,s)},next:function(t,s){return this.move(1,t,s)},prev:function(t,s){return this.move(-1,t,s)},movePage:function(w,v,u){i=w>0;var s=m.size*w;var t=k%m.size;if(t>0){s+=(w>0?-t:m.size-t)}return this.move(s,v,u)},prevPage:function(t,s){return this.movePage(-1,t,s)},nextPage:function(t,s){return this.movePage(1,t,s)},setPage:function(t,u,s){return this.seekTo(t*m.size,u,s)},begin:function(t,s){i=false;return this.seekTo(0,t,s)},end:function(t,s){i=true;var u=this.getSize()-m.size;return u>0?this.seekTo(u,t,s):r},reload:function(){p.trigger("onReload");return r},focus:function(){c=r;return r},click:function(u){var v=r.getItems().eq(u),s=m.activeClass,t=m.size;if(u<0||u>=r.getSize()){return r}if(t==1){if(m.loop){return r.next()}if(u===0||u==r.getSize()-1){i=(i===undefined)?true:!i}return i===false?r.prev():r.next()}if(t==2){if(u==k){u--}r.getItems().removeClass(s);v.addClass(s);return r.seekTo(u,time,fn)}if(!v.hasClass(s)){r.getItems().removeClass(s);v.addClass(s);var x=Math.floor(t/2);var w=u-x;if(w>r.getSize()-t){w=r.getSize()-t}if(w!==u){return r.seekTo(w)}}return r},bind:function(s,t){p.bind(s,t);return r},unbind:function(s){p.unbind(s);return r}});b.each("onBeforeSeek,onStart,onSeek,onReload".split(","),function(s,t){r[t]=function(u){return r.bind(t,u)}});f.addClass(m.disabledClass).click(function(){r.prev()});h.click(function(){r.next()});n.click(function(){r.nextPage()});if(r.getSize()<m.size){h.add(n).addClass(m.disabledClass)}g.addClass(m.disabledClass).click(function(){r.prevPage()});var j=m.hoverClass,q="keydown."+Math.random().toString().substring(10);r.onReload(function(){if(j){r.getItems().hover(function(){b(this).addClass(j)},function(){b(this).removeClass(j)})}if(m.clickable){r.getItems().each(function(s){b(this).unbind("click.scrollable").bind("click.scrollable",function(t){if(b(t.target).is("a")){return}return r.click(s)})})}if(m.keyboard){b(document).unbind(q).bind(q,function(t){if(t.altKey||t.ctrlKey){return}if(m.keyboard!="static"&&c!=r){return}var u=m.keyboardSteps;if(d&&(t.keyCode==37||t.keyCode==39)){r.move(t.keyCode==37?-u:u);return t.preventDefault()}if(!d&&(t.keyCode==38||t.keyCode==40)){r.move(t.keyCode==38?-u:u);return t.preventDefault()}return true})}else{b(document).unbind(q)}});r.reload()}b.fn.scrollable=function(d){var e=this.eq(typeof d=="number"?d:0).data("scrollable");if(e){return e}var f=b.extend({},b.tools.scrollable.conf);d=b.extend(f,d);d.keyboardSteps=d.keyboardSteps||d.size;this.each(function(){e=new a(b(this),d);b(this).data("scrollable",e)});return d.api?e:this}})(jQuery);(function(b){var a=b.tools.scrollable;a.plugins=a.plugins||{};a.plugins.circular={version:"0.5.1",conf:{api:false,clonedClass:"cloned"}};b.fn.circular=function(e){var d=b.extend({},a.plugins.circular.conf),c;b.extend(d,e);this.each(function(){var i=b(this).scrollable(),n=i.getItems(),k=i.getConf(),f=i.getItemWrap(),j=0;if(i){c=i}if(n.length<k.size){return false}n.slice(0,k.size).each(function(o){b(this).clone().appendTo(f).click(function(){i.click(n.length+o)}).addClass(d.clonedClass)});var l=b.makeArray(n.slice(-k.size)).reverse();b(l).each(function(o){b(this).clone().prependTo(f).click(function(){i.click(-o-1)}).addClass(d.clonedClass)});var m=f.children(k.item);var h=k.hoverClass;if(h){m.hover(function(){b(this).addClass(h)},function(){b(this).removeClass(h)})}function g(o){var p=m.eq(o);if(k.vertical){f.css({top:-p.position().top})}else{f.css({left:-p.position().left})}}g(k.size);b.extend(i,{move:function(s,r,p,q){var u=j+s+k.size;var t=u>i.getSize()-k.size;if(u<=0||t){var o=j+k.size+(t?-n.length:n.length);g(o);u=o+s}if(q){m.removeClass(k.activeClass).eq(u+Math.floor(k.size/2)).addClass(k.activeClass)}if(u===j+k.size){return self}return i.seekTo(u,r,p)},begin:function(p,o){return this.seekTo(k.size,p,o)},end:function(p,o){return this.seekTo(n.length,p,o)},click:function(p,r,q){if(!k.clickable){return self}if(k.size==1){return this.next()}var s=p-j,o=k.activeClass;s-=Math.floor(k.size/2);return this.move(s,r,q,true)},getIndex:function(){return j},setPage:function(p,q,o){return this.seekTo(p*k.size+k.size,q,o)},getPageAmount:function(){return Math.ceil(n.length/k.size)},getPageIndex:function(){if(j<0){return this.getPageAmount()-1}if(j>=n.length){return 0}var o=(j+k.size)/k.size-1;return o},getVisibleItems:function(){var o=j+k.size;return m.slice(o,o+k.size)}});i.onStart(function(p,o){j=o-k.size;return false});i.getNaviButtons().removeClass(k.disabledClass)});return d.api?c:this}})(jQuery);(function(b){var a=b.tools.scrollable;a.plugins=a.plugins||{};a.plugins.autoscroll={version:"1.0.1",conf:{autoplay:true,interval:3000,autopause:true,steps:1,api:false}};b.fn.autoscroll=function(d){if(typeof d=="number"){d={interval:d}}var e=b.extend({},a.plugins.autoscroll.conf),c;b.extend(e,d);this.each(function(){var g=b(this).scrollable();if(g){c=g}var i,f,h=true;g.play=function(){if(i){return}h=false;i=setInterval(function(){g.move(e.steps)},e.interval);g.move(e.steps)};g.pause=function(){i=clearInterval(i)};g.stop=function(){g.pause();h=true};if(e.autopause){g.getRoot().add(g.getNaviButtons()).hover(function(){g.pause();clearInterval(f)},function(){if(!h){f=setTimeout(g.play,e.interval)}})}if(e.autoplay){setTimeout(g.play,e.interval)}});return e.api?c:this}})(jQuery);(function(b){var a=b.tools.scrollable;a.plugins=a.plugins||{};a.plugins.navigator={version:"1.0.2",conf:{navi:".navi",naviItem:null,activeClass:"active",indexed:false,api:false,idPrefix:null}};b.fn.navigator=function(d){var e=b.extend({},a.plugins.navigator.conf),c;if(typeof d=="string"){d={navi:d}}d=b.extend(e,d);this.each(function(){var i=b(this).scrollable(),f=i.getRoot(),l=f.data("finder").call(null,d.navi),g=null,k=i.getNaviButtons();if(i){c=i}i.getNaviButtons=function(){return k.add(l)};function j(){if(!l.children().length||l.data("navi")==i){l.empty();l.data("navi",i);for(var m=0;m<i.getPageAmount();m++){l.append(b("<"+(d.naviItem||"a")+"/>"))}g=l.children().each(function(n){var o=b(this);o.click(function(p){i.setPage(n);return p.preventDefault()});if(d.indexed){o.text(n)}if(d.idPrefix){o.attr("id",d.idPrefix+n)}})}else{g=d.naviItem?l.find(d.naviItem):l.children();g.each(function(n){var o=b(this);o.click(function(p){i.setPage(n);return p.preventDefault()})})}g.eq(0).addClass(d.activeClass)}i.onStart(function(o,n){var m=d.activeClass;g.removeClass(m).eq(i.getPageIndex()).addClass(m)});i.onReload(function(){j()});j();var h=g.filter("[href="+location.hash+"]");if(h.length){i.move(g.index(h))}});return d.api?c:this}})(jQuery);

/* - carousel.js - */
// http://www.roxysteeparlour.com/portal_javascripts/carousel.js?original=1
jQuery(function($){setTimeout(function(){var resizeCarousel=function(carousel,scrollable,elems){var base_height=Math.max.apply(null,$(elems).map(function(){return $(this).height()}).get());if(base_height<$(carousel).height()){base_height=$(carousel).height()-$(".navi").outerHeight(true)}
$(elems).height(base_height);var scrollable_height=$(elems).eq(0).outerHeight(true);$(scrollable).height(scrollable_height);var outer_height=$(scrollable).outerHeight(true)+$(".navi").outerHeight(true);var $carousel=$(carousel);if($carousel.height()<outer_height){$carousel.height(outer_height).trigger('resized.carousel',[outer_height])}};$(".toolBar").hide();var carousels=$(".carousel");var interval=3000;carousels.each( function(i){var carousel=this;var scrollable=$(this).find(".scrollable").eq(0);var elems=$(scrollable).find('.tileItem');scrollable_width=$(scrollable).width();for(i=0;i<elems.length;i++){$(elems[i]).css({width:scrollable_width+'px'})};setTimeout(function(){resizeCarousel(carousel,scrollable,elems)},0);$(scrollable).find("img").load(function(event){resizeCarousel(carousel,scrollable,elems)});if(parseInt($(scrollable).attr('rel'))>0){interval=parseInt($(scrollable).attr('rel'))}});var ap=(carousels.length==1)?true:false;var api=$("div.scrollable").scrollable({size:1,clickable:false,loop:true}).circular().autoscroll({autoplay:ap,steps:1,interval:interval}).navigator({api:true});$(".carousel").hover(
function(){$(this).find(".toolBar").eq(0).slideToggle('fast').show()},
function(){$(this).find(".toolBar").eq(0).slideToggle('fast').hide()});$(".carousel .pause").click(function(){api.pause()})},(($.browser.safari||$.browser.webkit)?1250:500))})

