﻿var advicetime;

var ac=0;

function advice() {
	$.getJSON("/radvice", function(article) {
		$.getJSON("/rarticlescategories", function(cate) {
			for(var a = 0; a<article.length; a++){
				for(var b = 0; b<cate.length; b++){
					if (article[a].fields.category == cate[b].pk)
					{
						article[a].fields.category = cate[b].fields.name;
						article[a].fields.categoryslug = cate[b].fields.slug;
					};
				};
			};
			
			advicerefresh();
			advicestart();
			
			function advicerefresh() {
				$("div.mcontent.advice div").remove();
				$("div.mcontent.advice").append("<div><img src='http://www.twojakosmetyczka.vbiz.pl/img/artykuly/" + article[ac].fields.image + "' /><a href='/artykul/" + article[ac].fields.categoryslug + "/" + article[ac].pk + "," + slugify(article[ac].fields.title) + ".html'><p><span>" + article[ac].fields.title + "</span><br />" + article[ac].fields.description + "</p>więcej >></a></div>");
				ac=ac+1;
				if(ac==article.length-1){
					ac=0;
				}
				$("div.mcontent.advice").append("<div><img src='http://www.twojakosmetyczka.vbiz.pl/img/artykuly/" + article[ac].fields.image + "' /><a href='/artykul/" + article[ac].fields.categoryslug + "/" + article[ac].pk + "," + slugify(article[ac].fields.title) + ".html'><p><span>" + article[ac].fields.title + "</span><br />" + article[ac].fields.description + "</p>więcej >></a></div>");
				ac=ac+1;
				if(ac==article.length-1){
					ac=0;
				}
				$("div.mcontent.advice").append("<div><img src='http://www.twojakosmetyczka.vbiz.pl/img/artykuly/" + article[ac].fields.image + "' /><a href='/artykul/" + article[ac].fields.categoryslug + "/" + article[ac].pk + "," + slugify(article[ac].fields.title) + ".html'><p><span>" + article[ac].fields.title + "</span><br />" + article[ac].fields.description + "</p>więcej >></a></div>");
				ac=ac+1;
				if(ac==article.length-1){
					ac=0;
				}
			};
			
			function advicestart(){
				advicetime = setInterval(function() { advicerefresh(); }, 10000);
			}
			
			function advicestop(){
				clearInterval(advicetime); 
			}
			
			$("div.mcontent.advice div a").hover(
				function () {
					advicestop();
				},function () {
					advicestart();
				}
			);
		});
	});
}






