var com = {
    ch5finland : {
        n5 : {
            _showTemplates : function(cssclass, templates, hide) {
                jQuery(cssclass +" select[@name=template] option").each(function(i){
                    var option = jQuery(this);
                    if(hide){
                        option.show();
                    }else{
                        option.hide();
                    }                   
                    jQuery.each(templates, function(){
                        if(option.val() == this && !hide){
                            option.show();
                        }
                        if(option.val() == this && hide){
                            option.hide();
                        }
                    });
                });
                jQuery(cssclass +" select[@name=template]").each(function(i){
                    if(jQuery("option:visible:selected", this).size() == 0){
                        jQuery("option:selected", this).removeAttr("selected");
                        jQuery("option:visible:first", this).attr("selected", "selected");
                    }
                });
            },
            showTemplates : function(visibleTemplates){
                com.ch5finland.n5._showTemplates(".portlet-boundary_N5SecondaryContentEditor_", visibleTemplates, false);
                com.ch5finland.n5._showTemplates(".portlet-boundary_N5ContentEditor_", visibleTemplates, false);
            },
            hideTemplates : function(hiddenTemplates){
                com.ch5finland.n5._showTemplates(".portlet-boundary_N5SecondaryContentEditor_", hiddenTemplates, true);
                com.ch5finland.n5._showTemplates(".portlet-boundary_N5ContentEditor_", hiddenTemplates, true);
            }
        }
    }
}

