function ypjeffect_fadeshow(container) {
	container = jQuery(container);

	var fadeDuration = 1000;
	if (container.attr("data-fadeDuration")!=undefined) fadeDuration = container.attr("data-fadeDuration");
	var intervalDuration = 2500;
	if (container.attr("data-intervalDuration")!=undefined) intervalDuration = container.attr("data-intervalDuration");

	var images = container.children(':not(br)');
	if (images.length<2) return;

	images.css({"position": "absolute", "z-index": "1", "display": "block", "left": "0", "top": "0"}).hide();

	var index = 1;	
	var prev = null;
	var elem = jQuery(images.get(0));
	var next = jQuery(images.get(1));
	elem.show();

	setInterval(
		function() {
			if (prev) prev.hide().css("z-index", "1");
			elem.css("z-index", "2");
			next.css("z-index", "3").fadeIn(fadeDuration);
			prev = elem;			
			elem = next;	
			if ((++index)>=images.length) index = 0;
			next = jQuery(images.get(index));
		},
		intervalDuration+fadeDuration
	)
}


function ypjeffect_scroll(container, amount, beltSpeed) {
	if (!container) container = jQuery(this);
	container.animate({'margin-left': '-'+amount+'px'}, 1000*(amount/beltSpeed), 'linear').animate({'margin-left': '0px'}, 0, 'linear', "ypjeffect_scroll(null,"+amount+","+beltSpeed+")");
}


function ypjeffect_belt(container) {

	container = jQuery(container);
	container.css({"overflow": "hidden", "position": "relative"});

	container.wrapInner('<div style="width: 100%; height: 100%;" />');	
	container = container.children();
	container.css({"position": "relative"});

	var width = container.width();
	var images = container.children();
	var total = 0;
	images.each(function() { 
		var img = jQuery(this); 
		img.css({"position": "absolute", "left": total+"px", "top": "0", "display": "block"});	
		total += img.outerWidth();  
	});
	images.each(function() { 
		var img = jQuery(this).clone();
		container.append(img);
		img.css({"left": total+"px"});	
		total += img.outerWidth();  
	});

	var beltSpeed = 50;
	if (container.attr("data-beltSpeed")!=undefined) beltSpeed = container.attr("data-beltSpeed");
	setInterval(function () { ypjeffect_scroll( container, total/2, beltSpeed); }, 100 );
}


jQuery(function () {
	jQuery(".ypjeffect_fadeshow").each(function () { ypjeffect_fadeshow(this); });
	jQuery(".ypjeffect_belt").each(function () { ypjeffect_belt(this); });
});
