window.addEvent('domready', function(){

$('emailbox').setStyle('opacity','0');
$('emailbox').setStyle('display','block');


var fontchange = $('articlebody');

$('smalltext').onclick = function(){
fontchange.tween('font-size', 12);
return false;
}

$('mediumtext').onclick = function(){
fontchange.tween('font-size', 15);
return false;
}

$('largetext').onclick = function(){
fontchange.tween('font-size', 20);
return false;
}


var emailcontainer = $('emailbox');
emailcontainer.set('tween', {duration: 300});

$('emailboxbutton').onclick = function(){
emailcontainer.tween('opacity', 1);
return false;
}

$('emailcancelbutton').onclick = function(){
emailcontainer.tween('opacity', 0);
return false;
}



	$('commentform').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		//Empty the log and show the spinning indicator.
		var log = $('formresponse').empty().addClass('formajaxloading');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			log.removeClass('formajaxloading');
			log.set('html', response);
			log.addClass('formajaxdone');
		}});
		//Send the form.
		this.send();
	});


$('emailform').addEvent('submit', function(e) {
//Prevents the default submit event from loading a new page.
		e.stop();
		//Empty the log and show the spinning indicator.
		var log = $('emailformresponse').empty().addClass('formajaxloading');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			log.removeClass('formajaxloading');
			log.set('html', response);
			log.addClass('formajaxdone');
		}});
		//Send the form.
		this.send();


	});


  $$('img.captioned').each(function(el) {						
    var captionText = ( el.getProperty('title')!=null ) ? el.getProperty('title') : el.getProperty('alt');
    if ( captionText!=null ) {
    
    var floatdirection = "left";
    
    if(el.getProperty('align') == "right"){
    	floatdirection = "right";
    }
    
    
      var figure = new Element('div', {'class' : 'figure','styles' : {'width' : el.getProperty('width').toInt() + 10, 'float': floatdirection}});
      var caption = new Element('p', {'class' : 'caption','html' : captionText});
      
      
    
    if(el.getProperty('align') == "right"){
    	figure.setStyle('margin-left', 10);
    }
    else
    {
    	figure.setStyle('margin-right', 10);
    
    }
    
    el.removeProperty('align');
    el.setStyle('margin', 0);
    
      figure.wraps(el);
      caption.inject(el,'after');
    } else {
      //alert('The image: "'+el.getProperty('src')+'" needs a title or alt value.');
    }
  });




});
