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

		/* Blog Archive */
		if ($chk($('archiveList'))) {
			var lis = $$('#archiveList li');
			lis.each(function(li, i) {
				if (i>5) li.setStyle('display', 'none');
			});
			var showMore = new Element('a', {id: 'showMoreArchives'});
			showMore.innerHTML = 'Show More';
			showMore.setStyles({
				display: 'block',
				padding: '15px 0 0 0',
				cursor: 'pointer'
			});
			var archiveList = $('archiveList');
			showMore.inject(archiveList, 'after');
			showMore.addEvent('click', function(e) {
				e.stop();
				this.destroy();
				$$('#archiveList li').setStyle('display', 'block');
			});
		}
    
    /* - Blog Search - */
		if ($chk($('searchform')) && $chk($('searchsubmit'))) {
			$('searchsubmit').addEvent('click', function(e) {
				if ($('s').value == '') {
					e.stop();
					if (!$chk($('blogSearchErrors'))) {
						var errors  = new Element('div', {id: 'blogSearchErrors'});
						errors.innerHTML = 'Please type a search term in the box below';
						errors.setStyles({
							padding: '0 0 10px 0',
							color: '#CC0055'
						});
						errors.inject($('rowsearch'), 'before');
					}
				}
			});	
		}	
		/* - IE6 Submit Button Hovers & Thumb nail hovers - */
    if (Browser.Engine.version == 4) {		
      var lis = $$('span.button');
      lis.each(function(li){
        li.addEvent('mouseenter',function(){
          li.addClass('over');
        });
        li.addEvent('mouseleave',function(){
          li.removeClass('over');
        });
      });
	  var portraits = $$('a.portrait img');
	  portraits.each(function(portrait) {
			portrait.addEvent('mouseenter', function() {
				portrait.setStyle('border', '5px solid #7EB9BF');
			});
			portrait.addEvent('mouseleave', function() {
				portrait.setStyle('border', '5px solid #E8E8E8');
			});
	  });
    }
	
    /* - Blog Comments Validation & Ajax - */
    if ($chk($('blogcomments'))) {
      $('submit').addEvent('click', function(e) {
        e.stop();
        var errors = new Array();
        if ($chk($('commentauthor')) && $('commentauthor').value == '') {
          errors.push('You need to enter your name!');
        }
        if ($chk($('email')) && $('email').value == '') {
          errors.push('You need to enter an Email address, this will not be shown!');
        }
        if ($('comment').value == '') {
          errors.push('You need to enter a comment!');
        }
        if (errors.length == 0) {
          var submitComment = new Request({
            url: '/blog/wp-comments-post.php',
            method: 'post',
            onSuccess: function(responseText) {
              $('respondinner').innerHTML = '<h3>Thank you</h3><p>Your comment has been submitted, and will need to be approved by an administrator before it is published.</p>';
            }
          });
          submitComment.post({
            author: $('commentauthor').value,
            email: $('email').value,
            comment: $('comment').value,
            comment_post_ID: $('comment_post_ID').value
          });
        } else {
          var output = '<ul id="commenterrors">';
          errors.each(function(error) {
            output = output + '<li>' + error + '</li>';
          });
          output = output + '</ul>';
          $('ajaxresponse').innerHTML = output;
        }
      });
    }
	
});

