var mySlide;
window.addEvent('domready', function() {
//sliding top menu
mySlide= new Fx.Slide('topbarmenuwrapper');
$('topbar').addEvent('mouseenter', function(e){
	e = new Event(e);
	mySlide.slideIn();
	e.stop();
});

$('topbar').addEvent('mouseleave', function(e){
	e = new Event(e);
	mySlide.slideOut();
	e.stop();
});

//ballen //causing ie to trip....

var ball = $E('#dot1');
var fx = new Fx.Styles(ball, {duration: 1000, wait: false});
var ball2 = $E('#dot2');
var fx2 = new Fx.Styles(ball2, {duration: 1000, wait: false});

fx.options.transition = Fx.Transitions['Elastic']['easeIn'];
fx2.options.transition = Fx.Transitions['Elastic']['easeIn'];

new Drag.Base(ball, {
 
	onComplete: function(){
		fx.start(this.s);
	},
 
	onStart: function(){
		this.s = {
			'left': '197px',
			'top': '37px'
		};
	}
 
});

new Drag.Base(ball2, {
 
	onComplete: function(){
		fx2.start(this.s);
	},
 
	onStart: function(){
		this.s = {
			'left': '565px',
			'top': '90px'
		};
	}
 
});


//moocomments stuff
if(!window.mcpoptions) mcpoptions = {
		throbber : '/wp-content/plugins/moojax-comment-posting/throbber.gif',
		killForm : false
	};
	if($('commentform')) {
	var preT = new Image();
	preT.src = mcpoptions.throbber;
		$('commentform').addEvent('submit', function(ent) {
	try {
		var error = '';
		var elfocus = '';
		if(this.author && this.author.value == '') {
			error += '<br />Geef je naam op!';
			this.author.focus();
		}
		if(this.email && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(this.email.value))) {
			error += '<br />Geef een geldig e-mail adress op!';
			this.email.focus();
		}
		
		if(this.comment.value == '' || this.comment.value == this.comment.title) {
			error += '<br />Je bent vergeten een reactie te geven...';
			this.comment.focus();
		}
		if(error != '')
			mcp_error(error);
		else {
			$('comment').setStyle('background', 'transparent url('+mcpoptions.throbber+') no-repeat 50% 50%');
			this.send({
				evalScripts : true,
				onFailure : function() {
				try {
					var errorMessage = this.transport.responseText.split('<body>')
						errorMessage = errorMessage[1].split('</body>')
					mcp_error(errorMessage[0]);
					} catch(e) {
						mcp_error(this.status);
						$('ajaxxed').remove();
						$('commentform').removeEvents('submit').fireEvent('submit');
					}
				}
			});
		}
		new Event(ent).stop();
		return false;
			} catch(e) {return true;}
	}.bind($('commentform')));
	new Element('input', {
		id : 'ajaxxed',
		type : 'hidden',
		name : 'moojaxxed',
		value : 'true'
	}).injectInside($('commentform'));
	a = new Image(); a.src = mcpoptions.throbber;
	}

});

window.addEvent('load', function() {
	setTimeout("mySlide.slideOut();", 800);
});

//comments functions:
mcp_removeForm = function() {
	if(mcpoptions.killForm) {
		var hider = new Element('div').injectBefore($('commentform'));
		$('commentform').injectInside(hider);
		hider.setStyle('overflow','hidden');
		var winFx = new Fx.Styles(hider, {duration: 1800});
		winFx.start({
			opacity : [1,0],
			height : [hider.getStyle('height').toInt(), 0],
			'margin-bottom' : [0,hider.getStyle('height').toInt()]
		}).chain(function() {
			hider.remove();
		});
	} else
		$('comment').value = '';
};

mcp_ajaxDone = function() {	//remove all signs of ajax activity
	$('comment').setStyle('background', '');
};

mcp_error = function(errorMessage) {
	mcp_ajaxDone();
	var err = new Element('div', {'class': 'error' }).setHTML(errorMessage).injectBefore($('comment'));
	var errSlide = new Fx.Slide(err);
	var errFx = new Fx.Style(err, 'opacity', {duration:1000});
	errFx.start(0.1,0.9).chain(function(){
	errFx.start(0.9,0.1);
}).chain(function(){
	errFx.start(0.1,0.9);
}).chain(function() {
	errSlide.slideOut();
});
}