dojo.require('dojo.cookie');

var highslide = function() {};

highslide.prototype.init = function(images) {
	//init params
	hs.graphicsDir = '/trunk/modules/photoservice/highslide/graphics/';
	hs.align = 'center';
	hs.showCredits = false;
	hs.transitions = ['expand', 'crossfade'];
	hs.fadeInOut = true;
	hs.outlineType = 'rounded-white';
	hs.wrapperClassName = 'white';
	hs.captionEval = 'this.a.title';
	hs.numberPosition = 'caption';
	hs.useBox = true;
	hs.width = 600;
	hs.height = 600;
	hs.dimmingOpacity = 0.5;
	
	//load translation
	dojo.xhrGet({
		url: 'highslide/highslide.lang.'+dojo.cookie('lang')+'.js',
		load: function() {
			hs.lang = highslidelang;
		},
		sync: true,
		handleAs: 'javascript'
	});
	
	//init slideshow
	hs.addSlideshow({
		interval: 3000,
		repeat: true,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			position: 'bottom center',
			opacity: .75,
			hideOnMouseOut: true
		},
		thumbstrip: {
			position: 'above',
			mode: 'horizontal',
			relativeTo: 'expander'
		}
	});
	
	//init onClode
	hs.Expander.prototype.onclose = hs.Expander.prototype.close;
	hs.Expander.prototype.close = function() {
		hs.getExpander().onclose();
		myMooFlowPage.mf.glideTo(this.getAnchorIndex());
	}
	
	//create images
	var div = document.createElement('div');
	dojo.addClass(div, 'highslide-gallery');
	dojo.addClass(div, 'hidden-container');
	
	dojo.forEach(images, function(image) {
		var a = document.createElement('a');
		dojo.addClass(a, 'highslide');
		dojo.attr(a,{
			'href': image.href,
			'id': 'highslide_'+image.name
		});
		a.onclick = function() {
			return hs.expand(this);
		}
		var img = document.createElement('img');
		dojo.attr(img,{
			'src': image.src,
			'alt': ''
		});
		a.appendChild(img);
		div.appendChild(a);
	});
	dojo.body().appendChild(div);
	return div;
}
