/*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 initQTip(){
	jQuery('#staff-pics a img, .entry_author_image img').each(function() {
		jQuery(this).qtip({
			content: getContent(jQuery(this).attr('alt')),
			position: {
				corner: {
					target: 'topMiddle',
					tooltip: 'bottomMiddle'
				},
				//target: 'mouse',
				adjust: {
					y: -1
				}
			},
			show: {
				when: 'mouseover',
				solo: false,
				delay: 0,
				effect: {
					length: 100
				}
			},
			hide: { 
				effect: {
					length: 200
				}
			},
			style: {
				tip: {
					corner: 'bottomMiddle',
					size : {
						x: 6,
						y: 6
					}
				},
				border: {
					width: 1,
					radius: 1
				},
				padding: 5,
				width: 'auto',
				textAlign: 'left',
				name: 'light'
			}
		});
	});
}
//split title and subtitle for rollovers
function getContent(txt) {
	var parts = txt.split(',');
	var htmlTip = '<p class="staff-name">'+parts[0]+'</p>';
	if(parts[1]){
	 htmlTip = htmlTip + '<p class="staff-title">'+parts[1]+'</p>';
  }
  return htmlTip;
}

function initFancy(){
 // jQuery('.flickr-link').fancybox({'overlayShow': true, 'hideOnContentClick': true, 'overlayOpacity': 0.85});
}

jQuery(document).ready(function() {
  initFormTextClear();  
  //initTagToggle();
  initListClasses();
  //initSuperfish();
  initInputEffects();
  initQTip();
  Cufon.replace('.txt-rpl');  
  initFancy();
  jQuery('#outbound').hide();
});