//************************************************************************

//	common.js

//************************************************************************//

jQuery(document).ready(function() {
	addThisButton();
	accordion();
	$('textarea').hint();
	
    $(function() {
        $('#icon-main a.lightbox').lightBox();
    });	
	
});

/*
 *	Accordion-type functionality
*/

function accordion(){
	var accList = $('ul.accordion');
	$('ul.accordion li div.acc_content').hide();
	
	var openLink = '<span class="open">Open</span>';
	
	$('ul.accordion li h2').append(openLink).css('cursor', 'pointer');
		
		var currentItem = this;
		$('ul.accordion li h2').click(function(){
			if($(this).find('span').html()=='Open'){
				$(this).parent().find('.acc_content').slideDown(500);
				$(this).find('span').html('Close').addClass('close');
				$(this).parent().addClass('open');
			}else{
				$(this).parent().find('.acc_content').slideUp(500);
				$(this).find('span').html('Open').removeClass('close');
				$(this).parent().removeClass('open');	
			}
		});		
}
/*
 *	the AddThis button
*/

function addThisButton(){
	var addthis_pub="nmsi";
	var addThis = $('#addThis');
	addThis.css('display', 'block');
	addThis.mouseover(function(){
		return addthis_open(this, '', '[URL]', '[TITLE]');
	});	
	addThis.mouseout(function(){
		addthis_close();
	});	
}

/*
 *	Pref-fill field
*/

jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};