if(!window['juncture']) {
	window['juncture'] = {};
	var juncture = window['juncture'];
}

(function(){
	g = google;
	
	$(document).ready(function() {
		juncture.heroshots();
	});
	
	juncture.heroshots = function() {
		var heroshot = $('.heroshot-animated');

		var fade = parseInt( heroshot.attr('data-transition'), 10 ) * 1000;
		var dur = parseInt( heroshot.attr('data-show'), 10) * 1000;

		var images = heroshot.find('img');
		images.eq(0).show().attr('data-current', 'yes');
		

		if( images.size() < 2 ) { return; }

		juncture.heroshots.go = function() {
			juncture.heroshots.interval = setInterval(function(){
				var currentImage = images.filter('[data-current=yes]');
				var toImage = currentImage.parent('a').size() ? ( currentImage.parent('a').next('a').size() ? currentImage.parent('a').next('a').find('img') : images.eq(0) ) : ( currentImage.next('img').size() ? currentImage.next('img') : images.eq(0) );
				currentImage.fadeOut(fade).removeAttr('data-current');
				toImage.fadeIn(fade).attr('data-current', 'yes');
			}, fade + dur);
		}
		juncture.heroshots.go();
	}
})();
