glow.ready(function() {

	//check if any glow carousels require initialisation
	checkForCarousels();

});		




// checks if any glow carousels require initialisation
// extracts carousel config params from class starting g-cc
// ie class="g-cc-4-4-1-1" relates to size=4,step=4,loop=true,showPageNav=true
function checkForCarousels(){
	//find all ul with .glow-carousel		
	glow.dom.get('ul.g-mp-carousel , ul.g-cc-carousel , ol.g-cc-carousel').each(function(i) {		
		//now get all class names
		var classesList=glow.dom.get(this).attr('class').split(" ");
		for(var i=0; i<classesList.length;i++){
			var classParts=classesList[i].split("-");			
			//check that the first 2 parts match
			if(classParts[0]=="g" && classParts[1]=="cc" && classParts[2]!="carousel" ){
				//now get ID and apply carousel based on ID
				var id=glow.dom.get(this).attr('id');
				makeCarousel('#' +id,classParts[2],classParts[3],classParts[4],classParts[5]);    			
			}
		}
  	});
}

function makeCarousel(selector,size,step,loop,showPageNav){
	if(selector=="") return;
	var carousel=glow.dom.get(selector);
	if(!carousel) return;
	loop == loop=="1" || loop=="true" ? true : false;
	showPageNav == showPageNav=="1" || showPageNav=="true" ? true : false;
	
	var carousel = new glow.widgets.Carousel(selector,{
		slideOnScroll: true,
		animDuration: .25,
		animTween: glow.tweens.easeIn(),
		size: size,
		step: step,
		loop: loop,
        	pageNav: showPageNav
		
	});		
	
	;
	
	return carousel;
}