document.getElementsByPartialClassName = function(value, parentElement) {
  var children = ($(parentElement) || document.body).getElementsByTagName('*');
  var elements = [], child;
  regexp = new RegExp('(?:^|\\\s)('+value+'.*?)(?:\\\s|$)');
  for (var i = 0, length = children.length; i < length; i++) {
    child = children[i];
    if (matches = Element.classNames(child).toString().match(regexp)) {
      elements.push(Element.extend(child));
    }
  }
  return elements;
};

var SWFSub = Class.create();

SWFSub.prototype = {
  
  initialize: function(args) {
    if (!document.getElementsByPartialClassName){ return; }
    if (typeof args != 'object') { args = {}; } // if no args, make args an empty hash
    
    this.element_count = 0; // initialize element count
    this.swf_path = args.swf_path ? args.swf_path : 'swf/'; // set the path to your swf files, uses swf/ by default
    this.class_prefix = args.class_prefix ? args.class_prefix : 'swf_'; // set the class prefix that we should look for, swf_ by default
    
    var els = document.getElementsByPartialClassName(this.class_prefix.replace(/_$/,'*'));
    for (var i = 0; i < els.length; i++) {
      this.apply(els[i], args); // apply method to each element found
    }
  },
  
  apply: function(el, args) {
    var regexp = new RegExp('(?:^|\\\s)'+this.class_prefix.replace(/\_$/,'')+'_?(.*?)(?:\\\s|$)'); // regexp to use to grab the full class name
    var class_name = Element.classNames(el).toString().match(regexp)[1]; // get the full class name
    var top_padding = Element.getStyle(el,'paddingTop').replace('px',''); // top padding of the element
    var right_padding = Element.getStyle(el,'paddingRight').replace('px',''); // right padding of the element
    var bottom_padding = Element.getStyle(el,'paddingBottom').replace('px',''); // bottom padding of the element
    var left_padding = Element.getStyle(el,'paddingLeft').replace('px',''); // left padding of the element
    var width = el.offsetWidth-left_padding-right_padding; // width to set movie (minus left and right padding)
    var height = el.offsetHeight-top_padding-bottom_padding; // height to set movie (minus top and bottom padding)
    var color = new RGBColor(Element.getStyle(el,'color')); // create a new color object from the current color style
    var textsize = Element.getStyle(el,'fontSize').replace(/px|em\%/,'');
    var transform = Element.getStyle(el,'textTransform');

    // get the swf file name
    // Use the part after 'swf_' (or passed in class_prefix value) of the class name, or use the actual element name as the movie name if class doesn't match
    var swf_file = (class_name.replace(new RegExp("^" + this.class_prefix + "_?"),'') > '' ? class_name.replace(new RegExp("^" + this.class_prefix + "_?(.*?)"),"$1") : el.nodeName.toLowerCase()) + '.swf';
    
    // Start a new SWFObject and write it to the document
    var so = new SWFObject(this.swf_path + swf_file, 'swf_sub_' + this.element_count, width, height, 8); // new SWFObject
    var txt = escape(el.innerHTML);
    if (transform == 'uppercase') {
      txt = txt.toUpperCase();
    }
    so.addVariable('txt', txt); // add the text from inside the element
    so.addVariable('textcolor', color.toHex()); // add the flash_hex color calculated previously
    so.addVariable('textsize', textsize);
    so.addVariable('w', width); // set the width variable of the movie
    so.addVariable('h', height); // set the height variable of the movie
    so.addParam('wmode', 'transparent');
    so.write(el); // write the movie to the page
    this.increment_elements(); // increment the total elements (for use in assigning id attribute, see line that instantiates new SWFObject)
  },
  
  increment_elements: function() {
    this.element_count++;
  }

}

//function initSWFSub() { mySWFSub = new SWFSub({swf_path:'images/',class_prefix:'my_prefix_'})}
function initSWFSub() { mySWFSub = new SWFSub({swf_path:'/cms-admin/swf/'}); }

jQuery.noConflict();
  
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
  initSWFSub();
});
