/**
 * @author     Bob Xia < xiamr@qq.com >
 * @version    $Id: index.js 353 2008-07-16 09:35:46Z wynn $
 */

window.addEvent('domready', function() {
	var topics = $('topicstb');
	if(topics){
		topics.getElements('tr').forEach(function(item){
			item.addEvent('mouseover',function(e){
				item.addClass('over');
			});
			item.addEvent('mouseout',function(e){
				item.removeClass('over');
			});
		});
	}
	var toptb = $('toptb');
	if(toptb){
		toptb.getElements('tr').forEach(function(item){
			item.addEvent('mouseover',function(e){
				item.addClass('over');
			});
			item.addEvent('mouseout',function(e){
				item.removeClass('over');
			});
		});
	}
	var form = $('new_post_form');
	if(form){
		form.msg = $extend(new Element('p').inject(form.getElement('h2'), 'after').set('slide', {duration: 'short', transition: 'linear'}).slide('hide'), {
			error : function(text){
				this.addClass('error').set('text', text).slide('in');
				return this;
			},
			success : function(text){
				this.addClass('success').set('text', text).slide('in');
				return this;
			},
			cleanup : function(text){
				this.erase('text').slide('out');
				return this;
			}
		});
		form.set('send', {
			onComplete: function(result){
				result = JSON.decode(result);
				if(result !== true){
					this.msg.error(result);
				}
				else{
					this.msg.success('帖子已发表!');
					this.reset();
					(function(){window.location.reload();}).delay(1500);
				}
			}.bind(form)
		}).addEvent('submit', function(e){
			e.stop();
			this.send();
		});
	}
	
});