function scrollProductsInit( elmObal, elmItem, max, prevElm, nextElm, mode )
{
	$(elmObal).each( function(i)
	{
		scrollProducts($(this).children(elmItem), max, prevElm, nextElm, mode);
	});
}

function scrollProducts( elm, max, prevElm, nextElm, mode ){
	function processNext(elm)
	{
		if($(elm).filter(".show:last").next(".foto").length>0)
		{
			$(elm).filter(".show:first").animate({opacity:'hide',width:'toggle'},'slow');//css("display","none");
			$(elm).filter(".show:first").addClass("hide");
			$(elm).filter(".show:first").removeClass("show");
			$(elm).filter(".show:last").next().animate({opacity:'show',width:'toggle'},'slow');//.css("display","block");
			$(elm).filter(".show:last").next().addClass("show");
			$(elm).filter(".show:last").next().removeClass("hide");
		}
	}
	function processPrev(elm)
	{
		if($(elm).filter(".show:first").prev().length>0)
		{
			$(elm).filter(".show:last").animate({opacity:'hide',width:'toggle'},'slow');//.css("display","none");
			$(elm).filter(".show:last").addClass("hide");
			$(elm).filter(".show:last").removeClass("show");
			$(elm).filter(".show:first").prev().animate({opacity:'show',width:'toggle'},'slow');//.css("display","block");
			$(elm).filter(".show:first").prev().addClass("show");
			$(elm).filter(".show:first").prev().removeClass("hide");
		}
	}

	intervalX = false;
	intervalY = false;
	if($(elm).length>max)
	{
		//alert($(elm).length);
		$(elm).each( function(i)
		{
			//alert($(elm).index(this));
			if($(elm).index(this)>=max)
			{
				//alert('index: '+$(".c_item.borcolorpur .c_galerie .foto").index(this));
				$(this).css("display","none");
				$(this).addClass("hide");
			}else
			{
				$(this).addClass("show");
			}
		});

		$(elm).nextAll(nextElm).css("display","block");
		$(elm).nextAll(prevElm).css("display","block");

		//if(mode=='over')
		//{
			$(elm).nextAll(nextElm).mouseover( function(e)
			{
				if (intervalX) {
					clearInterval(intervalX);
					intervalX = false;
				}
				intervalY = setInterval(processNext, 1200, elm);
				processNext(elm);
			});
			$(elm).nextAll(nextElm).mouseout( function(e)
			{
				if (intervalX) {
					clearInterval(intervalX);
					intervalX = false;
				}
				if (intervalY) {
					clearInterval(intervalY);
					intervalY = false;
				}
			});
			$(elm).nextAll(prevElm).mouseover( function(e)
			{
				if (intervalY) {
					clearInterval(intervalY);
					intervalY = false;
				}
				intervalX = setInterval(processPrev, 1200, elm);
				processPrev(elm);
			});
			$(elm).nextAll(prevElm).mouseout( function(e)
			{
				if (intervalY) {
					clearInterval(intervalY);
					intervalY = false;
				}
				if (intervalX) {
					clearInterval(intervalX);
					intervalX = false;
				}
			});
		//}else if( mode=='click' )
		//{
			$(elm).nextAll(nextElm).click( function(e){	processNext(elm);	});
			$(elm).nextAll(prevElm).click( function(e){	processPrev(elm);	});
		//}
	}else
	{
		$(elm).nextAll(nextElm).css("display","none");
		$(elm).nextAll(prevElm).css("display","none");
	}
}//function scrollProducts


/* ****  **** */


