var amatomoi2_user_amazonid;
var amatomoi2_user_width;
var amatomoi2_user_type;
var amatomoi2_user_click;
var amatomoi2_user_image;
var amatomoi2_user_border_color;
var amatomoi2_user_background_color;
var amatomoi2_user_title_color;
var amatomoi2_user_price_color;

function amatomoi2_init_setting() {
    if ( amatomoi2_user_amazonid         == null ) { amatomoi2_amazonid         = "no-id";                     amatomoi2_noid = 1; }
                                              else { amatomoi2_amazonid         = amatomoi2_user_amazonid;     amatomoi2_noid = 0; }
    if ( amatomoi2_user_width            == null ) { amatomoi2_width            = "160";                           }
                                              else { amatomoi2_width            = amatomoi2_user_width;            }
    if ( amatomoi2_user_type             == null ) { amatomoi2_type             = "1";                             }
                                              else { amatomoi2_type             = amatomoi2_user_type;             }
    if ( amatomoi2_user_click            == null ) { amatomoi2_click            = "0";                             }
                                              else { amatomoi2_click            = amatomoi2_user_click;            }
    if ( amatomoi2_user_image            == null ) { amatomoi2_image            = "1";                             }
                                              else { amatomoi2_image            = amatomoi2_user_image;            }
    if ( amatomoi2_user_border_color     == null ) { amatomoi2_border_color     = "#aaf";                          }
                                              else { amatomoi2_border_color     = amatomoi2_user_border_color;     }
    if ( amatomoi2_user_background_color == null ) { amatomoi2_background_color = "#fff";                          }
                                              else { amatomoi2_background_color = amatomoi2_user_background_color; }
    if ( amatomoi2_user_title_color      == null ) { amatomoi2_title_color      = "#88f";                          }
                                              else { amatomoi2_title_color      = amatomoi2_user_title_color;      }
    if ( amatomoi2_user_price_color      == null ) { amatomoi2_price_color      = "#f22";                          }
                                              else { amatomoi2_price_color      = amatomoi2_user_price_color;      }
}

function amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) {
    if ( amatomoi2_amazonid == "no-id" ) {
        return "http://www.amazon.co.jp/exec/obidos/ASIN/" + amatomoi2_asin + "/ref=nosim";
    } else {
        return "http://www.amazon.co.jp/exec/obidos/ASIN/" + amatomoi2_asin + "/" + amatomoi2_amazonid + "/ref=nosim";
    }
}

function amatomoi2_display( amatomoi2_asin, amatomoi2_title, amatomoi2_imageurl_s, amatomoi2_imgsw, amatomoi2_imgsh, amatomoi2_imageurl_m, amatomoi2_imgmw, amatomoi2_imgmh, amatomoi2_price, amatomoi2_updown, amatomoi2_lowest, amatomoi2_checkflag ) {
    if ( amatomoi2_type == 1 ) {
        amatomoi2_display_type1( amatomoi2_asin, amatomoi2_title, amatomoi2_imageurl_s, amatomoi2_imgsw, amatomoi2_imgsh, amatomoi2_imageurl_m, amatomoi2_imgmw, amatomoi2_imgmh, amatomoi2_price, amatomoi2_updown, amatomoi2_lowest, amatomoi2_checkflag );
    } else {
        amatomoi2_display_type2( amatomoi2_asin, amatomoi2_title, amatomoi2_imageurl_s, amatomoi2_imgsw, amatomoi2_imgsh, amatomoi2_imageurl_m, amatomoi2_imgmw, amatomoi2_imgmh, amatomoi2_price, amatomoi2_updown, amatomoi2_lowest, amatomoi2_checkflag );
    }
}

