// JavaScript Document

(function() {

    var url = 'js/news_event.php';

    news_event = function() {
        newsdata();
        voicedata();
    }

    var newsdata = function() {
        var params = {
            action: 'news'
        }

        new Ajax.Request(url, {
            method: 'post',
            parameters: $H( params ).toQueryString(),
            onSuccess: function(request) {
                var data = eval('(' + request.responseText + ')');

                var template = '<p><img src="images/top/icon.gif" alt="アイコン" height="9" width="8" />&nbsp;#{entry}</p>';
                template = new Template(template);

                var html = '';
                if (data.code == 1) {
                    var entry = data.data;
                    for(var i = 0; i < entry.length; i++) {
                        html += template.evaluate({
                            entry: entry[i].entry
                        });
                    }
                    Element.update('news', html);
                }
            }
        });
    }

    var voicedata = function() {
        var params = {
            action: 'voice'
        }

        new Ajax.Request(url, {
            method: 'post',
            parameters: $H( params ).toQueryString(),
            onSuccess: function(request) {
                var data = eval('(' + request.responseText + ')');

                var template = '<p><img src="images/top/icon.gif" alt="アイコン" height="9" width="8" />&nbsp;#{entry}</p>';
                template = new Template(template);

                var html = '';
                if (data.code == 1) {
                    var entry = data.data;
                    for(var i = 0; i < entry.length; i++) {
                        html += template.evaluate({
                            entry: entry[i].entry
                        });
                    }
                    Element.update('voice', html);
                }
            }
        });
    }

})();

document.observe('dom:loaded', news_event);

