// Snippet Toggle
$(function() {
	$('#delete-switch').click(function(){
		$('#delete').slideToggle('slow');
		return false;
	});
	$('#edit-switch').click(function(){
		$('#edit').slideToggle('slow');
		$('#snippet').slideToggle('slow');
		return false;
	});
});

// Autosuggest results
function lookup(inputString) {
	if(inputString.length == 0) {
		$('#suggestions').fadeOut(50);
	} else {
		$.post("process/stringsearch.php", {mysearchString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#search-results-wrap').fadeIn();
				$('#search-results').html(data);
			}
		});
	}
} //end
$(function() {
	$("#close").click( function(){
		$("#search-results-wrap").fadeOut(500);
	});
});

// Hover logo
$(function(){
	$("#logo a").hover(function(){
		$(this).animate({opacity: 0.4}, 200); // This should set the opacity to 100% on hover
		},function(){
		$(this).animate({opacity: 1}, 500); // This should set the opacity back to 60% on mouseout
	});
});

// wait for the DOM to be loaded 
$(document).ready(function() { 
    // bind 'myForm' and provide a simple callback function 
    $('#edit-form').ajaxForm(function() { 
    	//alert("Thank you for your comment!");
    	$("#edit-form").slideUp( function(){
    		$("#edit").html("Saved");
    		setTimeout(function(){
    			$("#edit").slideUp();
    			location.reload();
			}, 200);
    	});
    }); 
}); 

// Toggle edit option in Account
$(function(){
	$("fieldset input").css({opacity: 0});
    $(".switch").toggle(function() {
        $(this).parent().find('fieldset input').animate({opacity: 1}, 400);
    },function() {
        $(this).parent().find('fieldset input').animate({opacity: 0}, 400);
    });
});

// Code Clip
$(function() {
    var $title = $("#snippet h2").text();
    $("#snippet pre").each(function() {
        var $preblock = $(this);
        var $codeblock = $preblock.find("code");
        var $snippet = "codaclips://<<**Title:" + $title + "**>>" + encodeURIComponent($codeblock.text());
        $('<a class="coda-clip">Add Coda Clip</a>').attr("href",$snippet).appendTo("#codaclip");
    });
});	
