var helper = {
	addEvent: function(obj, type, fn, capture) {
		var r;

		if ( obj.addEventListener ) {
				obj.addEventListener(type, fn, capture);
				return true;
		} else if ( obj.attachEvent ) {
				r = obj.attachEvent('on' + type, fn);
				return r;
		} else {
				obj['on' + type] = fn;
		}
	},

	cssjs: function(action, obj, c1, c2) {

		switch ( action.toLowerCase() ) {
		case 'add':

			if ( !helper.cssjs('check', obj, c1) ) {
				obj.className += obj.className ? ' ' + c1 : c1;
			}
			break;

		case 'check':
			return new RegExp('(^|\\s)' + c1 + '(\\s|$)').test(obj.className);

		case 'remove':
			var rep = obj.className.match(' ' + c1) ? ' ' + c1 : c1;
			obj.className = obj.className.replace(rep, '');
			break;

		case 'swap':
			obj.className = !helper.cssjs('check', obj, c1) ? obj.className.replace(c2, c1) : obj.className.replace(c1, c2);
			break;
		}
	},

	debug: null,

	debugAdd: function(bug) {
		var item;

		if ( !helper.debug ) {
			helper.debugBegin();
		}

		item = document.createElement('li');
		item.innerHTML = bug;
		helper.debug.appendChild(item);
	},

	debugBegin: function() {

		if ( helper.debug ) {
			helper.debugEnd();
		}

		helper.debug = document.createElement('ul');
		helper.debug.setAttribute('id', helper.debugWindowId);
		document.body.insertBefore(helper.debug, document.body.firstChild);
	},

	debugEnd: function() {

		if ( helper.debug ) {
			helper.debug.parentNode.removeChild(helper.debug);
			helper.debug = null;
		}
	},

	debugWindowId: 'helper-debug'
};
