$(document).ready(function () {

    // hide/show comment list
    $('.page-id-6 .commentlist').hide(); // hide the list of comments
    $('.comments').wrapInner('<a href="#"></a>');
    $('.comments a').click(function () {
        $(this).parent().parent().find('.commentlist').toggle(400);
        return false;
    });
    // hide/show comment form
    $('.page-id-6 .commentform').hide();
    $('.page-id-6 #respond h3').wrapInner('<a href="#"></a>');
    $('.page-id-6 #respond h3 a').click(function () {
        $(this).parent().parent().find('.commentform').toggle(400);
        return false;
    });
    $('.page-id-6 .comment-reply-link').click(function () {
        $(this).parent().parent().parent().find('.commentform').show('slow');
    });

    // append ; to all list items (li) in post entries if it's not already present
	// todo script needs finishing to add full stops at the end of li bunches
    /* $('.entry li').each(function (index) {
        var foo = $(this).text();
        if (foo.charAt(foo.length - 1) != ';') {
            $(this).append(';');
        };
    }); */

    // post code prompt on contact page
    $('.prompt').hide();
    $('.wpcf7-form input, textarea, select').focus(function () {
        $(this).parent().parent().find('.prompt').fadeIn();
    },
    function () {
        $(this).parent().parent().find('.prompt').fadeOut();
    });

    /*// scrollto in-page anchors
		$('.skipLink li').localScroll();
		$('.nav-section li').localScroll();*/

    // enable local nav to scroll with viewport
    // set up layout for scrollto implementation
    // #content needs a height for this to work
    var totalHeight = $(document).height();
    var totalHeight = totalHeight - $('#header').height();
    var totalHeight = totalHeight - $('#footer').height();
    var totalHeight = totalHeight - 150;
    $('.page-id-3 #content, .page-id-6 #content').css('height', totalHeight);
    // replace floated property on this with relative positioning
    $('.page-id-3 #content-secondary, .page-id-6 #content-secondary').css({
        'position': 'relative',
        'top': '0',
        'left': '0'
    });
    // initiate scrollto
    $('.page-id-3 #content-secondary').scrollFollow();
    $('.page-id-6 #content-secondary').scrollFollow();

    /* fix invalid in-page id's (note to self: js doesn't validate html lewis)
		$('.hentry h3 a').each(function(index){
			var originalValue = $(this).attr('id');
			$(this).attr('id', 'foo' + originalValue)
			});
		$('.nav-section li a').each(function(index){
			var originalValue = $(this).attr('href');
			var originalValue = originalValue.replace('#', '');
			$(this).attr('href', '#foo' + originalValue);
			}); */



    /* apply .active class (arrow) to .nav-section buttons when pressed */
    $('.nav-section li a').click(function () {
        $('.nav-section li a').removeClass('active');
        $(this).addClass('active');
    });
	
	/* prepend ^ to all caption text */
	$('.wp-caption-text').prepend('<span>&uarr;</span> ');

});
