function initmaster(r) {
	var l=$('div#gallery');
	$('<div class="foot"></div>').css('opacity',0.35).appendTo(l);
	$('<a href="'+r+'" class="return">return to menu</a>').appendTo(l);
}
function initrelease(r,i) {
	var l=$('div#gallery');
	$('<div class="foot"></div>').css('opacity',0.35).appendTo(l);
	$('<a href="'+r+'" class="return">return to menu</a>').appendTo(l);
	$('<div class="footinfo">click on above lots to view details</div>').appendTo(l);
}
function gallery(r,i,p) {
	var obj=this;
	this.ie6=/MSIE 6/.test(navigator.userAgent);
	this.i=i;
	this.r=r;
	if(this.i.length>=1) {
		this.init(p);
	}
}
gallery.prototype={
init:function(prefix) {
	this.frames=[];
	this.frames[0]=$('<div/>');
	this.frames[1]=$('<div/>');
	var l=$('#gallery');
	$.each(this.frames,function(j) {
		this.addClass('frame');
		this.appendTo(l);
	});
	this.images=[];
	for(x=0,ct=this.i.length;x<ct;x++){
		this.images[x]=new Image();
		this.images[x].src='/'+prefix+'.nb?nb%5Bop%5D=image&nb%5Bsize%5D=2&nb%5Bid%5D='+this.i[x];
	}
	this.image=0;
	this.frame=1;
	this.frames[1].css('z-index',33);
	this.frames[0].css('z-index',32);
	this.frames[1].empty().append(this.images[0]);
	this.frames[1].show();
	this.frames[0].hide();
	this.foot=$('<div class="foot"></div>').appendTo(l);
	this.foot.css('opacity',0.35);
	this.ret=$('<a href="'+this.r+'" class="return">return to menu</a>').appendTo(l);
	var o=this;
	if (this.i.length>1) {
		this.prevbtn=$('<a href="#" class="prev disabled"></a>').bind('click',function() {
			return o.go(this,-1);
		}).appendTo(l);
		this.nextbtn=$('<a href="#" class="next"></a>').bind('click',function() {
			return o.go(this,1);
		}).appendTo(l);
	}
},
step:function(){
	var obj=this;
	this.next=this.frame;
	this.frame=1-this.frame;
	this.frames[this.frame].stop(true,true);
	this.frames[this.frame].css('z-index',33);
	this.frames[this.next].stop(true,true);
	this.frames[this.next].css('z-index',32);
	this.frames[this.frame].empty().append(this.images[this.image]);
	var next=this.frames[this.next];
	this.frames[this.frame].fadeIn(300,function() { next.hide(); });
},
go:function(e,d) {
	e.blur();
	var oi=this.image;
	this.image+=d;
	if(this.image < 0) this.image = 0;
	if(this.image >= this.i.length) this.image = this.i.length-1;

	this.prevbtn.toggleClass('disabled',this.image == 0);
	this.nextbtn.toggleClass('disabled',this.image == (this.i.length-1));

	if (this.image != oi) {
		this.step();
	}
	return false;
}
}
function anim(i) {
	this.timeout=false;
	this.initted=false;
	this.start(i);
}
anim.prototype={
step:function(){
	var obj=this;
	this.image++;
	if(this.image>=this.images.length){
		this.image=0;
	}
	this.next=this.frame;
	this.frame=1-this.frame;
	this.frames[this.frame].css('z-index',33);
	this.frames[this.next].css('z-index',32);
	this.frames[this.frame].empty().append(this.images[this.image]);
	this.frames[this.frame].fadeIn(2000,function() { obj.frames[obj.next].hide(); });
	this.timeout=setTimeout(function(){ obj.step(); },5000);
},
stop:function(){
	if(this.timeout) {
		clearTimeout(this.timeout);
		this.timeout=false;
		this.frames[this.next].hide();
		this.frames[this.frame].hide();
	}
},
start:function(i){
	var x,ct,obj=this;
	this.i=i;
	if (!this.initted) {
		this.initted=true;
		this.frames=[];
		this.frames[0]=$('<div/>');
		this.frames[1]=$('<div/>');
		var l=$('#flash');
		$.each(this.frames,function(j) {
			this.addClass('frame');
			this.appendTo(l);
		});
	}
	this.images=[];
	for(x=0,ct=i.length;x<ct;x++){
		this.images[x]=new Image();
		this.images[x].src='/homepage.nb?nb%5Bop%5D=image&nb%5Bsize%5D=2&nb%5Bid%5D='+i[x];
	}
	this.image=0;
	this.frame=1;
	this.next=0;
	this.frames[1].css('z-index',33);
	this.frames[0].css('z-index',32);
	this.frames[1].empty().append(this.images[0]);
	this.frames[1].show();
	this.frames[0].hide();
	if(this.images.length>1) {
		this.timeout=setTimeout(function(){ obj.step(); },3000);
	}
}
}

function paged() {
	$('.paged:not(.configured)').each(function(i) { new pagedele($(this)); });
}
function pagedele(ele) {
	var obj=this;
	ele.addClass('configured');
	var pagefull=315;
	$('div.pagesep',ele).each(function() {
		this.style.height=(pagefull-(this.offsetTop%pagefull))+'px';
	});
	this.pagefull=pagefull;
	this.ele=ele;
	this.max=this.ele.height();
	this.ele.height(315);
	if(this.max>315) {
		ele.height(pagefull);
		var o=this.max%this.pagefull;
		var test;
		if (o>0) test=$('<div style="height:'+(this.pagefull-o)+'px"></div>').appendTo(ele);
		this.max-=o;
		ele.css({
			'overflow':'hidden',
			'opacity':1
		});
		this.nav=$('div#nav');
		if(this.nav.get(0).innerHTML=='') {
			this.nav.css('text-align','center');
		}
		this.down=$('<a href="#" class="next"></a>');
		this.down.bind('click',function() {
			return obj.moveto(this,ele.scrollTop()+obj.pagefull);
		});
		this.up=$('<a href="#" class="prev disabled"></a>');
		this.up.bind('click',function() {
			return obj.moveto(this,ele.scrollTop()-obj.pagefull);
		});
		this.up.appendTo(this.nav);
		this.down.appendTo(this.nav);
		$('a.c',this.ele).each(function() {
			var loc=Math.floor(this.offsetTop/pagefull);
			if (loc>0) {
				loc*=pagefull;
				obj.ele.attr('scrollTop',loc);
				obj.up.toggleClass('disabled',false);
				obj.down.toggleClass('disabled',loc>=obj.max);
			}
		});
	}
}
pagedele.prototype={
moveto:function(e,loc) {
	e.blur();
	if ($(e).hasClass('disabled')) {
		this.ele.attr('scrollTop',loc);
	} else {
		this.ele.stop(true,true).attr('scrollTop',loc).css('opacity',0).animate({
			'opacity':1
		},200);
	}
	this.up.toggleClass('disabled',loc<=0);
	this.down.toggleClass('disabled',loc>=this.max);
	return false;
}
}
