
jQuery.fn.wordCount = function(params)
{
  var p =  {
   counterElement:"display_count"
   };
 	
 	var total_words;

  if(params) {
      jQuery.extend(p, params);
  }

  //for each keypress function on text areas
 	this.keyup(function() {
    total_words=this.value.split(/[\s]+/).length;
    if(total_words == '1') {total_words = '0'}    
  	jQuery('#'+p.counterElement).html(total_words);
  });
 	this.click(function() {
    total_words=this.value.split(/[\s]+/).length;
    if(total_words == '1') {total_words = '0'}
  	jQuery('#'+p.counterElement).html(total_words);
  });  
  
};

jQuery.fn.clearonfocus = function() {
	jQuery(this)
		.bind('focus', function() {
			// Set the default value if it isn't set
			if ( !this.defaultValue ) this.defaultValue = this.value;
			// Check to see if the value is different
			if ( this.defaultValue && this.defaultValue != this.value ) return;
			// It isn't, so remove the text from the input
			this.value = '';
		})
		.bind('blur', function() {
			// If the value is blank, return it to the defaultValue
			if ( this.value.match(/^\s*$/) )
				this.value = this.defaultValue;
		});
};

$(function() {

	$("#secondary div:first-child").addClass('top'); 
	$('blockquote p:first-child').addClass('first-child');
	$('input[type=text]').addClass('text')
	$('input[type=text]').clearonfocus();
	$('input[type=submit]').addClass('submit');
	$('blockquote p:last-child').append('<img src="/images/ui/blockquote_end.png" alt="Closing quote" align="top" class="end-quote" />');
	$('hr').replaceWith('<div class="hr"><hr /></div>');
	$("div.hr:last-child").addClass('last-hr');
	$('ol.cf-ol').after('<p id="counter-holder">Word Count: <span id="display_count">0</span></p>');
	$('#cf_field_5').wordCount();
	$('#cycle-show').cycle({ 
    fx:    'fade', 
    speed:  3000,
    timeout:  8000,
    cleartype:1,
    nowrap:1,
    random:1
	});

});	
