// $Id: dental960.js $
/*
** we're using the jQuery based javascript, but our design pattern will be
** the Yui object paradigm which is much better at stability and 
** expandability.
*/
var Ticode = (("undefined" == typeof Ticode) || (!Ticode)) ? {} : Ticode;

(
function ($)
{

Ticode.Dental960 = function ()
{
  /*  
  ******************************************************************
  ** private variables available only to methods of the module.
  */

  /*  
  ** private shorthand variables to comon jQuery parts/utilities
  */

  /*  
  ** private shorthand variable for built jQuery objects. set in init()
  */

  /*  
  ** constants used in this module.
  */

  /*  
  ** module state:
  */

  /*  
  ** these are Dom refrences that won't change, they are set by direct
  ** calls when needed, and then used freely after that.
  */

  /*  
  ** ******************************************************************
  ** private methods available only to other methods of the module.
  */

  var that =
    /*
    ** publicly accessible variables where we store AJAX results by
    ** evaluating valid js pointing to these arrays.
    */
    { translations: [] // Ticode.Dental960.translations[]

      /*
      ** public method Ticode.Dental960.swapper_image_init() --
      **
      **    Allows an image to switch over with an alternate image while
      **    user hovers over it.
      **
      **  NOTE: This requires jquery.metadata.min.js and 
      **	jquery.swapimage.min.js
      **  NOTE: This may not be available for all pages, as only few of
      **        them actually requires this feature.  To reduce JS load,
      **	I added the jquery library includes for this only on
      **	those pages I require them.  For libs includes check
      **	[THIS THEME]/preprocess/preprocess-node.inc
      */
    , swapper_image_init: function ( )
      {
	// hovering image swaps (mainly for the before/after section).
	// image tags should have the following structure:
	//
	//	<img  class="swapImage {src: '[PATH_TO_ROLLOVER']}"
	//	      src="[PATH_TO_ORIG]" alt="" />
	//
	// SRC: http://code.google.com/p/jquery-swapimage/
	//
	if ($.isFunction($.swapImage))
	{
	  $.swapImage('.swapImage');
	}
      }

      /*
      ** public method Ticode.Dental960.fix_page_wimage() --
      **
      **    Adds a reference class to know if a page has a side-image
      **    and allow style fix for that.
      */
    , fix_page_wimage: function ( )
      {
	$('article.node-page').addClass('with-side-image');
      }

      /*
      ** public method Ticode.Dental960.switchboxes_init() --
      **
      **    Initialize the switching boxes that will hide and show based 
      **    on user selection in activator buttons.
      */
    , switchboxes_init: function ( )
      {
	var box_id  = '#' + $(this).attr('id') + '-box'
	  ;
	
	var openAction  = function (e)
	  {
	    e.preventDefault();

	    $('.display-box') .hide();
	    $(box_id)	      .show();
	  };

	$(this)		  .click(openAction);
	$('.display-box') .hide();
      }

    };
      /*
      ** for finding .attr('style', 'background:#ee9933');
      */
        //attr('style', 'background:#ee9933');

  return that;

}(); // the parens here cause the anonymous func to execute and return

Drupal.behaviors.Dental960 =
{
  attach: function(context, settings)
  {
    // first we init the hs and then create other attached behaviors
    //
    $('.opener', context)
	      
		      .once('dental', Ticode.Dental960.switchboxes_init);
    
    // check page type, if there is photo, add a class for further styling
    //
    $('body.page-node.node-type-page .field-name-field-side-image', context)
		    
			.once('dental', Ticode.Dental960.fix_page_wimage);

    // Sets the swap-image utility
    //
    $('body.page-node.node-type-page article.node-page', context)

		     .once('dental', Ticode.Dental960.swapper_image_init);
  }
};

}
)(jQuery);
;

