// script.js for Fresca 0.9

(function ($) {

  $(function () {
    $('body').addClass('js-enabled');
    $('a, area').linkType();
    $('.external, .pdf').openWindow();
    $('.rollover').rollover();

  $('.cycle').fadeIn(1000).cycle({
    fx: 'fade',
    timeout: 6000
   });

				// We only want these styles applied when javascript is enabled
				$('.galleriffic-content').css('display', 'block');

				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 0.67;
				$('#thumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				

				// Initialize Advanced Galleriffic Gallery (Single)
				$('.galleriffic-single #thumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 15,
					preloadAhead:              10,
					enableTopPager:            false,
					enableBottomPager:         false,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          false,
					renderNavControls:         false,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
						this.fadeTo('fast', 1.0);
					}
				});


  });

  $.fn.linkType = function (options) {
    var o = $.extend({
      except: '.thumb'
    }, options);
    return this.
      not(o.except).
      filter('[href^="http"]').each(function () {
        if (this.hostname !== window.location.hostname) {
          $(this).addClass('external');
        }
      }).end().
      filter('[href^="https"]').addClass('ssl').end().
      filter('[href$=".pdf"]').addClass('pdf').end().
      filter('[href$=".zip"]').addClass('zip');
  };

  $.fn.openWindow = function () {
    return this.click(function () {
      window.open(this.href);
      return false;
    });
  };

  $.fn.rollover = function (options) {
    var o = $.extend({
      postfix: '-h'
    }, options);
    return this.each(function () {
      this.originalSrc = $(this).attr('src');
      this.rolloverSrc = this.originalSrc.replace(new RegExp('(' + o.postfix + ')?(\.gif|\.jpeg|\.jpg|\.png)$', 'i'), o.postfix + '$2');
      this.rolloverImg = new Image;
      this.rolloverImg.src = this.rolloverSrc;
    }).hover(function () {
      $(this).attr('src', this.rolloverSrc);
    }, function () {
      $(this).attr('src', this.originalSrc);
    });
  };

})(jQuery);

