/**
 * FSI Viewer function 
 */
var FsiViewer = Class.create();
Object.extend(FsiViewer.prototype, {

	/**
	 * options to initialize fsi viewer
	 */
	options: {
		baseUrl: '',
		hs: {}
	},
	
	/**
	 * Initialize
	 * 
	 * @params array options Options to initialize instance
	 */
	initialize : function(options){
	},
	
	/**
	 * Sets options for fsi viewer and highslide
	 * 
	 * @param Object options
	 */
	setOptions : function(options){
		this.options = Object.extend(this.options, options);
	}, 
	
	/**
	 * Registers openViewer function on click of objects
	 * 
	 * @param Array objs objects to observe
	 */
	observeClick: function(objs){
		var _this = this; 
		objs = objs.length != null ? objs : [objs];
		objs.each(function(elm){
			Event.observe(elm, 'click', function(evt){
				Event.stop(evt);
				var fsiPagesDir = elm.getAttribute('rel');
				_this.openViewer(elm, fsiPagesDir);
			});
		});
	},
	
	
	/**
	 * Opens the fsi viewer in an highslide
	 * 
	 * @param Object triggerObj the htmlElement that triggered this call
	 * @param string fsiPagesDir 
	 */
	openViewer: function(triggerObj, fsiPagesDir){
		var src =  this.options.baseUrl + fsiPagesDir;
		hs.close();
		var height = (typeof window.innerHeight == 'undefined') ? document.documentElement.clientHeight : window.innerHeight;
		var width = (typeof window.innerWidth == 'undefined') ? document.documentElement.clientWidth : window.innerWidth;
		height = height - 40;
		width = width - 40;
		if ((width * 0.6875) > height) {
			height = height - 40;
			width = height / 0.6875;
		}
		else {
			height = width * 0.6875;
		}
		var objectHeight = height - 5;
		var objectWidth = width;
		hs.htmlExpand(triggerObj, Object.extend(this.options.hs, {src: src, align: 'center', height: height, width: width, objectHeight: objectHeight, objectWidth: objectWidth}));
	}
	

});

fsiViewer = new FsiViewer();

