Cufon.replace('h1, #header h2, #group-panels h2, #unit-latest-news h2 a, .template-homepage #unit-features h2, .template-homepage #unit-intro h2, .template-homepage #unit-you-and-your-pet h3, #unit-twitter h3, .template-clinics #unit-clinic h2 ');
Cufon.replace('.template-homepage #unit-latest-news h2 a', {hover: true});

$(document).ready(function() {
	$.fn.clear = function() {
			return this.focus(function() {
				if( this.value == this.defaultValue ) {
					this.value = "";
				}
			}).blur(function() {
				if( !this.value.length ) {
					this.value = this.defaultValue;
				}
			});
		};
	$('#unit-mailing-list input.text').clear();
	
	//shorten twitter urls
	$("#unit-twitter .excerpt a, #unit-you-and-your-pet li .excerpt a").each(function(){
		if($(this).width() > $("#unit-latest-tweets").width())
		{
			var difference = $(this).width() - $("#unit-latest-tweets").width();
			var char_pixel_ratio = 3;
			var start_pos = 20;
			
			var chars_to_cull = Math.ceil(difference/char_pixel_ratio);

			var url = $(this).text();
			newurl = url.substr(0, start_pos);
			newurl += "&hellip;" + url.substr(start_pos + chars_to_cull);
			$(this).html(newurl);
			$(this).attr("title", url);
		}
	});
	
	$('.select-pet img').click(function(){
		var selected = $(this).attr('id').substr(7,$(this).attr('id').length);
		var target = 'select-'+selected;
		$('.select-pet img').fadeTo('fast',0.4);
		$('.select-pet #'+target).fadeTo('fast',1);
		$("#comment-field-animal").val(selected);
	});
	
	var animal_selected = $('#comment-field-animal option:selected').val();
	if (animal_selected) {
		$('.select-pet img').fadeTo('fast',0.4);
		$('.select-pet #select-'+animal_selected).fadeTo('fast',1);
	} 
		
	$('#comment-field-animal').hide();
	
});

