jQuery(document).ready(function() {
 
	$('#comments').prepend('<a href="#commentsList" id="toggleComments" class="toggle"><span>Show/Hide Comments</span></a>');
	$('#respond').prepend('<a href="#commentForm" id="toggleForm" class="toggle"><span>Show/Hide Comment Form</span></a>');
	$('#commentsList').hide();
	$('#commentForm').hide();
	
	$('a.toggle').click(function(){
		
		var toggle = $(this);
		
		// Create a jQuery instance of the panel (via hash tag)
		$panel = $(this.hash);
		
		// If the panel is already open and not currently being animated
		if (toggle.hasClass('open') && (!$panel.is(':animated'))) {

			$panel.slideUp(function() {
				toggle.removeClass('open');
			});	
		} else {
			$panel.slideDown(function() {
				toggle.addClass('open');
			});
		} 
		return false;
	});
		
	// if there is a hash on the url that begins with 'comment', click the comments toggle.
	var windowHash = window.location.hash ? window.location.hash : ':first';
    if (windowHash.match(/^#comment/)) {
		$('#comments a.toggle').click();
    }
    
    // if the numComments link is clicked, click the comments toggle.
    $('.isSingle a.numComments').click(function() {
    	if (!$('#toggleComments').hasClass('open')) {
    		$('#comments a.toggle').click();
    	}
    });

	// Clear form values on focus
	$('#searchArchives input').focus(function() {
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    }).blur(function() {
	    if ($.trim(this.value) == ''){
	    	this.value = (this.defaultValue ? this.defaultValue : '');
	    }
    });
    
    // Init jQTools Scrollable gallery
	$('.postGallery').scrollable({
		size: 1,
		speed: 300,
		clickable: true
	}).navigator({ 
		navi: '.galleryNavi ul' 
	}); 

	// external links in a new window via http://www.martinish.com/blog/2009/07/opening-external-links-in-a-new-window-using-jquery/2/
    $('a[href^="http://"]').filter(function(){
    return this.hostname && this.hostname !== location.hostname; })
        .addClass("external")
        .click( function() {
            window.open(this.href);
            return false;
        });
    
});