$(document).ready(function(){
	// checkboxs box home inserir not�cia						   
	$('.chck_not_home').click(function(){
	   if($(this).is(":checked")){
		     $('.box_na_home').slideUp();
		     $(this).parent().find('div.box_na_home').slideDown(800);
	   }	 
	});						   
	$("#sem-exp").click(function () {
       $(".mostra_data").slideUp(800);
    });
	
	$(".rd_twit").click(function () {
       $("#box-twitter").slideDown(800);
    });
	$(".rd_no_twit").click(function () {
       $("#box-twitter").slideUp(800);
    });
	
	//tornar áudio ou vídeo um destaque
	$(".midia_no_dest").click(function () {
       $("#box-midia-dest").slideUp(800);
    });
	$(".midia_dest").click(function () {
	   $("#box-midia-dest").slideDown(800);
    });
	
	
	$(".rd_colab").click(function () {
       $("#box-colab").slideDown(800);
    });
	$(".rd_no_colab").click(function () {
       $("#box-colab").slideUp(800);
    });
	
	$("#sem-exp").click(function () {
       $(".mostra_data").slideUp(800);
    });	
	$(".lbl_agn_sim").click(function () {
       $("#box-agencia").slideDown(800);
    });	
	$(".lbl_agn_nao").click(function () {
       $("#box-agencia").slideUp(800);
    });		
	
	$("#com-exp").click(function () {
       $(".mostra_data").slideDown(800);
    });		
				   
	$(".vd_fora").click(function(){
        if($(this).is(":checked")){
            $("#anexo").slideUp(800);  
			$("#ytbox").show();
        } 
    });	
	$("#add-sec").click(function(){
            $("#new-sec").slideDown(800);  
    });	
	$("#add-sec2").click(function(){
            $("#new-sec2").slideDown(800);  
    });	
	$("#add-sec3").click(function(){
            $("#new-sec3").slideDown(800);  
    });		
	$(".vd_anex").click(function(){
        if($(this).is(":checked")){
            $("#ytbox").slideUp(800);  
			$("#anexo").show();
        } 
    });	
	$(".clr_txt").focus(function () {
	if($(this).attr("value") == 'Achar conte�do do m&ecirc;s'){
		  $(this).attr({ value: "" });
	}
	});
	$(".clr_txt").blur(function () {
		if($(this).attr("value") == ''){
			  $(this).attr({ value: "Achar conte�do do m�s" });
		}
	});
						   
	$(".link-togle").toggle(
		   function() {
			  $("#form-imagens").slideUp(800); 
			  $(this).css("backgroundImage", "url(img/click_togle_+.gif)");
		   },
		   function() {
			  $("#form-imagens").slideDown(800);	
			  $(this).css("backgroundImage", "url(img/click_togle.gif)");
		   }
	);
	$("#publicar_alterar").click(function(){
        if($(this).is(":checked")){
            $(".mudar_data").slideDown(800);    
        }
        if($("#publicar_agora").is(":checked")){
            $(".mudar_data").hide();
        }
    });

	
	$("#ph_sim").click(function(){
        if($(this).is(":checked")){
            $("#all-home").slideDown(800);    
        }
    });	
	$("#ph_nao").click(function(){
        if($(this).is(":checked")){
            $("#all-home").slideUp(800);    
        }
    });		

	$(".show_data").click(function(){
        if($(this).is(":checked")){
            $(".mudar_data").slideDown(800);    
        }
    });	
	$(".link-togle-edit").toggle(
		   function() {
			  $("#editar-galeria").slideUp(800); 
			  $(this).css("backgroundImage", "url(img/click_togle_+.gif)");
		   },
		   function() {
			  $("#editar-galeria").slideDown(800);	
			  $(this).css("backgroundImage", "url(img/click_togle.gif)");
		   }
	);	
/*	$(".tit-direito").toggle(
		   function() {
			  $("#direitos").slideDown(600);	
			  $(this).css("backgroundPosition", "0 3px");			  
		   },
		   function() {
		      $("#direitos").slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");				  
		   }
	);	*/
	$(".tit-direito, .tit-direito2").toggle(
		   function() {
			  $(this).parent().next().slideDown(600);	
			  $(this).css("backgroundPosition", "0 3px");			  
		   },
		   function() {
		      $(this).parent().next().slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");				  
		   }
	);
	/*$(".tit-direito2").toggle(
		   function() {
			  $("#direitos2").slideDown(600);	
			  $(this).css("backgroundPosition", "0 3px");			  
		   },
		   function() {
		      $("#direitos2").slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");				  
		 
		 }
	);	*/
	$(".tit-direito3").toggle(
		   function() {
			  $("#direitos3").slideDown(600);	
			  $(this).css("backgroundPosition", "0 3px");			  
		   },
		   function() {
		      $("#direitos3").slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");				  
		   }
	);
	$(".tit-direito4").toggle(
		   function() {
			  $("#direitos4").slideDown(600);	
			  $(this).css("backgroundPosition", "0 3px");			  
		   },
		   function() {
		      $("#direitos4").slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");				  
		   }
	);	
	$(".tit-coment").toggle(
		   function() {
			  $("#box-coment").slideDown(600);
			  $(this).css("backgroundPosition", "0 3px");
		   },
		   function() {
		      $("#box-coment").slideUp(600);	
			  $(this).css("backgroundPosition", "0 -53px");			  
		   }
	);	
	
	$("#h_mi").click(function(){
        if($(this).is(":checked")){
            $("#home1").slideDown(800);  
			$("#home2").hide(); 
			$("#home3").hide(); 			
        }
    });
	$("#h_mh").click(function(){
        if($(this).is(":checked")){
            $("#home2").slideDown(800);  
			$("#home1").hide(); 
			$("#home3").hide(); 			
        }
    });	
	$("#h_dh").click(function(){
        if($(this).is(":checked")){
            $("#home3").slideDown(800);  
			$("#home1").hide(); 
			$("#home2").hide(); 			
        }
    });		
	$("#show-home1").toggle(
		   function() {
			  $("#home1").slideDown(600);
			  $(this).css("backgroundPosition", "0 2px");
			},
		   function() {
		      $("#home1").slideUp(600);	
  			  $(this).css("backgroundPosition", "0 -55px");
		   }
	);
	$("#show-home2").toggle(
		   function() {
			  $("#home2").slideDown(600);
			  $(this).css("backgroundPosition", "0 2px");
		   },
		   function() {
		      $("#home2").slideUp(600);
  			  $(this).css("backgroundPosition", "0 -55px");
		   }
	);
	$("#show-home3").toggle(
		   function() {
			  $("#home3").slideDown(600);
			  $(this).css("backgroundPosition", "0 2px");
		   },
		   function() {
		      $("#home3").slideUp(600);	
  			  $(this).css("backgroundPosition", "0 -55px");
		   }
	);	
	$(".tornar-dest").click(
    	function() {
			$(this).hide();
			$(this).siblings().show();	
	    }
	);
	$("#a-ciente").click(
    	function() {
			$("#aviso").slideUp(800);
	    }
	);	
	$(".a-esq").click(
    	function() {
			$(".form-login").hide(300);
			$(".form-esqueci").fadeIn(800);	
	    }
	);	
	$("#zipimg").click(
    	function() {
			$(".se-zip").slideUp(600);
	    }
	);	
	$("#umaimg").click(
    	function() {
			$(".se-zip").slideDown(600);
	    }
	);
	// adicionar em correioNet
	$("#a_n_set").click(function() {
		$(".n_set").slideDown(600);
	});
	$("#a_n_grup").click(function() {
		$(".n_grup").slideDown(600);
	});
	$("#a_n_ativ").click(function() {
		$(".n_ativ").slideDown(600);
	});	
	
	// abas visual e html
	$(".op_visu a").click(function() { 
		$(this).parent().find("a").removeClass("a_up");
		$(this).addClass("a_up");
	});	
	 $(".inp_erro").keypress(function () {
			$(this).removeClass("inp_erro");
	});
	 
	$(".input-txt, .area_sub").focus(function () { 
			 $(this).addClass("focus"); 
	});
	$(".input-txt, .area_sub").blur( function(){ 
			$(this).removeClass("focus"); 
	});	
	
	$(".input-textarea").focus(function () { 
			 $(this).addClass("focus"); 
	});
	$(".input-textarea").blur( function(){ 
			$(this).removeClass("focus"); 
	});	

});
//ajustar altura do subMenu
var viewportheight;
if (typeof window.innerWidth != 'undefined'){
 viewportheight = parseFloat(window.innerHeight);
}
else if (typeof document.documentElement != 'undefined' && document.documentElement.clientWidth != 0){
 viewportheight = parseFloat(document.documentElement.clientHeight);
}
else{
 viewportheight = parseFloat(document.getElementsByTagName('body')[0].clientHeight);
}

