/*
 * This script requires jquery and access to an image replacement server to work.
 */

var defaultFont = "Museo 500";
var server = "/render/ImageReplace";

function replace(jq_array, a){
    jQuery.each(jq_array, function(i, val) {
        val = $(val);
        var the_styles = new Object();
        the_styles["width"] = val.width();
        the_styles["height"] = val.height();
        the_styles["text"] = val.text();
        the_styles["font"] = val.attr("font"),
        the_styles["font-size"]=val.css("font-size");
        the_styles["color"]=val.css("color");
	
        //copy parameter array values over to our the_styles
        if(a){
            $.each(a, function(name,value) {
                the_styles[name] = value;
            });
        }
        //hack all of the strings
        if(!the_styles.text){
            the_styles.text="Hello World";
        }
        the_styles.text= the_styles.text.replace(/ /g, "XxX");
        if(!the_styles.font){
            the_styles.font = defaultFont;
        }
        the_styles.font = the_styles.font.replace(/ /g, "XxX");
        the_styles.color = the_styles.color.replace(/ /g, "");
        //create url from associative array
        var the_url = server+"?";
        $.each(the_styles, function(name,value) {
            the_url += name+"="+value+"&";
        });
        val.load(the_url,function (responseText, textStatus, XMLHttpRequest) {
            //alert(responseText);//<div style='width:400px;height:18px;
            
            var wh = responseText.split("<div style='");
            //alert(wh);
            wh = wh[1].split(";");
            
            wh[0] = wh[0].replace("width:","");
            wh[1] = wh[1].replace("height:","");
            //alert(wh[0]+"x"+wh[1]);
            val.css("width", wh[0]);
            val.css("height", wh[1]);
        //val.css("border","solid 1px black");
        });
    });
}

$(document).ready(function () {
    replace($(".replace"),{
        "shadow":"eeedf2",
        "shadowBlur":"1"
    });

    replace($("#nav-content a"),{
        "font":"Museo 300",
        "shadow":"eeedf2",
        "shadowBlur":"0"
    });


    replace($(".widgettitle"),{
        "font":"Museo 500",
        "shadow":"eeedf2",
        "shadowBlur":"1"
    });

    replace($(".entry-title a"),{
        "font":"Museo 700",
        "shadow":"eeedf2",
        "shadowBlur":"1"
    });

    replace($(".replaceShadow"),{
        "font":"Museo 500",
        "color":"rgb(220,46,29)",
        "shadow":"cad5cb",
        "shadowBlur":"3"
    });
    
/*
    replace($(".featured-entry .entry-title"),{
        "font":"Museo 300",
        "shadow":"cccccc",
        "color":"rgb(220,46,29)"
    });
    */
});
