///**
// * HOMEPAGE SCROLLING BANNER SCRIPTS
// */
//$(function(){
//	scrollSetup();
//});
//
//function scrollSetup(){
//	$('#scrollyWrapper div:first').css({marginLeft:"0px"}).animate({
//		marginLeft:"-450px"
//	},1000,function(){
//		alert('done');
//	});
//}
var firstrun = true;
// On DOM Ready
$(function(){
	// Run the logo animator
	animateLogos('#scrollyWrapper','-960');
});

/**
Animates the logos at the top of the page using jQuery
*/
function animateLogos(parent,distance){

	// Find the first and last child descenders of the parent
	var firstitem 	= $(parent).find('>:first');
	var lastitem 	= $(parent).find('>:last');
	// We need to know which of the extra windows we are fading in
	var commentId = firstitem.attr('data-id');
	// If this isn't the first run
	if(!firstrun){
		// Fade out and in the correct div depending on the commentId we fetched a ms ago
		if(commentId == "scroll_1"){
			// Fade out 4
			$("#scroll_4").fadeOut('slow',function(){
				// Fade in 1
				$('#'+commentId).fadeIn('slow');
			});
		}else if(commentId == "scroll_2"){
			// Fade out 1
			$("#scroll_1").fadeOut('slow',function(){
				// Fade in 2
				$('#'+commentId).fadeIn('slow');
			});
		}else if(commentId == "scroll_3"){
			// Fade out 2
			$("#scroll_2").fadeOut('slow',function(){
				// Fade in 3
				$('#'+commentId).fadeIn('slow');
			});
		}else if(commentId == "scroll_4"){
			// Fade out 3
			$("#scroll_3").fadeOut('slow',function(){
				// Fade in 4
				$('#'+commentId).fadeIn('slow');
			});
		}
	}
	
	// Scroll first item out of view after a delay
	firstitem.css({'marginLeft':"0px"})				// Set margin to 0
				.animate({
					"marginLeft": distance+'px'
				},	// Animate Margin to desired distance
				30000,
				'linear',
				function(){					// callback and loop
					// Reset margin, and detach the item
					firstitem.css({'marginLeft':""}).detach();
					// Insert it after the last item in the list
					firstitem.insertAfter(lastitem);
					// Call Self to loop
					animateLogos(parent,distance);
				});
	
	firstrun = false;
}

