/*This will add some nice behavior to form inputs and text fields
  add the class "clear-text" to the input or text-field to include
  this behavior*/
function clearText(field){
  if (field.defaultValue == field.value) field.value = '';
  else if (field.value == '')
    field.value = field.defaultValue;
}
function initFormTextClear(){
  jQuery("input[type=text].clear-text, textarea.clear-text").blur(
    function(event){clearText(event.target);}
  );
  jQuery("input[type=text].clear-text, textarea.clear-text").focus(
    function(event){clearText(event.target);}
  );
}
/*Add toggle behavior to tags link*/
function initTagToggle(){
  jQuery(".tag-link").click(
    function(event){
      jQuery('#'+jQuery(this).attr('id')+'-list').toggle();
      if(jQuery('#'+jQuery(this).attr('id')+'-list').css('display') == 'none')
        jQuery('#'+jQuery(this).attr('id')+'-dir').html('&raquo;');
      else
        jQuery('#'+jQuery(this).attr('id')+'-dir').html('&laquo;');  
    }
  );    
}
/*Adds list classes for first and last list elements*/
function initListClasses(){
  jQuery('ul li:first-child').addClass( 'list-first' );
  jQuery('ul li:last-child').addClass( 'list-last' );
  jQuery('ol li:first-child').addClass( 'list-first' );
  jQuery('ol li:last-child').addClass( 'list-last' );
}
/*Adds the drop down menu*/
function initSuperfish(){
 jQuery("ul.sf-menu").superfish({delay:200, speed:'fast'}).find('ul').bgIframe({opacity:false});
}
/*Does cool input effects*/
function initInputEffects(){

  // Select all textboxes and assign them to an array
  var textboxes = jQuery('input.input-text, textarea.input-text');

  // Iterate through all textboxes in the form
  textboxes.each(function(index){
  
		var input = jQuery(this);
    var label = jQuery(this).prev();

    // Fade the label back when a field gains focus		
    input.focus(function(){
      if (input.val()==""){
        label.addClass('focus');            
      }
    });

    // Check if a field is empty when the user switches out
   input.blur(function(){
      if (input.val()==""){
        label.removeClass('focus').removeClass('hastext');          
      }
    });

    // Fade the label back if a field has text		
    if (!input.val()=="") {
      label.addClass('hastext');
    }

    // Fade the label back when the user starts to type		
    input.keypress(function(){
      label.addClass('hastext');
    });
  });

}

function initSlideshow(){
  jQuery('#slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

}

jQuery(document).ready(function() {
  initFormTextClear();  
  initTagToggle();
  initListClasses();
  //initSuperfish();
  initInputEffects();
  initSlideshow()
});