var popup=null;

jQuery(
	function() {
		if (Liferay.Browser.isIe() && Liferay.Browser.getMajorVersion() < 7) {
			jQuery('#navigation > ul > li').hover(
				function(event) {
					jQuery(this).addClass('hover');
				},
				function(event) {
					jQuery(this).removeClass('hover');
				}
			);
		}
	}
);
//carrossel notícias

jQuery(function(){
	jQuery('#slider-stage').carousel('#previous', '#next');
}
);


//carrossel album de fotos

jQuery(function(){
	jQuery('#slider-stage_album').carousel('#previous_album', '#next_album');
});


function AlteraNoticiaPrincipal(link, imagem, categoria, titulo, descricao, linkComentario, podcast, video, obj, userPrefs, noticia_id, user_id){

	jQuery(function(){
		jQuery('#noticia_principal_foto_id').fadeOut('fast');
		jQuery('#link_noticia_principal_titulo').fadeOut('fast');
		jQuery('#link_noticia_principal_descricao').fadeOut('fast');
		jQuery("div[id^='adminhaprefeitura']").fadeOut('fast');
	});

	var linkImagem = document.getElementById('noticia_principal_foto_link');
	linkImagem.href = link;
	var pCategoria = document.getElementById('p_categoria_noticia');
	pCategoria.innerHTML = categoria;
	
	var foto = document.getElementById('noticia_principal_foto_id');
	if(imagem == ''){
		document.getElementById('noticia_principal_foto').style.display = 'none';
	}else{
		document.getElementById('noticia_principal_foto').style.display = 'block';
	}
	foto.src = imagem;
	foto.title = titulo;
	
	var link_noticia = document.getElementById('link_noticia_principal_titulo');
	link_noticia.href = link;
	link_noticia.innerHTML = titulo;
	var link_descricao = document.getElementById('link_noticia_principal_descricao');
	link_descricao.href = link;
	link_descricao.innerHTML = descricao;
	


	
	if(linkComentario !=0){


	}else{



	}




	if(podcast == ''){

	}else{

	}



	if(new String(video).length < 43){

	}else{

		var link_video = document.getElementById('link_noticia_video');
		link_video.href = video;
	}

	var div_mp = document.getElementById('adminhaprefeitura');
	var widgetName = "noticia-"+noticia_id;


	jQuery(function(){
		jQuery('#noticia_principal_foto_id').fadeIn('slow');
		jQuery('#link_noticia_principal_titulo').fadeIn('slow');
		jQuery('#link_noticia_principal_descricao').fadeIn('slow');
		jQuery("div[id^='adminhaprefeitura']").fadeIn('slow');
	});
}




function showPopup(url, params, width ,height, title, modal){
	
	var conteudo = jQuery.ajax({
		  					url: url,
		  					data:params,
		  					async: false
		 			}).responseText;
	
	popup = Liferay.Popup({title:title,
							   width:width,
							   height:height,
							   message: conteudo,	
							   modal: modal
	                         });
}

 function showImagePopup(url, downloadurl, params, width ,height, title, modal){
	 var html = "<img src=\""+url+"\"></img>";
	 if(downloadurl != ""){
		 downloadurl = new String(downloadurl).replace("/image/image_gallery","/imagens");
		 html += "<br /><center><a href=\""+downloadurl+"\">Clique aqui e faça o download da imagem</a></center>";
		 height = (height + 28);
	 }
	 jQuery("#dialog").dialog({ modal: true, width: width, height:(height + 28), title:title});
	 jQuery("#dialog").html(html);
}

function showIframePopup(url, width ,height, title, modal){
		
	popup = Liferay.Popup({title:title,
							   width:width,
							   height:height,
							   message: "<iframe src=\""+url+"\" width="+(width-3)+" height="+(height-3)+"></iframe>",
							   modal: modal
					         });
}

function MudarTamanho(Tipo, Objeto)
{
	if (navigator.appName == "Netscape") {
		b_objeto_i="document.getElementById('";
		b_objeto_f="')"; 
	}else{
		b_objeto_i="document.all.";
		b_objeto_f="";
	}
	eval("var obj=" + b_objeto_i + Objeto + b_objeto_f);
	var Tamanho = parseFloat(obj.style.fontSize.replace("em",""));
	if(isNaN(Tamanho))
	{
		Tamanho=.9;
	}
	Tamanho=(Tipo==0 ? .9 : Tamanho+Tipo);
	if(Tamanho < 1.7 && Tamanho > 0.5){
		obj.style.fontSize=Tamanho+"em";
	}
}

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}


function getFileNewSize(originalSize){
	var numSize = new Number(originalSize);
	if(numSize > 1048576){
		document.write(rounding(numSize / 1048576)+' mb');
	}else if (numSize > 1024){
		document.write(rounding(numSize / 1024) + ' kb');
	}else{
		document.write(numSize+' b');
	}
	
}

function updateUserPrefs(userId, id, type, add, obj, title ,communityUrl, exibeConteudoPagePath, pubPath){
	
	if(userId != null && userId != ""){
		if(add){
			servlet = "/AddToUserPrefs";
			oper = "add";
		}else{
			servlet = "/RemoveFromUserPrefs";
			oper = "remove";
		}
		
		jQuery.ajax({
			type: "POST",
			url: servlet,
			data:{id:id, type:type, userId:userId},
			success: function(response){
				var div_mp = obj.parentNode;
				if(add){
					div_mp.title = "Remover da Minha Prefeitura";
					div_mp.innerHTML = "<a href='javascript:;' onclick=\"javascript:updateUserPrefs('"+userId+"', '"+id+"', '"+type+"', false, this, '"+title+"','"+communityUrl+"','"+exibeConteudoPagePath+"','"+pubPath+"');\">Remover da Minha Prefeitura</a>";
					if(div_mp.className == "adminhaprefeitura")
						div_mp.className = "remminhaprefeitura";
					else if(div_mp.className == "adminhaprefeitura2")
						div_mp.className = "remminhaprefeitura2";
					else if(div_mp.className == "add")
						div_mp.className = "remover";
						
				}
				else{
					div_mp.title = "Adicionar � Minha Prefeitura";
					div_mp.innerHTML = "<a href='javascript:;' onclick=\"javascript:updateUserPrefs('"+userId+"', '"+id+"', '"+type+"', true, this, '"+title+"','"+communityUrl+"','"+exibeConteudoPagePath+"','"+pubPath+"');\">Adicionar � Minha Prefeitura</a>";
					if(div_mp.className == "remminhaprefeitura")
						div_mp.className = "adminhaprefeitura";
					else if(div_mp.className == "remminhaprefeitura2")
						div_mp.className = "adminhaprefeitura2";
					else if(div_mp.className == "remover")
						div_mp.className = "add";
				}
				
				updateMPStartPortlet(oper, type, id, title, communityUrl, exibeConteudoPagePath, pubPath);

			}
		});
		
		
		
	}else{	
		showPopup("msgcadastrese.jsp","",600,150,"Tecle ESC para sair",true);
	}
}




