hs.graphicsDir = '/images/hs/';
hs.transitions = ['expand', 'crossfade'];
hs.restoreCursor = null;
hs.creditsPosition = 'bottom left';

// Add the slideshow providing the controlbar and the flower
hs.addSlideshow({
	slideshowGroup: 'gallery',
	interval: 5000,
	repeat: true,
	useControls: false,

	thumbstrip: {
		position: 'bottom center',
		mode: 'horizontal',
		relativeTo: 'expander',
		offsetY: 76
	}
});

// Options for the in-page items
var inPageOptions = {
	slideshowGroup: 'gallery',
	outlineType: null,
	allowSizeReduction: true,
	wrapperClassName: 'in-page',
	useBox: true,
	width: 655,
	height: 316,
	headingText: '&nbsp;', // empty headingText needed for the heading overlay with the zoom icon
	targetX: 'gallery-area 18px',
	targetY: 'gallery-area',
	autoplay: true
};

// Add the zoom icon to the heading overlay
hs.headingOverlay.position = 'top right';
hs.headingOverlay.offsetX = -155;
hs.Expander.prototype.onAfterGetHeading = function (sender) {
   if (sender.heading) {
      sender.heading.innerHTML = '<div class="full-expand-overlay" title="Expand to actual size"><a href="'+ sender.content.src +'" onclick="return hs.expand(this, largeImage)"></a></div>';
   }
};

// Options for large images
var largeImage = {
	allowSizeReduction: true,
	slideshowGroup: 'large',
	align: 'center',
	wrapperClassName: 'borderless'
};

// Close button for large images
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	fade: 2, 
	slideshowGroup: 'large'
});


// Open the first thumb on page load
hs.addEventListener(window, 'load', function() {
	document.getElementById('thumb1').onclick();
});

// Cancel the default action for image click and do next instead
hs.Expander.prototype.onImageClick = function() {
	if (/in-page/.test(this.wrapper.className))	return hs.next();
}

// Under no circumstances should the static popup be closed
hs.Expander.prototype.onBeforeClose = function() {
	if (/in-page/.test(this.wrapper.className))	return false;
}
// ... nor dragged
hs.Expander.prototype.onDrag = function() {
	if (/in-page/.test(this.wrapper.className))	return false;
}

// Keep the position after window resize
hs.addEventListener(window, 'resize', function() {
	var i, exp;
	hs.getPageSize();

	for (i = 0; i < hs.expanders.length; i++) {
		exp = hs.expanders[i];
		if (exp) {
			var x = exp.x,
				y = exp.y;

			// get new thumb positions
			exp.tpos = hs.getPosition(exp.el);
			x.calcThumb();
			y.calcThumb();

			// calculate new popup position
		 	x.pos = x.tpos - x.cb + x.tb;
			x.scroll = hs.page.scrollLeft;
			x.clientSize = hs.page.width;
			y.pos = y.tpos - y.cb + y.tb;
			y.scroll = hs.page.scrollTop;
			y.clientSize = hs.page.height;
			exp.justify(x, true);
			exp.justify(y, true);

			// set new left and top to wrapper and outline
			exp.moveTo(x.pos, y.pos);
		}
	}
});


// Start in-page focus mod - prevent in-page gallery to focus above other expanders
hs.Expander.prototype.onAfterExpand = function() {
    if (/in-page/.test(this.wrapper.className) && this.slideshow && this.slideshow.zIndex === undefined) {
        this.slideshow.zIndex = this.wrapper.style.zIndex;
    }
};
hs.Expander.prototype.onFocus = function() {
    if (/in-page/.test(this.wrapper.className)) {
        if (this.slideshow && this.slideshow.zIndex) {
            this.wrapper.style.zIndex = this.slideshow.zIndex;
        }
        if (this.outline) {
            this.outline.table.style.zIndex = this.slideshow.zIndex - 1;
        }
    }
};   
// End in-page focus mod

// Set different restorTitle for gallery and large image
hs.Expander.prototype.onInit = function() {
	if (this.slideshowGroup == 'in-page') {
		hs.lang.restoreTitle = "Click for next image";
		hs.transitionDuration = 1000;
	}
	else { 
		hs.lang.restoreTitle = ""; 
		hs.transitionDuration = 1000;
	}
};
