var imageswitchlists = {};

function init_imageswitcher(images, img_node, duration, start) {

	imageswitchlists[img_node] = {
		'images': images,
		'count': ((start + 1) % images.length),
		'duration': (duration * 1000)
	}
	if(isNaN(imageswitchlists[img_node]['duration'])) {
		imageswitchlists[img_node]['duration'] = 5000;
	}

	setTimeout("switch_image('" + img_node +"');", imageswitchlists[img_node]['duration']);
}
function switch_image(img_node) {
	var node = document.getElementById(img_node);
	node.src = imageswitchlists[img_node]['images'][imageswitchlists[img_node]['count']]['img'];
	node.parentNode.href= "#";
	node.parentNode.onclick = new Function("window.open('" + imageswitchlists[img_node]['images'][imageswitchlists[img_node]['count']]['href'] + "');");

	imageswitchlists[img_node]['count'] = (imageswitchlists[img_node]['count'] + 1) % imageswitchlists[img_node]['images'].length;
	setTimeout("switch_image('" + img_node +"');", imageswitchlists[img_node]['duration']);
}
function getItemByClassName(haystack, needle) {
	for(var i in haystack) {
		if(haystack[i].className == needle) {
			return haystack[i];
		}
	}
}
function printThis(node) {
	var images = node.getElementsByTagName('img');
	var image = getItemByClassName(images, 'printThisImage');
	var texts = node.getElementsByTagName('span');
	var text = getItemByClassName(texts, 'printThis');
	var newWindow = window.open('', 'Druckansicht', 'height=550, width=500, resize=yes, scrollbars=yes, menubar=yes');
	newWindow.document.write('<img src="' + image.src + '" style="float:left; margin-right: 12pt;margin-bottom: 12pt;" />');
	newWindow.document.write(text.innerHTML);
	newWindow.document.close();
	
	newWindow.print();

}