/*$(document).ready(function(){
	if (viewportheight <= 562) {//if resolution 800x600 or less
	 var offset = $("#menu").offset();
	 var docMenu = document.getElementById("menu");
	 docMenuHeight = docMenu.offsetHeight; // guarda a altura do menu	
	altura = viewportheight - offset.top - docMenuHeight; //height of site's top
	var tds = document.getElementsByTagName('ul');
		for (var i=0; i<tds.length; i++){
		  var tdsSub = tds[i];
			 if (tdsSub.className == 'subMenu'){
				 altSub = parseInt(tdsSub.offsetHeight);
				 if(altSub > altura){
						 tdsSub.style.height = altura + 'px';
						 tdsSub.style.overflow = 'auto';
				 }
			} 
		}
	}
});*/

/*
Acrescentando Barra de Rolagem ao subMenu quando a resolu��o for menor do que a altura do mesmo.
*/
$(document).ready(function(){
	if (viewportheight <= 562) {//if resolution 800x600 or less
	 var offset = $("#menu").offset();
	 var docMenu = document.getElementById("menu");
	 docMenuHeight = docMenu.offsetHeight; // guarda a altura do menu	
	altura = viewportheight - offset.top - docMenuHeight; //height of site's top
	var tds = docMenu.getElementsByTagName("ul");
		for (var i=0; i<tds.length; i++){
		  var tdsSub = tds[i];
			 altSub = tdsSub.offsetHeight;
			 if(altSub > altura){
					 tdsSub.style.height = altura + 'px';
					 tdsSub.style.overflow = 'auto';
					 tdsSub.style.width = '145px';
			 }
		}
	}
});