function amatomoi2_display_type1( amatomoi2_asin, amatomoi2_title, amatomoi2_imageurl_s, amatomoi2_imgsw, amatomoi2_imgsh, amatomoi2_imageurl_m, amatomoi2_imgmw, amatomoi2_imgmh, amatomoi2_price, amatomoi2_updown, amatomoi2_lowest, amatomoi2_checkflag ) {
    document.write(
        '<div id="amatomoi2" style="width: ' + amatomoi2_width + 'px; padding: 2px; margin: 1px; border: 1px solid ' + amatomoi2_border_color + '; background-color: ' + amatomoi2_background_color + ';">' +
            '<table width="' + amatomoi2_width + '" style="word-break: break-all;">' +
            '<tr><td><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><span style="color: ' + amatomoi2_title_color + '; font-weight: bold; text-decoration: none;">' + amatomoi2_title + '</span></a></td></tr>'
    );

    if ( amatomoi2_image == 1 ) {
        if ( amatomoi2_width < amatomoi2_imgsw + 10 ) {
            amatomoi2_imgwidth = amatomoi2_width - 5;
            amatomoi2_widthstr = ' width="' + amatomoi2_imgwidth + '"';
        } else {
            amatomoi2_widthstr = '';
        }
        document.write(
            '<tr><td><center><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="' + amatomoi2_imageurl_s + '"' + amatomoi2_widthstr + ' border="0" alt="' + amatomoi2_title + '" /></a></center></td></tr>'
        );
    } else {
        if ( amatomoi2_width < amatomoi2_imgmw + 10 ) {
            amatomoi2_imgwidth = amatomoi2_width - 5;
            amatomoi2_widthstr = ' width="' + amatomoi2_imgwidth + '"';
        } else {
            amatomoi2_widthstr = '';
        }
        document.write(
            '<tr><td><center><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="' + amatomoi2_imageurl_m + '"' + amatomoi2_widthstr + ' border="0" alt="' + amatomoi2_title + '" /></a></center></td></tr>'
        );
    }
    if ( amatomoi2_checkflag != 0 ) {
        document.write( '<tr><td><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="http://c-kom.homeip.net/amatomo/js/asin/' + amatomoi2_asin.charAt(8).toLowerCase() + amatomoi2_asin.charAt(9).toLowerCase() + '/' + amatomoi2_asin + '.gif" border="0" /></a></td></tr>' );
    }
    if ( amatomoi2_click != 0 ) {
        document.write(
            '<tr><td>' +
            '<form style="margin:0px" method="POST" action="http://www.amazon.co.jp/gp/aws/cart/add.html">' +
            '<input type="hidden" name="ASIN.1" value="' + amatomoi2_asin + '" />' +
            '<input type="hidden" name="Quantity.1" value="1" />' +
            '<input type="hidden" name="AssociateTag" value="' + amatomoi2_amazonid + '" />' +
//            '<input type="hidden" name="SubscriptionId" value="11C6XA5JGX12MRVG3S82" />' +
            '<input type="image" src="http://c-kom.homeip.net/amatomo/images/amazon-buy-jp.gif" alt="amazon.co.jp¤ÇÇã¤¦" />' +
            '</form>' +
            '<tr><td>' +
            '</td></tr>' +
            ''
        );
    }
    if ( amatomoi2_noid == 0 ) {
        document.write(
            '<tr><td align="right">Powered by <a href="http://c-kom.homeip.net/amatomo/asin/' + amatomoi2_asin + '"><img src="http://c-kom.homeip.net/amatomo/images/amatomo_js_chip50x16.gif" width="50" height="16" border="0" style="margin: 1px 0px -3px 0px;" /></a></td></tr>'
        );
    } else {
        document.write(
            '<tr><td align="right">Powered by <a href="http://c-kom.homeip.net/amatomo/asin/' + amatomoi2_asin + '"><img src="http://c-kom.homeip.net/amatomo/images/amatomo_js_chip50x16_noid.gif" width="50" height="16" border="0" style="margin: 1px 0px -3px 0px;" /></a></td></tr>'
        );
    }
    document.write(
            '</table>' +
        '</div>'
    );
}

