// Options for the in-page items
var inPageOptions = {
	//slideshowGroup: 'group1',
	outlineType: null,
	allowSizeReduction: false,
	wrapperClassName: 'in-page controls-in-heading',
	useBox: true,
	width: 600,
	height: 400,
	targetX: 'gallery-area 10px',
	targetY: 'gallery-area 10px',
	//captionEval: 'this.thumb.alt',
	numberPosition: 'caption'
}

//var gallery=function() { hs.expand(this, inPageOptions); };

document.observe('dom:loaded', function(){
	$$('.gallery').each(function(g){
		g.addClassName('hidden-container');

		var d=new Element('div',{id:'gallery-area',style:'border: 1px solid silver; margin-bottom:20px; width: 623px; height: 585px; '});

		if (g.nextSibling)
			g.parentNode.insertBefore(d, g.nextSibling);
		else
			g.parentNode.appendChild(d);
	});

	$$('.gallery a').each(function(a){
		a.addClassName('hslide');
		a.onclick=function(){
			hs.expand(this, inPageOptions);
		};
		//a.observe('click',function(e) { hs.expand(this, inPageOptions); });
		//a.observe('hslide:click',function(e) { e.stop(); hs.expand(this, inPageOptions); alert(this); });
	});

	/*$$('.gallery a img').each(function(i){
		i.setAttribute('height', '75');
		i.setStyle({height:'75px'});
	});*/
	//$$('.gallery a')[0].setAttribute('id', 'thumb1');






hs.graphicsDir = 'js/hslide/graphics/';
hs.transitions = ['expand', 'crossfade'];
hs.restoreCursor = null;
hs.lang.restoreTitle = 'Click for next image';
hs.showCredits = false;
hs.lang.number = "%1 / %2";
hs.outlineWhileAnimating=0;
hs.outlineStartOffset=0;

// Add the slideshow providing the controlbar and the thumbstrip
hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: true,
	useControls: true,
	overlayOptions: {
		position: 'bottom right',
		offsetY: 50
	},
	thumbstrip: {
		position: 'above',
		mode: 'horizontal',
		relativeTo: 'expander'
	}
});



// Open the first thumb on page load
hs.addEventListener(window, 'load', function() {
	//if ($('thumb1') && $('thumb1').onclick) $('thumb1').onclick();
	//console.log($$('.gallery').down('a').onclick);
	//document.getElementById('thumb1').onclick();
	$$('.gallery').each(function(g){
			//g.down('a').fire('hslide:click');
			g.down('a').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.page = 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);
		}
	}
});


}.bind(window));


var setclickableteaser=function(obj) {
	if (!obj) obj=document.body;
	Element.extend(obj);
	obj.select('.clickable').each(function(a) {
		var mehr = a.select('.mehr')[0];
		if (mehr) {
			a.setStyle({cursor: 'pointer'});
			a.observe('click', function(){window.location = mehr.href;});
			a.select('a,object').each(function(b){
				b.observe('click', function (e) {
					window.location = this.href;
					e.stop();
				}.bindAsEventListener(b));
			});
		}
	});
};


document.observe('dom:loaded', function(){setclickableteaser();});
