
jQuery(document).ready(function () {
	gwarticles.init();
});

gwarticles = {

	article: new Array(),
	articlecount: 0,
	position: 0,

	init: function () {
		jQuery('div.gwarticles div.slide').each(function(index) {
			gwarticles.article[index] = jQuery(this).html();
			gwarticles.articlecount++;
		});
		gwarticles.position = gwarticles.articlecount - 1;
		gwarticles.show(gwarticles.position);
	},

	show: function (index) {
		jQuery('div.gwarticles').html(gwarticles.article[index]);
		if (gwarticles.position == gwarticles.articlecount - 1) {
			nextarticle = 1;
		} else {
			nextarticle = gwarticles.position + 2;
		}
		if (gwarticles.position == 0) {
			prevarticle = gwarticles.articlecount;
		} else {
			prevarticle = gwarticles.position;
		}
		//jQuery('a.gwarticles-next').html('< #'+nextarticle);
		//jQuery('a.gwarticles-previous').html('#'+prevarticle+ ' >');
		jQuery('a.gwarticles-next').html('< Previous');
		jQuery('div.nav-position').html(''+(gwarticles.position+1)+" of "+(gwarticles.articlecount));
		jQuery('a.gwarticles-previous').html('Next >');
		if (gwarticles.position == 0) {
			jQuery('a.gwarticles-previous').addClass('loopjump');
		} else {
			jQuery('a.gwarticles-previous').removeClass('loopjump');
		}
		if (gwarticles.position == gwarticles.articlecount - 1) {
			jQuery('a.gwarticles-next').addClass('loopjump');
		} else {
			jQuery('a.gwarticles-next').removeClass('loopjump');
		}
	},
	
	next: function () {
		jQuery('div.gwarticles').fadeOut(500, function () {
			if (gwarticles.position < gwarticles.articlecount-1) {
				gwarticles.position++;
			} else {
				gwarticles.position = 0;
			}
			gwarticles.show(gwarticles.position);
			jQuery('div.gwarticles').fadeIn(500);
		});
	},

	previous: function () {
		jQuery('div.gwarticles').fadeOut(500, function () {
			if (gwarticles.position > 0) {
				gwarticles.position--;
			} else {
				gwarticles.position = gwarticles.articlecount - 1;
			}
			gwarticles.show(gwarticles.position);
			jQuery('div.gwarticles').fadeIn(500);
		});
	},

}