function amatomoi2_display_type2( amatomoi2_asin, amatomoi2_title, amatomoi2_imageurl_s, amatomoi2_imgsw, amatomoi2_imgsh, amatomoi2_imageurl_m, amatomoi2_imgmw, amatomoi2_imgmh, amatomoi2_price, amatomoi2_updown, amatomoi2_lowest, amatomoi2_checkflag ) {
    document.write(
        '<div id="amatomoi2" style="width: ' + amatomoi2_width + 'px; padding: 2px; margin: 1px; border: 1px solid ' + amatomoi2_border_color + '; background-color: ' + amatomoi2_background_color + ';">' +
            '<table width="' + amatomoi2_width + '" style="word-break: break-all;">'
    );

    if ( amatomoi2_image == 1 ) {
        if ( amatomoi2_width * 0.6 < amatomoi2_imgsw ) {
            amatomoi2_imgwidth = amatomoi2_width * 0.6;
            amatomoi2_widthstr = ' width="' + amatomoi2_imgwidth + '"';
        } else {
            amatomoi2_widthstr = '';
        }
        document.write(
            '<tr><td valign="top"><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="' + amatomoi2_imageurl_s + '"' + amatomoi2_widthstr + ' border="0" alt="' + amatomoi2_title + '" align="left" style="padding-right: 8px;" /></a>'
        );
    } else {
        if ( amatomoi2_width * 0.6 < amatomoi2_imgmw ) {
            amatomoi2_imgwidth = amatomoi2_width * 0.6;
            amatomoi2_widthstr = ' width="' + amatomoi2_imgwidth + '"';
        } else {
            amatomoi2_widthstr = '';
        }
        document.write(
            '<tr><td valign="top"><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="' + amatomoi2_imageurl_m + '"' + amatomoi2_widthstr + ' border="0" alt="' + amatomoi2_title + '" align="left" /></a>'
        );
    }

    document.write(
            '<a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><span style="color: ' + amatomoi2_title_color + '; font-weight: bold; text-decoration: none;">' + amatomoi2_title + '</span></a></td></tr>'
    );

    if ( amatomoi2_checkflag != 0 ) {
        document.write( '<tr><td><a href="' + amatomoi2_makeAmazonLink( amatomoi2_amazonid, amatomoi2_asin ) + '"><img src="http://c-kom.homeip.net/amatomo/js/asin/' + amatomoi2_asin.charAt(8).toLowerCase() + amatomoi2_asin.charAt(9).toLowerCase() + '/' + amatomoi2_asin + '.gif" border="0" /></a></td></tr>' );
    }
    if ( amatomoi2_click != 0 ) {
        document.write(
            '<tr><td>' +
            '<form style="margin:0px" method="POST" action="http://www.amazon.co.jp/gp/aws/cart/add.html">' +
            '<input type="hidden" name="ASIN.1" value="' + amatomoi2_asin + '" />' +
            '<input type="hidden" name="Quantity.1" value="1" />' +
            '<input type="hidden" name="AssociateTag" value="' + amatomoi2_amazonid + '" />' +
//            '<input type="hidden" name="SubscriptionId" value="11C6XA5JGX12MRVG3S82" />' +
            '<input type="image" src="http://c-kom.homeip.net/amatomo/images/amazon-buy-jp.gif" alt="amazon.co.jp¤ÇÇã¤¦" />' +
            '</form>' +
            '<tr><td>' +
            '</td></tr>' +
            ''
        );
    }
    if ( amatomoi2_noid == 0 ) {
        document.write(
            '<tr><td align="right">Powered by <a href="http://c-kom.homeip.net/amatomo/asin/' + amatomoi2_asin + '"><img src="http://c-kom.homeip.net/amatomo/images/amatomo_js_chip50x16.gif" width="50" height="16" border="0" style="margin: 1px 0px -3px 0px;" /></a></td></tr>'
        );
    } else {
        document.write(
            '<tr><td align="right">Powered by <a href="http://c-kom.homeip.net/amatomo/asin/' + amatomoi2_asin + '"><img src="http://c-kom.homeip.net/amatomo/images/amatomo_js_chip50x16_noid.gif" width="50" height="16" border="0" style="margin: 1px 0px -3px 0px;" /></a></td></tr>'
        );
    }
    document.write(
            '</table>' +
        '</div>'
    );
}

