var maxL;

function moveleft() {
	var goto = jQuery('#friends .in').css('left');
	goto = parseInt(goto.substr(0,goto.lastIndexOf('px')),10);
	if(goto==maxL) return;
	
	if(goto>(maxL+30)) {
		goto = '-=30px';
	} else {
		goto = maxL+'px';
	}
	jQuery('#friends .in').animate({left: goto},100,function() { moveleft(); });
}

function moveright() {
	var goto = jQuery('#friends .in').css('left');
	goto = parseInt(goto.substr(0,goto.lastIndexOf('px')),10);
	if(goto==0) return;
	
	if(goto<-30) {
		goto = '+=30px';
	} else {
		goto = '0px';
	}
	jQuery('#friends .in').animate({left: goto},100,function() { moveright(); });
}

jQuery(function() {
	if(jQuery('#hometop').size() > 0) {
		jQuery('#hometop').prepend('<div id="slides" />');
		jQuery.ajax({
			url: 'http://www.holyfires.com/slides/',
			dataType: 'html',
			success: function(data) {
				jQuery('#slides').html(data).append('<span />').children('div').each(function(i) {
					jQuery('#slides span').append('<a href="#" class="'+(i==0 ? 'on':'')+'" />');
					if(i>0) jQuery(this).hide();
					if(jQuery(this).children('div').size()==0) jQuery(this).addClass('fullimage');
				});
				jQuery('#slides span a').each(function(i) {
					jQuery(this).click(function() {
						jQuery(this).addClass('on').siblings('.on').removeClass();
						jQuery('#slides .slide:eq('+i+')').show().siblings('.slide:visible').hide();
						return false;
					});
				});
			}
		});
	}
	
	maxL = (jQuery('#friends .in img').size() -5) * (-188);
	
	jQuery('#friends a.arr').bind('mouseover',function() {
		if(jQuery(this).hasClass('n')) {
			moveright();
		} else {
			moveleft();
		}
	}).bind('mouseout',function() {
		jQuery("#friends .in").stop();
	}).bind('click',function() { return false; });
});
