/**
* headline_bright.js 
* Author: Christian Müller
* Email: christian.mueller@impigra.de
* URL: http://www.impigra.de
* Version: 0.0.1a
* No License available, but feel free to contact me for a solution.
*
* Used with the Open Source CMS Contenido
**/


window.addEvent('domready', function() {
/* replacing headlines */
    $$('h1.h_bright').each(function(headline) {
              var hlText = headline.get('html'); 
                    var strings = hlText.split(':');
                    
                    var text = strings[0];
                    
if(typeof strings[1] != 'undefined') {var bold = strings[1]}
else {var bold = ''}
                    
//                  var bold = strings[1].substring(0, (strings[1].length-4));
//                  var bold = strings[1]
//                  alert(strings[1]);
      if (hlText!='') { 
         // Pfad zum dynamischen Image 
                 
                 // HTML zwischen a Tags leeren 
         headline.empty(); 
         // Create span Element 
         var iSpan = new Element( 'span', {
                    'class' : 'hide',
          'html' : hlText 
                    });
                    // Span Element einfügen 
          iSpan.inject(headline, 'inside');
                 // obsolete
                 //var rnd = Math.floor(Math.random()*1111111);
                 // image path
                 if(bold != '') {
                 var path = 'images/headline_bright.php/foo.png?text='+text+'&textbold='+bold;
                 }
                 else {
                 var path = 'images/headline_bright.php/foo.png?text='+text;
                 }
         var iPath = new Image(); 
                 // manipulation on onload event
                 iPath.onload = function() {                        
            // Class setzen (background-position für hover setzen) 
            var iPathWidth = iPath.width; 
            // set class for anchor
                        headline.addClass('dynpng');
                        // set styles for anchor
                        headline.setStyles({
                            //display : 'block',
                            //width : iPathWidth,
                            height : 20,
                            'background-image' : 'url('+iPath.src+')',
                            'background-repeat' : 'no-repeat'
                            //float : 'left'
                        });
                    }
                    // set image path after onload section to catch the event
                    iPath.src = (path);
      } else {
                // error output
        alert('kein HTML Inhalt im Link ' +headline.getProperty('href')); 
      } 
    });

});