$.fn.expander = function() {
	$('.head', this).siblings().hide();
    var expandedid = 'expanded';
    $('.head', this).bind('click', function() {
    	$('#' + expandedid + ' .head').siblings().hide('slow');
		var currentid = $(this).parent().attr('id');
		$('#' + expandedid).attr({id: ''});
		if(currentid !== expandedid) {
			$(this).siblings().show('slow');
			$(this).parent().attr({id: expandedid});
		}
		return false;
    })
} 

$.fn.scroller = function() {
	var speed = 'slow'; // Choose default speed
	$(this).each(function() {
		$(this).bind('click', function() {
			var target = $(this).attr('href'); // Get scroll target
			$(target).ScrollTo(speed);
			return false;
		});
	});
} 

$.fn.validate = function() {
	var effect = 'slideDown'; // Pick default effect
	var speed = 'fast'; // Choose default speed
	this.submit(function(e) {
		$('.error').remove();
		var er = 0;
		// Simple empty field validation
		$('.required').each(function (i) {
			var v = $(this).val();
			var mID = $(this).attr('id');
			if (v == '') {
				// Format the Error div
				var html = '<span class="error">Please complete this field</span>';
				$('#'+this.id).after(html);
				$('#'+mID).css('border','1px solid #FF0000');
				$('#'+mID).css('background','#FFBFC8');
				//Set focus to field with error
				$('#'+this.id)[0].focus();
				er++;
			}else{
				// Remove error class
				$('#'+mID).css('border','1px solid #000');
				$('#'+mID).css('background','#FFF');
				//$('#'+this.id).removeClass('errorField');
			}
		});
		spam = $('#c_spam').val();
		if(spam !== 'nizhoni') {
			// Format the Error div
			var html = '<br /><span class="error">This field must be "nizhoni"</span>';
			$('#c_spam').after(html);
			$('#c_spam').css('border','1px solid #FF0000');
			$('#c_spam').css('background','#FFBFC8');
			er++;
		}
		// Call Error effect
		$('div.error')[effect](speed);
		// Catch Submit Event on Error
		if (er) {
			alert('Please complete the fields in red!');
			e.preventDefault();
		}
	});
}