
function Viewer() {
	v = 0;
	timeout = 1500 + Math.floor(1500 * Math.random());
	$views = $("div.mElViewer");
	count = $views.length;
	view = new Array();
	}

Viewer.prototype.startup = function() {
	for(i=0;i<count;i++){
		view[i] = new Object();
		view[i].count = set[i].length;
		view[i].current = 0;
		d = i+1;
		view[i].id = "v"+d;
	}
		$("img","div.mElViewer").load(function(){
/*			$images = $(this).find("img");
			$($images).each(function(){*/
				w = $(this).width();
				h = $(this).height();
				if(h<313 && w<262){
					$(this).css("top",function(i){return h==0 ? h : 156 - h/2});
					$(this).css("left",function(i){return w==0 ? w : 131 - w/2});
				}
/*			});*/
		});

	Viewer.prototype.cycler();
}

Viewer.prototype.cycler = function() {
	v = 0;
	m = setTimeout(function() {
		Viewer.prototype.changePicture();
	},timeout);
}

Viewer.prototype.changePicture = function() {
	view[v].current++;
	cnt = view[v].count;
	$act = $("div.mElViewer#"+view[v].id+" img.active");
	var $next = $act.next().length ? $act.next() : $("div.mElViewer#"+view[v].id+" img:first");
	var cur = (view[v].current > cnt-1) ? cur = view[v].current = 0 : cur = view[v].current;
	src = set[v][cur];
	$act.addClass("last-active");
	$next.css({opacity:0.0}).addClass("active").animate({opacity: 1.0},900,function() {
		$act.removeClass("active last-active")
	});
	v++;
	if(v > count-1) {
		clearTimeout(t);
		Viewer.prototype.cycler();
	} else 
		t = setTimeout(function() {
			Viewer.prototype.changePicture();
		},1000);
}
