$(document).ready(function() {
	
	$(".site select").change(function(){
		
		if(this.value == "")
			return;
		document.location.href = this.value;
		
	});
	
	$(".removerImagem").click(function(){
		if(confirm("Ao remover a imagem verique antes se a mesma não se encontra em um texto.\nPode remover eu verifiquei!")){
			imagem = $(this).attr("id");
			$.post("?", {"remover" : $(this).attr("id")}, function(response){
				response = eval(response) || false;
				if(response){
					$("#"+response).parent().remove();
				}else{
					alert("Erro ao remover imagem tente novamente mais tarde!");
				}
			});
		}
	});
	
	$('*.pme-buttons input:disabled, *.pme-buttons select:disabled, *.pme-goto').remove();
	$('textarea').css("width", "100%");
	$('textarea').css("height", "400px");
	
	$("#pais .conteudo img[longdesc!='galeria'],#pais .notmenu img[longdesc!='galeria']").each(function(){
	    src = $(this).attr("src");
	    html = '<div class="divLegenda"><a href="'+src.replace(/.jpg/g, "-big.jpg")+'" target="_blank"><img class="imgLegenda" title="'+$(this).attr("alt")+'" alt="'+$(this).attr("alt")+'" src="'+src+'"/><div class="txtLegenda"><div>'+$(this).attr("alt")+'</div></div><div class="clearfloat"></div></a></div>';
	    try{
	    $(this).wrap(html);
	    }catch(e){};
	    $(this).remove();
	});
	
	var galeria = $("#pais .conteudo img[longdesc='galeria'],#pais .notmenu img[longdesc='galeria']");
	
	if(galeria.length != false){
		
		var html = '<div class="content"><div id="myGallery" class="myGallery">';
		galeria.each(function(){
		    src = $(this).attr("src");
		    html += '<div class="imageElement"><h3>'+$(this).attr("alt")+'</h3><p></p><a href="'+src.replace(/.jpg/g, "-big.jpg")+'" title="open image" class="open"></a><img src="'+src+'" class="full" /><img src="'+src.replace(/.jpg/g, "-min.jpg")+'" class="thumbnail" /></div>';
		    $(this).remove();
		});
		html += '</div></div>';
		try{
			$('#pais .conteudo p:first, .notmenu p:first').wrap(html);
	    }catch(e){};
	}
	
	if($('#myGallery').length != false){
		try{
			var myGallery = new gallery(Moo.$("myGallery"), {
				timed: true,
				useReMooz: false,
				embedLinks: false
			});
		}catch(e){}
	}
	
	$('.txtLegenda').each(function(){
		if($.trim($(this).children("div").html()) == ""){
			$(this).remove();
		}
	});
	
});

try{
	tinyMCE.init({
		mode : "textareas",
		language : "pt",
		theme : "advanced",
		skin : "o2k7",
		skin_variant : "silver",
		plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,visualchars,nonbreaking,blockquote,pagebreak",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,|,preview,|,forecolor,backcolor,|,cite,abbr,acronym,del,ins",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,|,insertlayer,moveforward,movebackward,absolute,",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		relative_urls : false,
		document_base_url : "http://www.paisesdomundo.com.br/"
	});

}catch(e){};
