
// slide show global variables
var s4c__slideshowHandler = null;
var s4c__slideshowDelay = 5; // seconds

function s4c__slideshowPlay()
{
  // this advances the
  // gallery at intervals
  jQuery.galleria.next();
  s4c__slideshowHandler = setTimeout('s4c__slideshowPlay()', s4c__slideshowDelay * 1000);
}


jQuery(function($) { 
  
  $('ul.galleria-gallery').galleria({
  	history   : false, // deactivates the history object for bookmarking, back-button etc.
  	clickNext : true, // helper for making the image clickable
  	insert    : '#s4c-galleria-feature', // the containing selector for our main image
  	
  	onImage   : function(image, caption, thumb) { // let's add some image effects for demonstration purposes
  			
  		// fetch the thumbnail container
  		var _li = thumb.parents('li');
  		
  		// fade out inactive thumbnail
  		_li.siblings().find('img.selected').fadeTo(500,0.4);
  		
  		// fade in active thumbnail
  		thumb.fadeTo('fast',1).addClass('selected');
  		
  		// add a title for the clickable image
  		image.attr('title','Next image >>');
  		
  		// ensure the image is not wider than box
  		// use the styled width for the container
  		var _div = image.parents('div.feature'); 
  		var _width = parseInt(_div.css('width').replace(/px/, ''));
  		if (image.width() > _width) image.css({width: _width});
  		
  		// ensure the image is not taller than wrapper
  		// use the styled width for the image container
  		var _div = image.parents('div.galleria_wrapper'); 
  		var _height = parseInt(_div.css('height').replace(/px/, '')) - 8;
  		if (image.height() > _height) image.css({height: _height});
  		
  		// now center the image within the available height
  		//image.css({marginTop: -(image.height() - _height)/2});  									
  	},
  	
  	onThumb : function(thumb) { // thumbnail effects goes here
  		
  		// fetch the thumbnail container
  		var _li = thumb.parents('li');
  		
  		// if thumbnail is active, fade all the way.
  		var _fadeTo = _li.is('.active') ? '1' : '0.3';
  		
  		// fade in the thumbnail when finnished loading
  		thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
  		
  		// hover effects
  		thumb.hover(
  			function() { thumb.fadeTo('fast',1); },
  			function() { _li.not('.active').find('img').fadeTo('fast',0.4); } // don't fade out if the parent is active
  		)
  	}
  });


});

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

  // add the proper actions to the next and previous links
  $('#s4c-galleria-navigation a.previous').click(function(e) {
    e.preventDefault();
    $.galleria.prev();
  });
  $('#s4c-galleria-navigation a.next').click(function(e) {
    e.preventDefault();
    $.galleria.next();
  });
  
  // preload drop down arrow
  var loader = new Image();
  $(loader).attr('src', 'pics/item__tiny_up_arrow_black.gif');
  
  // open and close the drop down menu when selector is clicked
  $('div#s4c-header-gallery-menu div.drop-down').click(function(e) {
    var opt = $(this).children('ul.options');
    
    if (!$(e.target).closest('div#s4c-header-gallery-menu ul.options').size())
      $(this).children('ul.options').toggleClass('s4c-hidden');
      
    if (opt.hasClass('s4c-hidden')) $(this).removeClass('open');
    else $(this).addClass('open');
  });
  
  // click outside drop closes menu
  $(document.body).click(function(e) {
    if (!$(e.target).closest('div#s4c-header-gallery-menu div.drop-down').size())
    {
      var menu = $('div#s4c-header-gallery-menu div.drop-down');
      menu.children('ul.options').addClass('s4c-hidden');
      menu.removeClass('open');
    }
  });
  
  // add the slide show controls functionality to the play link
  $('div#s4c-galleria-navigation div.left a').click(function(e) {
    var el = $(this).blur();
    e.preventDefault();
    
    // determine if slideshow
    // is underway and take action
    if (el.hasClass('playing'))
    { 
      el.text('PLAY SLIDESHOW'); 
      el.removeClass('playing');
      clearTimeout(s4c__slideshowHandler);
    }
    else 
    { 
      el.text('PAUSE SLIDESHOW'); 
      el.addClass('playing');
      s4c__slideshowPlay();
    }
  });
       
});

jQuery(document).ready(function($){
  
  // access the right column of the page with the video links 
  var r = $('div#s4c-content-gallery div.s4c-content-column-right');
  
  // add the capability for all exapnder links
  // to open the text video links section on page
  r.find('.list-expander').click(function(e) {
    var $ = jQuery;
    e.preventDefault();
    e.stopPropagation();
    
    // get a reference to the right column container 
    var r = $(this).parents('div.s4c-content-column-right')
    if (r.find('div.boxed-arrow').hasClass('expanded')) return;
    r.find('div.boxed-arrow').addClass('expanded');
    
    // slide down the links and after
    // that slide up the click for more
    var l = r.find('div.text-links');
    l.slideDown('normal', function() {
      var $ = jQuery;
      var r = $('div#s4c-content-gallery div.s4c-content-column-right');
      r.find('div.click-for-more').slideUp('slow');
    });
    
  });
  
});


  
