document.writeln('<sc' + 'ript language="JavaScript" src="/sf/web/js/prototype.js"></scr' + 'ipt>');

document.writeln('<style type="text/css">\
.comment-summary\
{\
    max-height: 32px;\
    overflow: hidden\
}\
.comment-more-icon\
{\
    display: block;\
    float: right;\
    padding: 2px 4px 2px 4px;\
}\
.comment\
{\
    position: absolute;\
    z-index: 10000;\
    opacity: 1.0;\
    background-color: #ffffff;\
    border: 1px solid #333399;\
    color: #333399;\
    margin: 0px;\
    padding: 4px;\
    width: 330px;\
    display: block;\
    visibility: hidden;\
    font-size: 140%\
}\
.kr\
{\
    font-family: "Gulim";\\n\
}\
</style>');

function getElementsByClass(searchClass)
{
    if (document.all) {
        var classElements = new Array();
        var allElements = document.all;
        for (i = 0, j = 0; i < allElements.length; i++) {
            if (allElements[i].className == searchClass) {
                classElements[j] = allElements[i];
                j++;
            }
        }
    } else if (document.getElementsByTagName) {
        var classElements = new Array();
        var allElements = document.getElementsByTagName("*");
        for (i = 0, j = 0; i < allElements.length; i++) {
            if (allElements[i].className == searchClass) {
                classElements[j] = allElements[i];
                j++;
            }
        }
    } else {
      return;
    }

    return classElements;
}

function getElementScreenPosition(elem)
{
    var html = document.documentElement;
    var rect = elem.getBoundingClientRect();
    var left = rect.left - html.clientLeft;
    var top = rect.top - html.clientTop;

    return {left:left, top:top};
}

function getElementPosition(elem)
{
    var html = document.documentElement;
    var body = document.body;
    var scrollLeft = (body.scrollLeft || html.scrollLeft);
    var scrollTop  = (body.scrollTop || html.scrollTop);

    var pos = getElementScreenPosition(elem);

    var left = pos.left + scrollLeft;
    var top  = pos.top + scrollTop;
    return {left:left, top:top};
}

function include_plans(div_id) {
    document.open();
    document.write('<div id="' + div_id + '"></div>');
    document.close();

    var options = {};
    options.div_id = div_id;
    options.method = "get";
    options.asynchronous = false;
    options.onComplete = function(request) {
        $(request.request.options.div_id).innerHTML = request.responseText;

        var commentSummaryElems = getElementsByClass('comment-summary');
        for (var i = 0; i < commentSummaryElems.length; i++) {
            var elem = commentSummaryElems[i];
            Event.observe(elem, 'mouseover', function() {
                var commentElem = $(this.id + '-body');
                var commentIconElem = $(this.id + '-icon');

                if ('' != commentElem.innerHTML) {
                    var pos = getElementPosition(commentIconElem);
                    commentElem.style.visibility = 'visible';
                    commentElem.style.left = (pos.left - 350) + 'px';
                 }
            });

            Event.observe(elem, 'mouseout', function(event) {
                var commentElem = $(this.id + '-body');
                commentElem.style.visibility = 'hidden';
            });
        }
    }
    options.onFailure = function(request) {
        $(div_id).innerHTML = '読み込みに失敗しました';
    }
    options.onException = function(request, e) {
        $(div_id).innerHTML = '読み込み中にエラーが発生しました (' + e.name + ': '+ e.message + ')';
    }
    
    window.location.href.match(/(\/)([a-zA-Z0-9_\-]+)(\/[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+\/)$/);
    locale = RegExp.$2;
    slug = RegExp.$3;

    switch (locale) {
    case 'jp':
        php = 'index.php';
        break;
    default:
        php = 'index-' + locale + '.php';
        break;
    }

    new Ajax.Request('/sf/web/' + php + '/plan/list?url=' + escape(slug) , options);
}
