/* $Id: navarro.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.Navarro = function ()
{
  /*  
  ******************************************************************
  ** private variables available only to methods of the module.
  */
  var galleries = '';

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

  /*  
  ** private shorthand variable for built jQuery objects. set in init()
  */
  var gallery_args  = { width:	      650
		      ,	height:	      650
		      ,	transition:   'fade'
		      , autoplay:     true
		      , showInfo:     true
		      , _toggleInfo:  false
		      };

  /*  
  ** 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 carousel_callback = function (carousel)
  {
    carousel.buttonNext.click(function() {
      carousel.startAuto(0);
    });

    carousel.buttonPrev.click(function() {
      carousel.startAuto(0);
    });

    carousel.clip.hover(function() {
      carousel.stopAuto();
    }, function() {
      carousel.startAuto();
    });
  };

  /*
  ** private method banner_switch_action() -- The function that performs
  **					      the actual action of 
  **	changing from a banner slide to the next one.
  */
  var banner_switch_action = function ()
  {
    var $active = $('#banner img.active');

    // Add some default variables
    //
    if (0 == $active.length)
    {
      $active = $('#banner img:last');
    }

    var $next = $active.next().length 
	      ? $active.next()
	      : $('#banner img:first');

    $active.addClass('last-active');

    // Adds a blur transition effect.
    //
    $next .css({opacity: 0.0})
	  .addClass('active')
	  .animate({opacity: 1.0}, 1000, function() {
	    $active.removeClass('active last-active');
	  });
  };

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

    /*
    ** public method Ticode.Navarro.gallery_start() -	gallery starter.
    */
    , gallery_start : function ( )
      {
	theme_path = '/js/galleria/themes/classic/galleria.classic.min.js';
	Galleria.loadTheme(theme_path);

	$('#gallery-photos').galleria(gallery_args);
      }

      /*
      ** public method Ticode.Navarro.banner_switch() - Performs the 
      **						action of
      **    changing the slides over time.  This function is the 
      **    public interface of the actual slider switching function.
      */
    , banner_switch : function ( )
      {
	banner_switch_action();
      }

      /*
      ** public method Ticode.Navarro.banner_start() -- banner slider
      **						movement starter.
      */
    , banner_start : function ( )
      {
	setInterval('Ticode.Navarro.banner_switch()', 5000);
      }

      /*
      ** public method Ticode.Navarro.collapsible() - Prepares a box to
      **					      hide by default and
      **    a related link to open the box when user clicks it.
      */
    , collapsible : function ( )
      {
	var link_id = $(this).attr('id')
	  , box_id  = '#' + link_id + '-box'
	  , $link   = $(this)
	  , $box    = $(box_id)
	  , $other  = $('.collapsible')
	  ;

	// This is the event for displaying a box, triggered when the user
	// clicks the opener link.  It will also hide all other boxes.
	//
	var display_box	= function ()
	{
	  $other.hide();
	  $box.show();
	};

	// Bind the correct event.
	//
	$link.unbind();
	$link.click(function(e) {
	  e.preventDefault();
	  display_box()
	});

	// Hide other boxes, startup point.
	//
	$other.hide();
      }
    };
      /*
      ** for finding .attr('style', 'background:#ee9933');
      */
        //attr('style', 'background:#ee9933');

  return that;

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

}
)(jQuery);

$(document).ready(function () {
  var context = $('div#wrapper');

  // Site banner slideshow
  //
  $('#banner', context)	     .once('navarro', Ticode.Navarro.banner_start);

  // Photo gallery display
  //
  $('#gallery-photos', context)  
			    .once('navarro', Ticode.Navarro.gallery_start);

  // Display/collapse artifact
  //
  $('.box-opener', context)   .once('navarro', Ticode.Navarro.collapsible);
});

