jQ = jQuery.noConflict();
jQ(document).ready(function(){
try{

var teaserCount = jQ(".productInfoLayer").length;
var teaserCurrent = 0;

var showTeaser = function(n, sbs){
	for(i=0; i<teaserCount; i++)
		if(i!=n){
			jQ(".productInfoLayer:eq("+i+")").hide();
		}else{
			jQ(".productInfoLayer:eq("+i+")").show();
		}
	jQ(".pagerBox div > span.active").removeClass("active");
	jQ(".pagerBox div > span:eq("+teaserCurrent+")").addClass("active");
	if(sbs===true){
		var path=jQ(".productInfoLayer:eq("+teaserCurrent+") img").attr("src");
		var link=jQ(".productInfoLayer:eq("+teaserCurrent+") a");
		if(link!=null){
			jQ("#backstretch").click(function(){window.location.href=link.attr("href");});
			jQ(".productInfoLayer:eq("+teaserCurrent+")").click(function(){window.location.href=link.attr("href");});
		}
		//path=path.substring(path.indexOf("files")-1, path.length);
		swapBackstretch(path);
	}
}

var pagerPrev = function(){
	teaserCurrent--;
	if(teaserCurrent<0)
		teaserCurrent=teaserCount-1;
	showTeaser(teaserCurrent, true);
	return false;
}

var pagerNext = function(){
	teaserCurrent++;
	if(teaserCurrent>teaserCount-1)
		teaserCurrent=0;
	showTeaser(teaserCurrent, true);
	return false;	
}

var initTeasers = function(){
	for(i=0; i<teaserCount; i++)
		jQ(".pagerBox > div").append("<span>&nbsp;</span>");
		
	jQ('#pagerPrev').click(function(){pagerPrev(); return false;});
	jQ('#pagerNext').click(function(){pagerNext(); return false;});	
		
	showTeaser(teaserCurrent, false);
	jQ.backstretch(jQ(".productInfoLayer:eq("+teaserCurrent+") img").attr("src"), {speed: 10});
	
	if(teaserCount==1){
		jQ("#pagerHomeTeaser").hide();
	}else
		window.setInterval(function(){pagerNext();}, 10000);		
}

initTeasers();

}catch(e){alert(e);}

});
