// redistribute divs from div#boxIdCardTeasersCol1 to div#boxIdCardTeasersCol(1|2|3)
function renderIdCardTeasers() {
	var boxTeasers = document.getElementById('boxIdCardTeasers');
	var boxCols = new Array();
	var nodeNew;
	var nodeClone;
	var i;

	boxCols[0] = document.getElementById('boxIdCardTeasersCol1');
	boxCols[1] = document.getElementById('boxIdCardTeasersCol2');
	boxCols[2] = document.getElementById('boxIdCardTeasersCol3');

	// check structure
	if (!(boxTeasers && boxCols[0] && boxCols[1] && boxCols[2])) {
		console.log('ERROR: missing column(s).');
		return;
	}
	// get content
	var boxFunctions = YAHOO.util.Dom.getElementsByClassName('idcardfunction', 'div', boxCols[0]);

	for (i=0; i<boxFunctions.length; i++) {
		nodeNew = document.createElement('div');
		nodeNew.className = 'boxIdCardFunctionDots';
		boxFunctions[i].insertBefore(nodeNew, boxFunctions[i].firstChild);
		boxFunctions[i].className = 'boxIdCardTeaser boxIdCardFunction';
	}
	var boxIdCards = YAHOO.util.Dom.getElementsByClassName('boxIdCardTeaser', 'div', boxCols[0]);

	// move boxIdCards[i] to second column
	nodeNew = document.createElement('div');
	nodeNew.className = 'boxIdCardSpacer';
	boxCols[1].appendChild(nodeNew);

	for (i=Math.floor((boxIdCards.length+4)/3); i<2*Math.floor((boxIdCards.length+4)/3)-1; i++) {
		nodeClone = boxIdCards[i].cloneNode(true);
		boxCols[0].removeChild(boxIdCards[i]);
		boxCols[1].appendChild(nodeClone);
	}
	// move boxIdCards[i] to third column
	nodeNew = document.createElement('div');
	nodeNew.className = 'boxIdCardSpacer';
	boxCols[2].appendChild(nodeNew);

	for ( ; i<boxIdCards.length; i++) {
		nodeClone = boxIdCards[i].cloneNode(true);
		boxCols[0].removeChild(boxIdCards[i]);
		boxCols[2].appendChild(nodeClone);
	}
	// move div.navigate to div#boxIdCardTeasers
	var boxPagers = YAHOO.util.Dom.getElementsByClassName('navigate', 'div', boxCols[0]);

	if (boxPagers && boxPagers.length) {
		var boxPager = boxPagers[0];
		var boxPagerClone = boxPager.cloneNode(true);
		boxCols[0].removeChild(boxPager);
		document.getElementById('boxIdCardTeasers').appendChild(boxPagerClone);
	}
}

YAHOO.util.Event.onDOMReady(renderIdCardTeasers);
