var loading = '<div class="loading"><img src="'+bp+'images/loading.gif" width="32" height="32" alt="Loading" /></div>';
var nextClick = function (){
	var objid = $(this).attr('id');
	var nxt = (objid=='next')||$(this).hasClass('bg');
	if (nxt&&(++b>=bkgs.length)) b = 0;
	else if ((objid=='prev')&&(--b<0)) b = bkgs.length - 1;
	if ($('#loading').length==0) $(this).parent().append('<div id="loading" style="float:left;"><img src="'+bp+'images/loading.gif" height="16" width="16" /></div>');
	else $('#loading').stop().fadeIn();
	h = $('#content').height();
	$('.bg:first').fadeOut(800, function(){
		var img = new Image();
		$('#content').height(h);
		$(img).load(function () {
			$('#content').append('<div class="bg" style="background-image:url('+bkgs[b][0]+');height:'+bkgs[b][1]+'px;" />')
			$('#content').height('auto');
			$('.bg:last').hide().fadeIn();
			$('#dida').html(bkgs[b][2]);
			if ($('#galnum').length) $('#galnum').html(b+1);
			$('#loading').fadeOut();
			img = null;
		}).attr('src', bkgs[b][0]);
		$(this).remove();
	});
}
function init(){
	$('.ext').live('click', function(){window.open($(this).attr('href'));return false;});
	var h = $('#content').height();
	$('.bg').hide();
	$('#content').height(h);
	$('.bg').fadeIn(800);
	$('#next, #prev').live('click', nextClick);
	if (bkgs.length>1) $('.bg').live('click', nextClick);
	else $('.bg').css({cursor:'default'});
}
$(function(){init();});
