/* --------------------------------- */
/* CORE SNIPPETS                     */
/* --------------------------------- */

var FullscreenrOptions = {  width: 1800, height: 1400, bgID: '#pageBackground' };
jQuery.fn.fullscreenr(FullscreenrOptions);


/* --------------------------------- */
/* SLIDESHOW                         */
/* --------------------------------- */


// JavaScript Document

$(document).ready(function() {
// fade in default image
$('#main_image img').css('display','none').fadeIn('normal');

// fade out inactive thumbnails
$('ul.gallery li.active').siblings().css({display:'none',opacity:'0.4'}).fadeIn(500);

// thumbnails hover effects
$('ul.gallery li').hover(function() {
$(this).not('.active').fadeTo('fast',1);
$(this).not('.active').css('position', 'relative').css('left', 0).css('top', 0); 
}, function() {
$(this).not('.active').fadeTo('fast',0.4);
}
);

// thumbnails click function
$('ul.gallery li').click(function() {

// set class for clicked thumbnail to active
$(this).addClass('active');

// fade out and remove active classes on all other thumbnails 
$(this).siblings().removeClass('active').fadeTo('fast',0.4);

// get image source reference from the thumbnail link and store in a variable
var img = $(this).children('a').attr('href');
// get image caption from the title attribute of the image tag
var caption = $(this).children('a').children('img').attr('title');

// fade out and hide the previous image
$('#main_image img').fadeOut().hide(); 
// and the caption
$('#main_image .caption').fadeOut().hide();

// set the new image source file and fade in the new image
$('#main_image img').attr('src',img);
$('#main_image img').fadeIn();
// set the caption text
$('#main_image .caption').text(caption).fadeIn();

});

});


/* --------------------------------- */
/* SET UP DYNAMIC TAB NAVIGATION     */
/* --------------------------------- */

$(function(){
  $('.core').each(function(){
    $(this).data( 'bbq', {
      cache: {
        '': $(this).find('.core-default')
      }
    });
  });
  $('.core a[href^=#]').live( 'click', function(e){
    var state = {},
      id = $(this).closest( '.core' ).attr( 'id' ),
      /* set up proper redirect scheme */
      url = $(this).attr( 'href' ).replace( /^#/, '' ); 
    state[ id ] = url;
    $.bbq.pushState( state );
    return false;
  });  
  $(window).bind( 'hashchange', function(e) {
    $('.core').each(function(){
      var that = $(this),
        data = that.data( 'bbq' ),
                url = $.bbq.getState( that.attr( 'id' ) ) || '';
      if ( data.url === url ) { return; }
      data.url = url; 
      that.find( 'a.core-current' ).removeClass( 'core-current' );      
      that.find( '.core-content' ).children( ':visible' ).hide();
      url && that.find( 'a[href="#' + url + '"]' ).addClass( 'core-current' );
      if ( data.cache[ url ] ) {
        data.cache[ url ].show();
      } else {
        that.find( '.core-loading' ).show();
        data.cache[ url ] = $( '<div class="core-item"/>' )
          .appendTo( that.find( '.core-content' ) )
          .load( url, function(){
            that.find( '.core-loading' ).hide();
          });
      }
    });
  })
  $(window).trigger( 'hashchange' );  
});

/* --------------------------------- */


(function($) {
  $.fn.toggleFade = function(settings)
  {
  	settings = jQuery.extend(
  		{
        speedIn: "normal",
        speedOut: settings.speedIn
  		}, settings
  	);
  	return this.each(function()
  	{
  	  var isHidden = jQuery(this).is(":hidden");
      jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
      

      
    });

  };
})(jQuery);