/*
Empurrando o rodape para o bottom
*/
$(document).ready(function(){
   bod = document.getElementsByTagName('body');
   if (bod[0].offsetHeight < viewportheight) {
	   margin = (viewportheight - bod[0].offsetHeight);
		var cont = document.getElementById('content');
		cont.style.marginBottom = margin + "px";
   }
});


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        //if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) { 
		if (theInput.type == 'text' && theInput.className == 'cleardefault txt' || theInput.className == 'cleardefault input-txt txt') {
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

/*
Config Tooltip
*/
$(document).ready( function() {
/*	$("input[@type=checkbox]").click(function () {
      $(".display-none").slideToggle("slow");
    });*/
	$(function() {
	  $('.form-tooltip label').Tooltip({ showURL: false, top: -20 });
	  $('.info').Tooltip({ showURL: false, top: -20 });
	   $('.op_visu a').Tooltip({ showURL: false, top: -20 });
	  $('#bd_gr_home #content #hside a').Tooltip({ showURL: false, top: -20 });
    });
		
});


// FOR�A LINKS A ABRIREM EM UMA NOVA JANELA

window.onload = function(){
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anc = anchors[i];
            if(anc.getAttribute("href") && anc.getAttribute('rel')=='externo') { 
			// <-- � necess�rio inserir rel="externo" no link
                anc.target = '_blank';
                var title = anc.title + ' (Este link abre uma nova janela)'; 
				// <-- Insere este texto no final do Title do link
                anc.title = title;
            }
        }
    }
}

