
$(function(){
// GALLERIFIC JQUERY IMAGE GALLERY
var onMouseOutOpacity = 0.67;
if(onMouseOutOpacity < 1 && onMouseOutOpacity >= 0){
$('#ImageGallery1 .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); }
}
);
}
$('#ImageGallery1 .gallery-adv').show();

var galleryCurrentPage = 0;
var showingFirstImageOfNewPage = false;
var galleryInTransition = false; //double-click fix hack
var galleryAdv = $('#ImageGallery1 .thumbs-adv').galleriffic({
delay:4000,
numThumbs:12,
preloadAhead: 10,
enableTopPager: true,
enableBottomPager:true,
maxPagesToShow: 4,
imageContainerSel:'#ImageGallery1 .slideshow-adv',
controlsContainerSel: '#ImageGallery1 .controls-adv',
captionContainerSel:'#ImageGallery1 .caption-adv',
loadingContainerSel:'#ImageGallery1 .loading-adv',
renderSSControls: true,
renderNavControls:true,
playLinkText: 'Play Slideshow',
pauseLinkText:'Pause Slideshow',
prevLinkText: "&lt; Previous Image",
nextLinkText: "Next Image &gt;",
nextPageLinkText: "Next Page &gt;",
prevPageLinkText: "&lt; Prev Page",
enableHistory:false,
autoStart:true,
syncTransitions:false, //allows overlapping transitions
defaultTransitionDuration: 400,
onSlideChange:function(prevIndex, nextIndex){
$('#ImageGallery1 .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 (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 = $("#ImageGallery1 .thumbs-adv");
//set up hyperlink on slide click
var hyperlink = $thumbs.find('li.selected').attr('data-hyperlink');
if (hyperlink){
$(slide).find('a').unbind('click').click(function(){
window.location = hyperlink;
return false;
});
}
},
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;
//hide items by sliding them out
$thumbs = $('#ImageGallery1 .thumbs-adv ul.thumbs');
$thumbsWrapper = $("#ImageGallery1 .thumbsWrapper");
if ($thumbsWrapper.length == 0){
$thumbsWrapper = $('#ImageGallery1 .thumbs-adv .thumbs').wrap('<div class="thumbsWrapper" />').parent().css('overflow','hidden');
}

if ($.browser.msie && parseInt(jQuery.browser.version.substr(0, 1))<= 7){
$thumbs.animate({
opacity: 0
}, {
duration: 100,
complete: callback
});
}
else {
$thumbs.css('position', 'relative');
if (showNextPage){ //slide left
$thumbs.animate({
left: '-110%'
}, {
duration: 200,
complete: callback
});
}
else { //slide right
$thumbs.animate({
left: '110%'
}, {
duration: 200,
complete: callback
});
}
}
},
onPageTransitionIn: function(){
//hide items by sliding them out
$thumbs = $('#ImageGallery1 .thumbs-adv ul.thumbs');
$thumbsWrapper = $("#ImageGallery1 .thumbsWrapper");
if ($thumbsWrapper.length == 0){
$thumbsWrapper = $('#ImageGallery1 .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');
}
});


//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();
});
});


