
$(function(){
// GALLERIFIC JQUERY IMAGE GALLERY
var onMouseOutOpacity = 1;
if(onMouseOutOpacity < 1 && onMouseOutOpacity >= 0){
$('#ImageGallery3 .thumbs-adv ul.thumbs li').css('opacity', onMouseOutOpacity)
.hover(
function (){
if($){ $(this).not('.selected').fadeTo('fast', 1.0); }
},
function (){
if($){ $(this).not('.selected').fadeTo('fast', onMouseOutOpacity); }
}
);
}
$("#ImageGallery3 .thumbs-adv a[rel=lightbox]").lightBox({useOverlayInIE:false, fixedNavigation:true, imageRoot:"/cirkuit/includes/"});

var galleryCurrentPage = 0;
var showingFirstImageOfNewPage = false;
var galleryInTransition = false; //double-click fix hack
var galleryAdv = $('#ImageGallery3 .thumbs-adv').galleriffic({
delay:4000,
numThumbs:12,
preloadAhead: 10,
enableTopPager: true,
enableBottomPager:true,
maxPagesToShow: 4,
imageContainerSel:'#ImageGallery3 .slideshow-adv',
controlsContainerSel: '#ImageGallery3 .controls-adv',
captionContainerSel:'#ImageGallery3 .caption-adv',
loadingContainerSel:'#ImageGallery3 .loading-adv',
renderSSControls: false,
renderNavControls:false,
playLinkText: 'Play Slideshow',
pauseLinkText:'Pause Slideshow',
prevLinkText: "&lt; Previous Image",
nextLinkText: "Next Image &gt;",
nextPageLinkText: "Next &gt;",
prevPageLinkText: "&lt; Prev",
enableHistory:false,
autoStart:false,
syncTransitions:false, //allows overlapping transitions
defaultTransitionDuration: 400,
onSlideChange:function(prevIndex, nextIndex){
$('#ImageGallery3 .thumbs-adv').find('ul.thumbs').children()
.eq(prevIndex).animate({'opacity':onMouseOutOpacity}, {duration:300}).end()
.eq(nextIndex).animate({'opacity':1}, {duration:300});
},
onTransitionOut:function(slide, caption, isSync, callback){
galleryInTransition = true;//double-click fix hack
$(slide).css('display','block').fadeTo('fast', 0, function(){
galleryInTransition = false;//double-click fix hack
callback();
});
},
onTransitionIn: function(slide, caption, isSync){
if(showingFirstImageOfNewPage){ //first image lightbox fix when not using slideshow
showingFirstImageOfNewPage = false;
return;
}
if (galleryInTransition){ //double-click fix hack
$(slide).remove(); 
$(caption).remove();
return;
}
$(caption).show().fadeTo(1,1).css('filter','');
$(slide).css('display','block').fadeTo(150, 1.0);
$("a[rel=lightbox]", caption).lightBox({useOverlayInIE:false, fixedNavigation:true, imageRoot:"/cirkuit/includes/"});

var $thumbs = $("#ImageGallery3 .thumbs-adv");
//lightbox from thumbnail click
$("a[rel=lightbox]:eq("+this.currentImage.index+")", $thumbs).click();
$(".selected", $thumbs).removeClass("selected");
},
onPageTransitionOut:function(callback){
showingFirstImageOfNewPage = true;
if(galleryCurrentPage == this.currentImage.index){ //first time the page loads, this gets called. dont animate this
callback();
return;
}
var showNextPage=false, showPrevPage=false;
if(this.currentImage.index == 0 || this.currentImage.index < galleryCurrentPage)showPrevPage=true;
else showNextPage=true;
galleryCurrentPage = this.currentImage.index;
$('#ImageGallery3 .thumbs-adv ul.thumbs').fadeOut('fast', callback);
},
onPageTransitionIn: function(){
//hide items by sliding them out
$thumbs = $('#ImageGallery3 .thumbs-adv ul.thumbs');
$thumbsWrapper = $("#ImageGallery3 .thumbsWrapper");
if ($thumbsWrapper.length == 0){
$thumbsWrapper = $('#ImageGallery3 .thumbs-adv .thumbs').wrap('<div class="thumbsWrapper" />').parent().css('overflow','hidden');
}

$thumbs.css({
position:'static',
top: 0,
left: 0,
'height':$thumbs.parent().height()
});
$thumbs.css('opacity','');
$thumbs.css('height','');

$thumbs.fadeIn('fast');
$(".selected", galleryAdv).removeClass("selected").fadeTo(1, onMouseOutOpacity);
}
});

$(".selected", galleryAdv).removeClass("selected").fadeTo(1, onMouseOutOpacity);

//set up hyperlinks
var $thumbs = $("#ImageGallery3 .thumbs-adv li[data-hyperlink] a.thumb").unbind('click').click(function(e){
var $this = $(this);
var hyperlink = $this.closest('li').attr('data-hyperlink');
window.location = hyperlink;
return false;
});

//huge hack so clicking the lightbox next buttons moves the image gallery. had to use mouseup cause click gets caught early in lightbox
$('#lightbox-nav-btnPrev, #lightbox-nav-btnNext').live('mouseup', function(){
if(this.id == 'lightbox-nav-btnPrev')
galleryAdv.previous();
else galleryAdv.next();
});
});


