// +---------------------------------------------------------------------------+
// | Twitter Plugin for Geeklog - The Ultimate Weblog                          |
// +---------------------------------------------------------------------------+
// | public_html/admin/plugins/twitter/js/twitter.js                           |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2009-2010 mystral-kk - geeklog AT mystral-kk DOT net        |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+

var kzTwitter = {};

kzTwitter.addEventListener = function(target, type, callback) {
	if (target) {
		if (document.addEventListener) {	// W3C DOM 2
			target.addEventListener(type, callback, false);
		} else if (document.attachEvent) {	// Internet Explorer
			target.attachEvent('on' + type, callback);
		}
	}
}

kzTwitter.init = function() {
	var targets = ['block', 'center'],
		i,
		elm,
		label,
		handler;
	
	for (i = 0; i < targets.length; i ++) {
		elm = document.getElementById('tw_textarea_' + targets[i]);
		label = document.getElementById('tw_counter_' + targets[i]);
		
		if (elm && label) {
			handler = function(elm, label) {
				var that = kzTwitter,
					el = elm,
					lb = label;
				
				that.addEventListener(elm, 'keyup', function(e) {
					lb.innerHTML = 140 - el.value.length;
				});
			}(elm, label);
		}
	}
}

// Attaches the 'onload' event listener to window
kzTwitter.addEventListener(window, 'load', kzTwitter.init);
