// Changes state of Systems pagview to whatever content is specified
function show_page(page) {
  location.hash = page;
  page = page.replace('#','');
  // Remove 'current' class from all subnav links
  $('#subnav li a').removeClass('current');
  $('#systems #right-column').removeAttr('class');
  // Add 'current' class to current link
  $('#subnav li.'+page+'-link a').addClass('current');
  $('#systems #right-column').addClass(page+'-column');
  // Hide all content
  $('div#copy div.content', 'body#systems').hide();
  // Show current content
  $('div#copy .'+page+'-box', 'body#systems').show();


}

// jQuery
$(document).ready(function(){

  // Preload images
  jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++) {
      jQuery("<img>").attr("src", 'images/' + arguments[i]);
    }
  }

  $.preloadImages(
    'logo.png',
    'intro-body.gif', 'intro-header.jpg',
    'about-body.gif', 'about-copy-header.gif', 'about-header.gif', 'about-left.jpg', 'about-right.jpg',
    'contact-body.gif', 'contact-copy-header.gif', 'contact-header.gif',
    'portfolio-body.gif', 'portfolio-copy-header.gif', 
    'process-body.gif', 'process-copy-header.gif', 'process-header.gif',
    'systems-body.gif', 'systems-copy-header.gif', 'systems-header.gif', 'systems-left.jpg',
    'systems-right-theaters.jpg', 'systems-right-lighting.jpg', 'systems-right-distributed.jpg', 'systems-right-automated.jpg',
    'welcome-body.gif', 'welcome-copy-header.gif', 'welcome-header.gif', 'welcome-left.jpg', 'welcome-right.jpg'
  );

  // Systems
  default_page = 'theaters' // default Systems section to show
  if (location.href.indexOf('systems') != -1) {
    if (location.href.indexOf('#') == -1) {
      show_page(default_page);
    } else {
      var hash = location.hash;
      show_page(hash);
    }
  }

  // Clickable logo
  $('#logo').click(function(){ location.href = 'index.php'; });

  // Portfolio

  // Initially set opacity on thumbs and add
  // additional styling for hover effect on thumbs
  var onMouseOutOpacity = 0.3;
  var onMouseInOpacity = 1;

  $('#thumbnails ul.thumbs li').css('opacity', onMouseOutOpacity).hover(
    function(){
      $(this).not('.selected').fadeTo('fast', 1.0);
    },
    function(){
      $(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
    }
  );

  var gallery = $('#gallery').galleriffic('#thumbnails', {
    delay:                  6000, // in milliseconds
    numThumbs:              4, // The number of thumbnails to show page
    preloadAhead:           -1, // Set to -1 to preload all images
    enableTopPager:         false,
    enableBottomPager:      true,
    imageContainerSel:      '#current_image', // The CSS selector for the element within which the main slideshow image should be rendered
    controlsContainerSel:   '.nav-controls', // The CSS selector for the element within which the slideshow controls should be rendered
    captionContainerSel:    '', // The CSS selector for the element within which the captions should be rendered
    loadingContainerSel:    '', // The CSS selector for the element within which should be shown when an image is loading
    renderSSControls:       false, // Specifies whether the slideshow's Play and Pause links should be rendered
    renderNavControls:      false, // Specifies whether the slideshow's Next and Previous links should be rendered
    playLinkText:           'Play',
    pauseLinkText:          'Pause',
    prevLinkText:           'Previous',
    nextLinkText:           'Next',
    nextPageLinkText:       'Next Page',
    prevPageLinkText:       'Previous Page',
    enableHistory:          false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes 
    autoStart:              true, // Specifies whether the slideshow should be playing or paused when the page first loads 

    onChange: function(prevIndex, nextIndex) {
      $('#thumbnails ul.thumbs').children()
      .eq(prevIndex).fadeTo('fast', 0.4).end()
      .eq(nextIndex).fadeTo('fast', 1.0);
    },
    onTransitionOut: function(callback) {
      $('#caption').fadeTo('fast', 0.0);
      $('#current_image').fadeTo('fast', 0.0, callback);
    },
    onTransitionIn: function() {
      $('#current_image').fadeTo('fast', 1.0);
      $('#caption').fadeTo('fast', 1.0);
    },
    onPageTransitionOut: function(callback) {
      $('#thumbnails ul.thumbs').fadeTo('fast', 0.0, callback);
    },
    onPageTransitionIn: function() {
      $('#thumbnails ul.thumbs').fadeTo('fast', 1.0);
    }
  });

});

