function init() {
	tinyMCEPopup.resizeToInnerSize();
}

function insertEmotion(file_name) {
	tinyMCE.insertImage(tinyMCE.getParam('emotions_path') + file_name);
	tinyMCEPopup.close();
}

function emotions_onload()
{
    var html = '<table>';
    var images = tinyMCE.getParam('emotions_images', '', true, ',');
    var columns = tinyMCE.getParam('emotions_dialog_columns');
    var rows = Math.floor(images.length / columns + (images.length % columns ? 1 : 0));
    var i = 0;
    for (var y = 0; y < rows; y++)
    {
        html += "<tr>";

        for (var x = 0; x < columns; x++)
        {
            var image = "";
            if (i < images.length)
            {
                image = "<a href=\"#\" onclick=\"javascript:insertEmotion('"
                        + images[i] + "');\"><img src=\"" + tinyMCE.getParam('emotions_path') + images[i]
                        + "\" border=\"0\"/></a>";
                ++i;
            }
            html += "<td>" + image + "</td>";
        }

        html += "</tr>";
    }
    html += "</table>";
    document.getElementById('tableDiv').innerHTML = html;
}
