var imgRotCntr = 0;
var imgRotItems = new Array();
var irotate = null;
var interval = 5000;
var thumbprefix = "img-";
var contThumb = '';
var fadeTime = 1500;

function Rotate(container, imgprefix, thumbprefix, speed) {
	interval = speed;
	jQuery("a", "." + container).each(function () {
		imgRotItems.push(imgprefix + (imgRotItems.length + 1));
		jQuery("." + thumbprefix + imgRotItems.length).mouseover(function () {
			clearTimeout(irotate);
			imgRotCntr = parseInt(this.className.replace(thumbprefix, ""));
			ResetRotation();
			jQuery("#" + imgRotItems[imgRotCntr - 1]).show();
		});
		jQuery("." + thumbprefix + imgRotItems.length).mouseout(function () {
			clearTimeout(irotate);
			irotate = setTimeout("StartRotate()", interval);
		});
	});
	StartRotate();
}

function RotateNew(containerThumb, containerImg, imgprefix, speed) {
	interval = speed;
	contThumb = containerThumb;

	jQuery("." + containerImg + " > div").each(function () {
		imgRotItems.push(imgprefix + (imgRotItems.length + 1));

		jQuery("." + containerThumb).append("<li class='" + thumbprefix + imgRotItems.length + "'><a href='javascript:void(0);'>" + imgRotItems.length + "</a></li>");

		jQuery("." + thumbprefix + imgRotItems.length).click(function () {
			clearTimeout(irotate);
			imgRotCntr = parseInt(this.className.replace(thumbprefix, ""));
			ResetRotation();
			jQuery("#" + imgRotItems[imgRotCntr - 1]).fadeIn(fadeTime);
			jQuery("." + thumbprefix + imgRotCntr.toString() + " > a").addClass('current');
		});
	});

	jQuery(imgRotItems).each(function () {
		jQuery("#" + this).mouseover(function () {
			clearTimeout(irotate);
			imgRotCntr = parseInt(this.id.replace(imgprefix, ""));
			ResetRotation();

			jQuery("#" + imgRotItems[imgRotCntr - 1]).show();
			jQuery("." + thumbprefix + (imgRotCntr).toString() + " > a").addClass('current');
		});
		jQuery("#" + this).mouseout(function () {
			clearTimeout(irotate);
			irotate = setTimeout("StartRotate()", interval);
		});
	});

	ResetRotation();
	StartRotate();
}

function StartRotate() {
	clearTimeout(irotate);
	if (imgRotCntr >= imgRotItems.length)
		imgRotCntr = 0;

	jQuery("." + thumbprefix + (imgRotCntr == 0 ? imgRotItems.length : imgRotCntr).toString() + " > a").removeClass('current');
	jQuery("#" + imgRotItems[(imgRotCntr == 0 ? imgRotItems.length - 1 : imgRotCntr - 1)]).fadeOut(fadeTime);

	if (isIE8) { // for IE8 each child element must be faded in and out
		jQuery("#" + imgRotItems[(imgRotCntr == 0 ? imgRotItems.length - 1 : imgRotCntr - 1)] + " > *").each(function () {
			jQuery(this).fadeOut(fadeTime);
		});

		jQuery("#" + imgRotItems[imgRotCntr] + " > *").each(function () {
			jQuery(this).fadeIn(fadeTime);
		});
	}

	jQuery("." + thumbprefix + (imgRotCntr + 1).toString() + " > a").addClass('current');
	jQuery("#" + imgRotItems[imgRotCntr]).fadeIn(fadeTime);

	imgRotCntr++;
	irotate = setTimeout("StartRotate()", interval);
}

function ResetRotation() {
	jQuery(imgRotItems).each(function () {
		jQuery("#" + this).stop(true, true).hide();
	});

	if (contThumb != '') {
		jQuery("." + contThumb + " li a").each(function () {
			jQuery(this).removeClass('current');
		});
	}

	if (isIE8) {
		jQuery(imgRotItems).each(function () {
			jQuery("#" + this + " > *").stop(true, true).show();
		});
	}
}

