// footer archives
$(function() {
	$('.footer-archives ul li:first, .footer-links ul li:first, .footer-recent-posts ul li:first').addClass('first');
});

// comments
$(function () {

/* MOBILE/IPAD TWEAKS */
if ($.browser.mobile) {
    $("h1, h2, .title p").css("visibility", "visible");
    $(".title h1 a").css("font-size","72px");
}

	$('#comment_form input, #comment_form textarea').each(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('defaultvalue'));
		}
	}).focus(function () {
		$(this).removeClass('inputerror');
		if ($(this).val() == $(this).attr('defaultvalue')) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('defaultvalue'));
		}
	});
	$('#comment_form').submit(function () {
		$('#submiterror').remove();
		var errors = 0;
		$(this).find('textarea, input').each(function () {
			if ($(this).val() == $(this).attr('defaultvalue')) {
				if ($(this).attr('name') != 'comment_post_ID') {
					$(this).val('');
				
				}			
			}
			if ($(this).hasClass('required') && $(this).val() == '') {
				$(this).addClass('inputerror');
				errors++;
			}
		});
		if (errors > 0) {
			$(this).find('textarea, input').each(function () {
				if ($(this).val() == '') {
					$(this).val($(this).attr('defaultvalue'));
				}
			});
			$(this).prepend('<div id="submit-error">Please complete the highlighted fields.</div>');
			return false;
		}
		return true;
	});
});


// anchor scroll
$(function() {
	$("a.anchor-scroll").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}