function imageSlider( galleryElm, galleryControll, controlElm, timeOut )
{
	var intervalNextImage = false;
	if( $(galleryElm+":has(a)").children("a").length < 2 ) return false;
	$(galleryElm+":has(a)").children("a:first").addClass("first visible");
	$(galleryControll+":has("+controlElm+")").children(controlElm+":first").addClass("viewed");
	$(galleryControll+":has("+controlElm+")").children(controlElm).each( function(e)
	{
		$(this).click( function(i)
		{
			clearInterval(intervalNextImage);
			intervalNextImage = false;
			var index = $(galleryControll+":has("+controlElm+")").children(controlElm).index(this);
			imageShow( index );
			$(galleryControll+":has("+controlElm+")").children(controlElm).removeClass("viewed");
			$(this).addClass("viewed");
		});
	});
	$(galleryElm+":has(a)").children("a").each( function(e)
	{
		if($(this).hasClass("first")){
			$(this).removeClass("first");

		}
		else{
			$(this).addClass("hidden");
			$(this).fadeOut('toggle');
		}
	});
	function imageShow( index )
	{
		elm = $(galleryElm+":has(a)").children("a").get( index );
		if($(elm).hasClass("visible")){}
		else
		{
			$(galleryElm+":has(a)").children("a.visible").hide();
			$(galleryElm+":has(a)").children("a.visible").addClass('hidden');
			$(galleryElm+":has(a)").children("a.visible").removeClass('visible');
			$(elm).addClass('visible');
			$(elm).removeClass('hidden');
			$(elm).fadeIn('slow');
		}
		return false;
	}
	function imageFadeIn( elm )
	{
		$(elm).css('display','none');
		$(elm).next("a").removeClass("hidden");
		$(elm).next("a").addClass("visible");
		$(elm).next("a").fadeIn("slow");
	}
	function imageNextShow( )
	{
		elm = $(galleryElm+":has(a)").children("a.visible");
		if($(elm).nextAll("a").length>0)
		{
			$(elm).removeClass("visible");
			$(elm).addClass("hidden");
			$(elm).fadeOut('slow', imageFadeIn( elm ));
		}else
		{
			$(elm).removeClass("visible").addClass("hidden");
			$(elm).hide();
			$(galleryElm+":has(a)").children("a:first").addClass("visible").removeClass("hidden");
			$(galleryElm+":has(a)").children("a:first").fadeIn("slow");
		}
		elm2 = $(galleryControll+":has("+controlElm+")").children(controlElm+".viewed");
		//alert(elm);
		if($(elm2).nextAll(controlElm).length>0)
		{
			$(elm2).removeClass("viewed");
			$(elm2).next(controlElm).addClass("viewed");
		}else
		{
			$(elm2).removeClass("viewed").addClass("hidden");
			$(galleryControll+":has("+controlElm+")").children(controlElm+":first").addClass("viewed");
		}
	}
	intervalNextImage = setInterval(imageNextShow, timeOut);
}//function imageSlider

function multipleSlider( elmWhere, elmWhat, iInterval, sSpeed )
{
	if( $(elmWhere+":has("+elmWhat+")").children(elmWhat).length < 2 ) return false;
	$(elmWhere+":has("+elmWhat+")").children(elmWhat+":first").addClass("first visible");
	$(elmWhere+":has("+elmWhat+")").children(elmWhat).each( function(e)
	{
		if($(this).hasClass("first")){
			$(this).removeClass("first");

		}
		else{
			$(this).addClass("hidden");
			$(this).fadeOut('toggle');
		}
	});
	function imageFadeIn( elm )
	{
		$(elm).css('display','none');
		$(elm).next(elm).removeClass("hidden");
		$(elm).next(elm).addClass("visible");
		$(elm).next(elm).fadeIn(sSpeed);
	}
	function imageNextShow( elmWhere2, elmWhat2 )
	{
		elm = $(elmWhere2+":has("+elmWhat2+")").children(elmWhat2+".visible");
		if($(elm).nextAll(elmWhat2).length>0)
		{
			$(elm).removeClass("visible");
			$(elm).addClass("hidden");
			$(elm).fadeOut(sSpeed, imageFadeIn( elm ));
		}else
		{
			$(elm).removeClass("visible").addClass("hidden");
			$(elm).hide();
			$(elmWhere2+":has("+elmWhat2+")").children(elmWhat2+":first").addClass("visible").removeClass("hidden");
			$(elmWhere2+":has("+elmWhat2+")").children(elmWhat2+":first").fadeIn(sSpeed);
		}
		intervalNextImage = setTimeout(imageNextShow, iInterval, elmWhere2, elmWhat2);
	}
	intervalNextImage = setTimeout(imageNextShow, iInterval, elmWhere, elmWhat);
}//multipleSlider


