jQuery.fn.setupHyp = function() {

    var imageCount = 1;
    var headlineCount = 1;
    var flashplayer = "9.0.0";

	var swfparams = {
		menu: "false",
		wmode: "transparent",
		scale: "noscale",
		quality: 'high',
		align: 'middle',
		play: 'true',
		loop: 'true',
		devicefont: 'false',
		allowFullScreen: 'false',
		allowScriptAccess: 'sameDomain',
		movie: 'image',
		salign: 'lt'
	};
	
	
    var replaceHeadline = function(){
        
        $(this)[0].id = "headline"+headlineCount;
        
    	var fontsize = $(this).css("font-size");
    	fontsize = parseInt(fontsize);
    	    	
    	var color = $(this).css("color");
    	if (String(color).substr(0,1) != "#") {
            color = color.replace(/rgb/, "");
            color = color.replace(/\)/, "");
            color = color.replace(/\(/, "");
            color = color.split(/,/);
            color = rgb2hex(color);
        }
        else {
            color = color.replace(/#/gi, "0x");
        }

        
        swfparams['width'] = $(this).width();
        swfparams['height'] = fontsize+10;
        
        // flashvars
    	var flashvars = {
    	    text:escape($(this)[0].innerHTML.replace(/&amp;/, '&')),
    	    size:fontsize,
    	    color:color
    	};
    	
    	//margin & padding
        var margins = {
            style:"margin-left:" + $(this).css("margin-left") + "; margin-bottom:" + $(this).css("padding-bottom") + "; margin-top:" + $(this).css("padding-top") + ";"
        };


        $.swfobject.embedSWF("/header.swf", $(this)[0].id, $(this).width(), fontsize+10, flashplayer, "", flashvars, swfparams, margins);
        headlineCount++;
        
        //get hex format for rgb colour
        function rgb2hex(rgb) {
            //generates the hex-digits for a colour.
            function hex(x) {
                hexDigits = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
                return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x% 16];
            }

            return "0x" + hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
        }
    }
        
    // replace headlines
    $(this).find('h1').each(replaceHeadline);
    //$(this).find('h2').each(replaceHeadline);
    //$(this).find('h3').each(replaceHeadline);
    //$(this).find('h4').each(replaceHeadline);
}

