var url = "http://entrecard.s3.amazonaws.com";



function ecard_render(user_id, top, right) {

    /* Write out iframe and contents */

    document.write('<iframe width="125px" style="border: none; position: absolute; top: '+top+'px; right: '+right+'px;" frameborder="0" scrolling="no" src="'+ url +'/adspot/' + user_id + '?nocache='+(Math.round(10000*Math.random()))+'" height="125px"></iframe>');

}



function ecard_button_render(user_id, bottom, left, width) {

    /* Write out button iframe in given position */

    document.write('<iframe width="'+width+'px" scrolling="no" style="position: absolute; bottom: '+bottom+'px; left: '+left+'px; border: none;" frameborder="0" height="22px" src="' + url + '/button.html?user_id=' + user_id+ '" border="0"></iframe>');

}



function ecard_widget_standard_127(user_id) {

    /* Write out 127 width thin widget */

    document.write('<div style="float: none; margin-left: auto; margin-right: auto; width: 125px; height: 148px; background-color: black; border: 1px solid #444444; position: relative;">');    

    details_url = "http://entrecard.com/user_details/" + user_id;

    document.write('<a href="' + details_url +'"><img style="border: none; position: absolute; padding: 0px; bottom: 0px; left: 0px; width: 21px; height: 22px;" src="' + url +'/images/125_logo.png" /></a>');

    /* Render ecard */

    ecard_render(user_id,0,0);

    /* Button */

    ecard_button_render(user_id, 0, 20, 105);

    /* Close up */

    document.write('</div>');

}



function ecard_widget_standard_200(user_id) {

    /* Write out 127 width thin widget */

    document.write('<div style="margin-left: auto; margin-right: auto; width: 200px; height: 127px; background: black url(' + url + '/images/dark_bg.png); position: relative;">')

    details_url = "http://entrecard.com/user_details/" + user_id;

    document.write('<a href="'+details_url+'"><img style="border: none; position: absolute; padding: 0px; top: 37px; left: 19px; width: 35px; height: 35px;" src="' + url +'/images/250_logo.png" /></a>');

    /* Render ecard */

    ecard_render(user_id,1,1);

    /* Button */

    ecard_button_render(user_id, 1, 1, 72);

    /* Close up */

    document.write('</div>');

}



function ecard_widget_standard_250(user_id) {

    /* Write out 127 width thin widget */

    document.write('<div style="margin-left: auto; margin-right: auto; width: 250px; height: 127px; background: black url(' + url + '/images/dark_bg.png); position: relative;">')

    details_url = "http://entrecard.com/user_details/" + user_id;

    document.write('<a href="'+ details_url + '"><img style="border: none; position: absolute; padding: 0px; top: 0px; left: 0px; width: 124px; height: 103px;" src="' + url +'/images/250_full_logo.png" /></a>');

    /* Render ecard */

    ecard_render(user_id,1,1);

    /* Button */

    ecard_button_render(user_id, 1, 1, 122);

    /* Close up */

    document.write('</div>');

}



function ecard_widget_new_127(user_id) {

    document.write('<iframe hspace="0" vspace="0" width="125px" style="border: 1px solid #444444;" frameborder="0" scrolling="no" src="'+ url +'/widget/127_standard.html?user_id=' + user_id + '&nocache='+(Math.round(10000*Math.random()))+'" height="148px"></iframe>');

}



function ecard_widget_new_200(user_id) {

    document.write('<iframe hspace="0" vspace="0" width="200px" style="border: 1px solid #444444;" frameborder="0" scrolling="no" src="'+ url +'/widget/200_standard.html?user_id=' + user_id + '&nocache='+(Math.round(10000*Math.random()))+'" height="125px"></iframe>');

}



function ecard_widget_new_250(user_id) {

    document.write('<iframe hspace="0" vspace="0" width="250px" style="border: 1px solid #444444;" frameborder="0" scrolling="no" src="'+ url +'/widget/250_standard.html?user_id=' + user_id + '&nocache='+(Math.round(10000*Math.random()))+'" height="125px"></iframe>');

}



/* and for 200 and 250 */



function ecard_widget_render(type, user_id) {

    /* Write out widget */

    /* Select appropriate type and call */

    /*

    if (type == "standard_127") {

        ecard_widget_standard_127(user_id);

    }

    if (type == "standard_200") {

        ecard_widget_standard_200(user_id);

    }

    if (type == "standard_250") {

        ecard_widget_standard_250(user_id);

    }

    */

    if (type == "standard_127") {

        ecard_widget_new_127(user_id);

    }

    if (type == "standard_200") {

        ecard_widget_new_200(user_id);

    }

    if (type == "standard_250") {

        ecard_widget_new_250(user_id);

    }

    if (type == "new_127") {

        ecard_widget_new_127(user_id);

    }

    if (type == "new_200") {

        ecard_widget_new_200(user_id);

    }

    if (type == "new_250") {

        ecard_widget_new_250(user_id);

    }

}



function get_param(url_path, name) {

    /* Get named parameter from query string */

    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

    

    var regexS = "[\\?&]"+name+"=([^&#]*)";

    var regex = new RegExp( regexS );

    var results = regex.exec( url_path );

    

    if( results == null )

        return "";

    else

        return results[1];

}

