/**
 * Adds a teaser to the stack
 * 
 * @param	Number		id: the id of the content element
 * @param	Number		duration: the time of the duration in milliseconds
 * @param	Array		items: the data of all items, each item is also an array with [0] headline, [1] text, [2] image source, [3] link href
 * @return	Void		returns nothing
 */ 
function caseStudySolutionTeaserAddRotation (id, duration, items) {
	if (typeof(caseStudySolutionTeaserRotations) !== "object") {
		caseStudySolutionTeaserRotations = new Array();
	}
	caseStudySolutionTeaserRotations[caseStudySolutionTeaserRotations.length] = new Array(id, duration, items, 1);
}

/**
 * Initiates the rotation of the caseStudy teasers
 * 
 * @return	Void		returns nothing
 */ 
function caseStudySolutionTeaserInitRotations () {
	if (typeof(caseStudySolutionTeaserRotations) !== "object") {
		return;
	}
	var count = caseStudySolutionTeaserRotations.length;
	for (var i=0; i<count; i++) {
		var rotation = window.setInterval("caseStudySolutionTeaserRotation("+i+")", caseStudySolutionTeaserRotations[i][1]);
	}
}

/**
 * Initiates the rotation of the caseStudy teasers
 * 
 * @param	Number		no: the key of the rotation data in global data array caseStudySolutionTeaserRotations
 * @return	Void		returns nothing 
 */ 
function caseStudySolutionTeaserRotation (no) {
	var data = caseStudySolutionTeaserRotations[no];
	var id = data[0];
	var items = data[2];
	var count = data[3];
	
	var newHeadline = items[count][0];
	var newText = items[count][1];
	var newImgSrc = items[count][2];
	var newLinkHref = items[count][3];
	
	var headline = document.getElementById("caseStudy_"+id+"_solutionTeaser_headline");
	var text = document.getElementById("caseStudy_"+id+"_solutionTeaser_text");
	var image = document.getElementById("caseStudy_"+id+"_solutionTeaser_image");
	var link = document.getElementById("caseStudy_"+id+"_solutionTeaser_link");
	
	headline.innerHTML = newHeadline;
	text.innerHTML = newText;
	image.setAttribute("src", newImgSrc);
	link.setAttribute("href", newLinkHref);
	
	var itemCount = items.length;
	count++;
	if (count >= itemCount) {
		caseStudySolutionTeaserRotations[no][3] = 0;
	} else {
		caseStudySolutionTeaserRotations[no][3] = count;
	}
}

/**
 * Do onLoad
 *
 * @return	void
 */
oldOnload7845 = window.onload;
window.onload = function() {
	if (typeof(oldOnload7845) === "function") {
		oldOnload7845();
	}
	if (document.getElementById && document.createTextNode) {
		caseStudySolutionTeaserInitRotations();
	}
}
