var myCarousel;
var boxcounter = 0;
var boxheights = new Array();
var sparebox = new Array();
var arrayblock = new Array();

glow.ready(function() {
	//myCarousel = new glow.ui.CarouselPane('#twitterlist', {spotlight: 1, loop: true, duration: 1.2, page: 1});
	//setInterval("shiftCarousel()", 5000);
	glow(".mct_innerpagecontentwrap .mct_onecol").each(function(i, nodeList) { if(i > 3) { glow(this).removeClass('mct_onecol'); glow(this).addClass('boxrealigner'); sparebox.push(glow(this).clone()); glow(this).remove(); } });
	shiftBoxes();
});

function shiftCarousel() {
	myCarousel.next();
}

function shiftBoxes() {
	//alert(sparebox.length);
	for(x in sparebox) {
		arrayblock.length = 0;
		arrayblock = glow(".mct_innerpagecontentwrap .mct_onecol");
		glow(arrayblock[grabBiggestCol()]).append(glow(sparebox[x]));
	}
	/*arrayblock = glow(".mct_innerpagecontentwrap .mct_onecol");
	for(x in sparebox) {
		grabBiggestCol();
		alert(boxheights[0]+' '+boxheights[1]);
		for (i=0;i<boxheights.length;i++) {
			var i = 0;
			var compcount = 0;
			if(boxheights[i] < boxheights[compcount]) { compcount = i; }
		}
		alert(arrayblock[compcount].height());
		//glow(arrayblock[grabBiggestCol()]).append(glow(sparebox[x]));
	}*/
}

function grabBiggestCol() {
	boxheights.length = 0;
	glow(".mct_innerpagecontentwrap .mct_onecol").each(function(i, nodeList) { boxheights.push(glow(nodeList[i]).height()); });
	var i = 0;
	var compcount = 0;
	for (i=0;i<boxheights.length;i++) {
		if(boxheights[i] < boxheights[compcount]) { compcount = i; }
	}
	return(compcount);
	//alert(boxheights[0]+' '+boxheights[1]+' '+boxheights[2]+' '+boxheights[3]);
}


//alert(glow(nodeList[1]).height());
