/* Create Cross Browsesr Method for accessing CSS rules */
if (document.styleSheets[0].cssRules) { 
    cssRules = document.styleSheets[0].cssRules;
}
else if (document.styleSheets[0].rules) {
    cssRules = document.styleSheets[0].rules;
}

/* Obtain the Needed Values from the css Rules */
var icnRule = "";
var txt1Rule = "";
var txt2Rule = "";
var txt3Rule = "";

for (i = 0; i < cssRules.length; i++) {
    if(cssRules[i].selectorText != undefined){
        if (cssRules[i].selectorText.toLowerCase() == ".icn1") {
            icnRule = cssRules[i];
        }

        if (cssRules[i].selectorText.toLowerCase() == ".txt1") {
            txt1Rule = cssRules[i];
        }

        if (cssRules[i].selectorText.toLowerCase() == ".txt2") {
            txt2Rule = cssRules[i];
        }

        if (cssRules[i].selectorText.toLowerCase() == ".txt3") {
            txt3Rule = cssRules[i];
        }
    }
}

/* Pull styles from style sheet otherwise set to defaults */
var icn1, txt1, txt2, txt3, tempcolor;

if (icnRule && icnRule.style.color != "") {
    tempcolor = colorToHex(icnRule.style.color);
    icn1 = "0x" + tempcolor.replace("#", "");
}
else {
    icn1 = "0xFFFFFF";
}

if (txt1Rule && txt1Rule.style.color != "") {
    tempcolor = colorToHex(txt1Rule.style.color);
    txt1 = "0x" + tempcolor.replace("#", "");
}
else {   
    txt1 = "0x000000";
}

if (txt2Rule && txt2Rule.style.color != "") {
    tempcolor = colorToHex(txt2Rule.style.color);
    txt2 = "0x" + tempcolor.replace("#", "");
}
else {
    txt2 = "0x000000";
}

if (txt3Rule && txt3Rule.style.color != "") {
    tempcolor = colorToHex(txt3Rule.style.color);
    txt3 = "0x" + tempcolor.replace("#", "");
}
else {
    txt3 = "0x000000";
}

/* Write out the DIV and Flash Content */
document.write("\<div class=\"rjBanner wealthManagementOutlook\">" +
    "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"151\" height=\"183\" id=\"test\" align=\"middle\">" +
    "<param name=\"allowScriptAccess\" value=\"sameDomain\" />" + 
    "<param name=\"movie\" value=\"/branches/library/banners/economic_outlook.swf?icn1=" + icn1 + "&amp;txt1=" + txt1 + "&amp;txt2=" + txt2 + "&amp;txt3=" + txt3 + "\" />" +
    "<param name=\"quality\" value=\"high\" />" +
    "<param name=\"bgcolor\" value=\"#ffffff\" />" +
    "<param name=\"wmode\" value=\"transparent\" />" +
    "<embed src=\"/branches/library/banners/economic_outlook.swf?icn1=" + icn1 + "&amp;txt1=" + txt1 + "&amp;txt2=" + txt2 + "&amp;txt3=" + txt3 + "\" width=\"151\" height=\"183\" align=\"middle\" quality=\"high\" bgcolor=\"#ffffff\" name=\"test\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\" />" +
    "</object></div>");
    
    
function colorToHex(color) {
    if (color.substr(0, 1) === '#') {
        return color;
    }
    var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);
    
    var red = parseInt(digits[2]);
    var green = parseInt(digits[3]);
    var blue = parseInt(digits[4]);
    
    var rgb = blue | (green << 8) | (red << 16);
    return digits[1] + '#' + rgb.toString(16);
}
