jQuery(document).ready(function() {

	// Hide it
	jQuery(".colourInput").next(".pickerBlock").hide();

	// Add the colour picker
	jQuery("div.pickerBlock div.picker").each(function(a){
		var farbtastic = jQuery.farbtastic(this);
		jQuery(this).parent().prev(".colourInput").each(function(){ // FIX
			farbtastic.linkTo(this);
		})
	});

	// Show colour picker when the form field is clicked and hide all others
	jQuery(".colourInput").focus(function(){
		var pickerBlock = jQuery(this).next(".pickerBlock");
		jQuery(".pickerBlock").not(pickerBlock).slideUp(500);
		pickerBlock.slideDown(500);
	});

	// Hide it if the toggle is clicked
	jQuery(".farbToggle").click(function(){
		jQuery(this).parent().slideUp(500);
		return false;
	});

	// Clicking one of the bullet points will set the input field
	jQuery(".bulletColour").each(function(){
		var colour = jQuery(this).attr("rel").toLowerCase();
		var picker = jQuery(this).parent().prev(".picker");
		var fb = jQuery.farbtastic(picker);

		jQuery(this).click(function(){
			fb.setColor(colour);
		});

		// Check every half second to see if the colour is this bullets colour.
		//var thisBullet = jQuery(this);
		//var periodicTest = setInterval(function(){
		//	if (fb.color.toLowerCase() == colour) {
		//		thisBullet.animate({opacity:"1",fontSize:"14pt"});
		//	} else {
		//		thisBullet.animate({opacity:"0.4",fontSize:"8pt"});
		//	}
		//},500);
	});

});
