var flashTitle = new Object();

flashTitle = {

	flashes: new Array(),

    findTags: function( tag, cn ) {

        var returnArray = [];
        var els = document.getElementsByTagName( tag );

        var pattern = new RegExp('(^|\\s)'+cn+'(\\s|$)');
        for (var FSi = 0; FSi < els.length; FSi++) {
            if ( ((cn !== null || cn !== '') && pattern.test(els[FSi].className)) && (cn !== null || cn !== '') )
                returnArray.push(els[FSi]);
         }

        return returnArray;
    },

    addFlash: function( num, cn, flash, w, h, wmode ) {
        var data = new Array();
        data['num'] = num;
        data['className'] = cn;
        data['flash'] = flash;


        if ( w !== null )
            data['width'] = w;

        if ( h !== null )
            data['height'] = h;

        if ( wmode !== null )
            data['wmode'] = wmode;

        this.flashes.push( data );
    },


    replaceHeaders: function() {
        for ( var i=0; i<this.flashes.length ; i++ ) {
            var headers = this.findTags( this.flashes[i]['num'], this.flashes[i]['className'] );

            for ( var j=0; j<headers.length; j++ )	{
                if ( headers[j].id == null || headers[j].id == '' )
                    headers[j].id = 'flashTitle_' + i + '_' + j;

                if ( typeof this.flashes[i]['width'] !== 'undefined' ) {
                    var width = this.flashes[i]['width'];
                } else {
                    var width = headers[j].offsetWidth;
                }

                if ( typeof this.flashes[i]['height'] !== 'undefined' ) {
                    var height = this.flashes[i]['height'];
                } else {
                    var height = headers[j].offsetHeight;
                }

                var so = new FlashObject('top', this.flashes[i]['flash'], width, height);

                if ( this.flashes[i]['wmode'] !== null ) {
                    so.setAttribute('wmode', this.flashes[i]['wmode']);
                }

                headers[j].style.border = 'none';

                so.addVariable('Title', headers[j].innerHTML);
                so.write( headers[j].id );
            }
        }
    }

};

Event.register('load',function(){flashTitle.replaceHeaders();},window);

/* SET ME  (tagName, className, flashURI) */
flashTitle.addFlash('h1','','/gfx/title.swf', null, 110, 'transparent');
//flashTitle.addFlash('h2','','/gfx/NeoSans2.swf', null, 15, 'transparent');
//flashTitle.addFlash('h3','','/gfx/NeoSans3.swf', null, 15, 'transparent');
/*flashTitle.addFlash('h1','FlashTitle','/gfx/title.swf', null, null, 'transparent');*/

