// COMMENT

jQuery(function() {	
	showComment();
});

var time_fade = 500;
var time_show = 7500;
var t = 0, thumbVisible, timer;
var skipNext = false;

function hideComment() {
	clearTimeout(timer);
	jQuery('#lastGB .gbcomment, #lastGB .gbthumb').fadeOut(time_fade, showComment);
}

function showComment(){
	if(skipNext == false) {
		if(t==c_comments.length) t = 0;
		
		jQuery('#lastGB .gbcomment').html('<div class="commentBox">'+c_dates[t]+': "'+c_comments[t]+'"</div><a href="'+ c_domain[t] +'">'+ c_church_name[t] +'</a>');
	
		var imageUrl = "http://tpl.asite.no/sites/no.kirkenorge/screen/gfx/blank.gif"; 
	
		if(c_thumbnails[t] != '') {
			thumbVisible = 1; 
		} else { 
			thumbVisible = 0;
			c_thumbnails[t] = 'http://tpl.asite.no/sites/no.kirkenorge/screen/gfx/emptyChurch.gif';
		}
			
		jQuery('#lastGB .gbthumb')
			.css('opacity', parseInt(thumbVisible))
			.html('<img src="'+imageUrl+'" style="background-image: url('+c_thumbnails[t]+'); background-position: center center;" width="48" height="48" />');
			
		jQuery('#lastGB .gbcomment, #lastGB .gbthumb').fadeIn(time_fade);
		timer = setTimeout('hideComment()', time_show); 
		
		t++;
	} else {
		skipNext = false;
		timer = setTimeout('hideComment()', time_show); 		
	}
}

function showComment_demand(){
	if(t==c_comments.length) t = 0;
	
	jQuery('#lastGB .gbcomment').html('<div class="commentBox">'+c_dates[t]+': "'+c_comments[t]+'"</div><a href="'+ c_domain[t] +'">'+ c_church_name[t] +'</a>');

	var imageUrl = "http://tpl.asite.no/sites/no.kirkenorge/screen/gfx/blank.gif"; 

	if(c_thumbnails[t] != '') {
		thumbVisible = 1; 
	} else { 
		thumbVisible = 0;
		c_thumbnails[t] = 'http://tpl.asite.no/sites/no.kirkenorge/screen/gfx/emptyChurch.gif';
	}
		
	jQuery('#lastGB .gbthumb')
		.css('opacity', parseInt(thumbVisible))
		.html('<img src="'+imageUrl+'" style="background-image: url('+c_thumbnails[t]+'); background-position: center center;" width="48" height="48" />');
		
	jQuery('#lastGB .gbcomment, #lastGB .gbthumb').fadeIn(time_fade);
	
	skipNext = true;
	t++;
}

function previousComment() {
	t = t - 2;

	if(t < 0) {
		t = c_comments.length -1;
	}

	showComment_demand();
}

function nextComment() {
	showComment_demand();
}