
/* 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++portletbanners.js - */
// http://www.bnct.ch/portal_javascripts/++resource++portletbanners.js?original=1
jq.fn.portletBanners=function(delay,fade_speed){jq(this).each(function(){var container=jq(this);var items=container.find('.portletbanner');container.height(container.height());container.width(container.width());container.css('position','relative');items.css({'position':'absolute','top':0,'left':0});var active=items.eq(0);
function rotate(){var next=active.next('.portletbanner');if(next.length==0){next=items.eq(0)}
active.fadeOut(fade_speed);next.fadeIn(fade_speed, function(){active=next})}
var rotate_timer=setInterval(rotate,delay)});return this};

/* - ++resource++sectioncss.js - */

/*
 * 3.2010
 * Raptus AG
 * 
 * SectionCSS
 * on every change, the choosen css file will 
 * be reloaded.
 * 
 */

var sectionCSS = {

    cssSelectField : '#sectioncss',
    cssSelectLink : '#sectioncss-link',
    
    init : function() {
      jq(sectionCSS.cssSelectField).change(function()
      {
          option = jq(sectionCSS.cssSelectField + ' option:selected');
          if (option.attr('value'))
            jq(sectionCSS.cssSelectLink).attr('href', option.attr('value'));
          else
            jq(sectionCSS.cssSelectLink).attr('href', jq(sectionCSS.cssSelectLink).attr('name'));
      });
    }
}

jq(document).ready(sectionCSS.init);

/* - bnct.theme.various.js - */
jQuery(document).ready(function($){
    var oldselect = $('#portal-languageselector');
    var current = oldselect.find('li.currentLanguage');
    var available = oldselect.find('li:not(li.currentLanguage)');
    
    oldselect.replaceWith(function(){
        var str = '<dl id="portal-languageselector">';
        str += '<dt class="currentLanguage">';
        str += current.html();
        str += '</dt>';
        available.each(function(){
            str += '<dd>';
            str += $(this).html();
            str += '</dd>';
        })
        str += '</dl>';
        return str;
    });
    var newselect =  $('#portal-languageselector');
    newselect.find('dd').hide(0);
    newselect.find('dt a').click(function(){
        newselect.find('dd').slideDown();
        return false;
    });
    newselect.mouseleave(function(){
        newselect.find('dd').slideUp();
    });
    
    
    
    
});

/* - subcontentwidget_plugin.js - */
(function($){
    $.fn.subcontentwidget = function(options) {
        
        var defaults = {
            // actually no options available
        };
        
        var options = $.extend(defaults, options);

        var Widget = function(field){
            if( arguments.length ) { this.init(field); };
        };
        
        Widget.prototype.init = function (field){
            var regex = /(archetypes-fieldname-)(.*)/;
            this.fieldname = field.parent('div').attr('id');
            this.fieldname = this.fieldname.match(regex)[2];
            
            skeleton = field.find('tr input.skeleton').parents('tr');
            this.table = skeleton.parents('tbody');
            this.skeleton = skeleton.wrapInner('<tr/>').html();
            skeleton.remove();
            this.initRow();
        }
        
        Widget.prototype.initRow = function(){
            this.index = 0;
            this.table.children('tr').each($.proxy(function(i, elem){
                this.index++;
                index = this.index;
                $(elem).data('index',this.index);
                var button = $(elem).find('.subcontentwidget_remove');
                button.unbind('click');
                button.click( $.proxy(function(){
                    this.del($(elem).data('index'));
                    return false;
                },this));
            },this));
        }
        
        Widget.prototype.getSkeleton = function(){
            this.index++;
            var regex = new RegExp("(_"+this.fieldname+"___)([0-9]*)(__)",'gm');
            input = this.skeleton;
            return this.skeleton.replace(regex, "$1"+this.index+"$3");
        }
        
        Widget.prototype.add = function(){
            this.table.append(this.getSkeleton());
            this.initRow();
        }
        
        Widget.prototype.del = function(index){
            this.table.children('tr').each(function(i, elem){
                if ($(elem).data('index') == index)
                    $(elem).remove();
            });
        }
        
        Widget.prototype.get = function(index){
            
        }
        
        var widgets = new Array();
        this.each(function(index){
            widgets[index] = new Widget($(this));
        });
        return widgets;
    };
    
})(jQuery);

