// John Resig - http://ejohn.org/ - MIT Licensed
(function() {
    var cache = {};
    this.tmpl = function tmpl(str, data) {
        var fn = !/\W/.test(str) ? 
            cache[str] = cache[str] || tmpl(document.getElementById(str).innerHTML) :
            new Function("obj",
                "var p=[],print=function(){p.push.apply(p,arguments);};" +
                "with(obj){p.push('" +
                str
                    .replace(/[\r\t\n]/g, " ")
                    .split("<#").join("\t")
                    .replace(/((^|#>)[^\t]*)'/g, "$1\r")
                    .replace(/\t=(.*?)#>/g, "',$1,'")
                    .split("\t").join("');")
                    .split("#>").join("p.push('")
                    .split("\r").join("\\'") +
                "');}return p.join('');");
        return data ? fn(data) : fn;
    };
})();

    function renderProducts() {
	var products = $("#homeProducts .product");
	products.find("div.bg").fixPNG(null, true);
	if (products.length <= homePageConf.NumberOfProducts) return;
	for (var i = 0; i < homePageConf.NumberOfProducts; i++) {
	    (function(j){ 
		var p = $(products[j]);
	    	p.fadeIn(timer.ProductLoad, function() {
		    setTimeout(function() { seti(p, timer.ProductRotate); }, timer.ProductStagger * j + 1);
	    	});
	    })(i);
	}
	function seti(el, t) {
	    setTimeout(function() { 
		//alert(el.find("h2").text());
		var pos = el.position();
		el.animate({ opacity: 0 }, 500, "linear", function() { $(this).css({ display: "none", opacity: 1 }); });
		var next = el.nextAll(".product:hidden:first");
		if (next.length != 1) next = el.prevAll(".product:hidden:last");
		next.fadeIn(timer.ProductLoad, function() { setTimeout(function() { seti(next, t); }, t); });
	    }, t);
	}
    }
