var fancy = {
	thumbSize : '186x80',
	zoomSize : '558x240',
	idcounter:0,
	items : [],
	_getHtml : function (config){
		var title=config.title||'',
			group=config.group||null,
			img=config.img||null
		;
		var out = [];
		if(!img) return out;
		var h=window.location.href,
		l = h.lastIndexOf("/"),
		IMG= h.substr(0,l)+'/img.php?';
		config.ID = 'fancy_'+ (this.idcounter++);
		
		out.push('<a id="'+ config.ID +'"');
		if(group){
			out.push('rel="' + group + '"');
		}
		if(title){
			out.push('title="' + title + '"');
		}
		out.push('href="' + IMG + 'id=' + img +'&resize=' + this.zoomSize + '&t:far=C"');
		out.push('><img style="border:1px solid #DDD"');
		out.push('alt="' + ((group)?'':config.ID)  + '"');
		out.push('src="' + IMG + 'id=' + img +'&resize=' + this.thumbSize + '&t:far=C"></a>');
		return out;
	},
	insert:function (config){
		if(!config) return ;
		var out = this._getHtml(config);
		document.write(out.join(" "));
		config=$.extend({
			'titleShow'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none'
			},config);
		this.items.push(config);
	},
	gallery : function (ids,config){
		var self=this;
		var group= config.group = 'fancy_g_'+ (this.idcounter++);
		var out = [];
		$.each(ids,function (index,img){
			var copy_config = $.extend({img : img},config);
			out.push(self._getHtml().join(" "));
			self.insert(copy_config);
		});
		document.write(out.join("\n"));
		this.items.push(config);
	},
	show : function (){
		$.each(this.items,function (index,config){
			var a = (config.group)?$('a[rel='+config.group+']'):$('a#'+config.ID);
			a.fancybox(config);
		})	;
	}
}
$(document).ready(function() {
	fancy.show();
});