/**
 * @author brunogermano
 * http://egermano.com
 */

imgr = new Array();

imgr[0] = "http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/no-image.gif";
imgr[1] = "http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/no-image.gif";
imgr[2] = "http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/no-image.gif";
imgr[3] = "http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/no-image.gif";
imgr[4] = "http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/no-image.gif";

showRandomImg = true;
tablewidth = '100%';
cellspacing = 0;
borderColor = "";
bgTD = "";


imgwidth = 150;
imgheight = 100;
fntsize = 16;
acolor ="#000" ;
aBold = true;
icon = " ";

text = "no";

showPostDate = false;

summaryPost = 100;
summaryFontsize = 10;
summaryColor = "#000";
icon2 = " ";

numposts = 999;
label = "";

var arr_crimes = [];


function removeHtmlTag(strx,chop){
	var s = strx.split("<");
	for(var i=0;i<s.length;i++){
		if(s[i].indexOf(">")!=-1){
			s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);
		}
	}
	s =  s.join(" ");
	s = s.substring(0,chop-1);
	return s;
}

function showrecentposts(json) {
	j = (showRandomImg) ? Math.floor((imgr.length+1)*Math.random()) : 0;
	img  = new Array();

  	for (var i = 0; i < json.feed.entry.length; i++) {
    	var entry = json.feed.entry[i];
    	var posttitle = entry.title.$t;
		var pcm;
    	var posturl;
		
		if ("category" in entry) {
			var encontrou = false;
      		for(var cat = 0; cat<entry.category.length; cat++)
				if(entry.category[cat].term.indexOf('destaque') != -1 || entry.category[cat].term.indexOf('Destaque') != -1 )
					encontrou = true;
			
			if(!encontrou)
				continue;
		}else{
			continue;
		}
		
    	if (i == json.feed.entry.length) break;
    	for (var k = 0; k < entry.link.length; k++) {
      		if (entry.link[k].rel == 'alternate') {
        		posturl = entry.link[k].href;
        		break;
      		}
    	}
		
		for (var k = 0; k < entry.link.length; k++) {
      		if (entry.link[k].rel == 'replies' && entry.link[k].type == 'text/html') {
        		pcm = entry.link[k].title.split(" ")[0];
        		break;
      		}
    	}
		
    	if ("content" in entry) {
      		var postcontent = entry.content.$t;}
    	else
    	if ("summary" in entry) {
      		var postcontent = entry.summary.$t;}
    	else var postcontent = "";
    	
    	postdate = entry.published.$t;
		
		if(j>imgr.length-1) j=0;
		img[i] = imgr[j];
	
		s = postcontent	; a = s.indexOf("<img"); b = s.indexOf("src=\"",a); c = s.indexOf("\"",b+5); d = s.substr(b+5,c-b-5);
	
		if((a!=-1)&&(b!=-1)&&(c!=-1)&&(d!="")) img[i] = d;
	
		var tmpImg = document.createElement("img");
		tmpImg.src = img[i];
		var w = tmpImg.width/110;
		var h = tmpImg.height/w;
		
		var li = document.createElement("li");
		var div_float = document.createElement("div");
		var div_img = document.createElement("div");
		var img_ = document.createElement("img");
		var div_conteudo = document.createElement("div");
		var a_titulo = document.createElement("a");
		var div_titulo = document.createElement("div");
		var div_texto = document.createElement("div");
		var div_vermais = document.createElement("div");
		var a_vermais = document.createElement("a");
		var img_vermais = document.createElement("img");
	
		//var arr_crimes = [];
		
		div_float.className= 'slideFloatLeft' ;
		div_img.className = 'slide_img';
			img_.style.width = '110px';
			//gambi IE
			h = isNaN(h)?'207':h;
			//
			img_.style.height = h + 'px';
			img_.src = img[i];
		div_img.appendChild(img_);
		div_float.appendChild(div_img);
		
		div_conteudo.className = 'slide_conteudo';
		a_titulo.href = posturl;
		div_titulo.className = 'slide_titulo';
		div_titulo.innerHTML = posttitle;
		a_titulo.appendChild(div_titulo);
		
		div_texto.className = 'slide_texto';
		div_texto.innerHTML = removeHtmlTag(postcontent,summaryPost);
		
		div_vermais.className = 'verMaisCrimes';
		a_vermais.href = posturl;
		img_vermais.src = 'http://i576.photobucket.com/albums/ss205/danilofernandes/novolayout/crimes_populares_leiamais.png';
		a_vermais.appendChild(img_vermais);
		div_vermais.appendChild(a_vermais);
		
		div_conteudo.appendChild(a_titulo);
		div_conteudo.appendChild(div_texto);
		div_conteudo.appendChild(div_vermais);
		
		li.appendChild(div_float);
		li.appendChild(div_conteudo);
		
		arr_crimes.push(li);
	  
		j++;
	}
}
document.write("<script src='http://genizah-virtual.blogspot.com/feeds/posts/default?max-results="+numposts+"&category=Destaque&alt=json-in-script&callback=showrecentposts'><\/script>");

