// initialise plugins
jQuery(function(){
    // main navigation init
    jQuery('ul.sf-menu').superfish({
	animation:   {opacity:'show', height:'show'},
	autoArrows:  false,
	dropShadows: false 
    });
    
    jQuery("#catNoticias").change(function(){
	location.href = jQuery(this).val();
    });
    
    // prettyphoto init
    jQuery("a[rel^='prettyPhotoIframe']").prettyPhoto({
	animation_speed: 'fast', /* fast/slow/normal */
	    slideshow: false, /* false OR interval time in ms */
	    autoplay_slideshow: false, /* true/false */
	    show_title: true, /* true/false */
	    allow_resize: true, /* Resize the photos bigger than viewport. true/false */
	    counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
	    theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default */
	    horizontal_padding: 20, /* The padding on each side of the picture */
	    hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
	    wmode: 'opaque', /* Set the flash wmode attribute */
	    autoplay: true, /* Automatically start videos: True/False */
	    modal: false, /* If set to true, only the close button will close the window */
	    deeplinking: false, /* [true or false] Allow prettyPhoto to update the url to enable deeplinking. */
	    overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
	    keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
	    changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
	    callback: function(){}, /* Called when prettyPhoto is closed */
	    ie6_fallback: true,
	    markup: '<div class="pp_pic_holder"> \
				    <div class="ppt">&nbsp;</div> \
				    <div class="pp_top"> \
					    <div class="pp_left"></div> \
					    <div class="pp_middle"></div> \
					    <div class="pp_right"></div> \
				    </div> \
				    <div class="pp_content_container"> \
					    <div class="pp_left"> \
					    <div class="pp_right"> \
						    <div class="pp_content"> \
							    <div class="pp_loaderIcon"></div> \
							    <div class="pp_fade"> \
								    <a href="#" class="pp_expand" title="Expand the image">Expand</a> \
								    <div class="pp_hoverContainer"> \
									    <a class="pp_next" href="#">next</a> \
									    <a class="pp_previous" href="#">previous</a> \
								    </div> \
								    <div id="pp_full_res"></div> \
								    <div class="pp_details"> \
									    <div class="pp_nav"> \
										    <a href="#" class="pp_arrow_previous">Previous</a> \
										    <p class="currentTextHolder">0/0</p> \
										    <a href="#" class="pp_arrow_next">Next</a> \
									    </div> \
									    <p class="pp_description"></p> \
									    {pp_social} \
									    <a class="pp_close" href="#">Close</a> \
								    </div> \
							    </div> \
						    </div> \
					    </div> \
					    </div> \
				    </div> \
				    <div class="pp_bottom" > \
					    <div class="pp_left"></div> \
					    <div class="pp_middle"></div> \
					    <div class="pp_right"></div> \
				    </div> \
			    </div> \
			    <div class="pp_overlay"></div>',
	    gallery_markup: '<div class="pp_gallery"> \
						    <a href="#" class="pp_arrow_previous" style="display:none">Previous</a> \
						    <div style="display:none"> \
							    <ul style="display:none"> \
								    {gallery} \
							    </ul> \
						    </div> \
						    <a href="#" class="pp_arrow_next" style="display:none">Next</a> \
					    </div>',
	    //image_markup: '<img id="fullResImage" src="{path}" />',
	    //flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
	    //quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
	    //iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
	    //inline_markup: '<div class="pp_inline">{content}</div>',
	    //custom_markup: '',
	    social_tools: false
    });

    //if(jQuery(".rap").find("div").size() > 1){
	//faded slider init
	jQuery("#faded").faded({
	    speed: 500,
	    crossfade: true,
	    bigtarget: false,
	    loading: true,
	    autoplay: 10000,
	    autorestart: 2000,
	    autopagination:false
	});
    //}
    // Faz um loop em todos os campos do tipo text
    jQuery("input[type='text']").each(function(){
	// Guarda o elemento na variável $this
	var $this = jQuery(this);
	// Verifica se o elemento tem o atributo title
	// Se tiver...
	if ($this.attr("title")){
	    // Adiciona a class .val-padrao
	    $this.val($this.attr("title")).addClass("val-padrao");
	    // Quando o campo receber o foco
	    $this.focus(function(){
		// Verifica se existe a class
		// Se existir...
		if ($this.is(".val-padrao")){
		    // Remove a class
		    $this.val("").removeClass("val-padrao");
		}
	    });
	    // Quando o campo perder o foco
	    $this.blur(function(){
		// Verifica se o value está vazio
		// Se estiver...
		if ($this.val() == ""){
		    // Adiciona a class .val-padrao
		    $this.val($this.attr("title")).addClass("val-padrao");
		}
	    });
	}
    });
    jQuery(".return_link").click(function(){
	history.go(-1);
    });
   
   //Envio de Comentários de Notícias, se houver
    jQuery("#submitComentario").click(function(){
	var erro = false;
	var objeto;
	var mensagem = "Atenção:\nO FORMULÁRIO tem os seguintes erros:\n";

	if(jQuery("#nmComentario").val() == ""){
	    mensagem = mensagem + "\n - campo NOME está vazio";
	    if (!erro){
		objeto = '#nmComentario';
	    }
	    erro = true;
	}
	
	if(jQuery("#dsEmail").val() == ""){
	    mensagem = mensagem + "\n - campo E-MAIL está vazio";
	    if (!erro){
		objeto = '#dsEmail';
	    }
	    erro = true;
	}else{
	    if(jQuery("#dsEmail").val().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/) == null){
		mensagem = mensagem + "\n - campo E-MAIL está incorreto";
		if (!erro){
		    objeto = '#dsEmail';
		}
		erro = true;
	    }
	}
	
	if(jQuery("#dsComentario").val() == ""){
	    mensagem = mensagem + "\n - campo MENSAGEM está vazio";
	    if (!erro){
		objeto = '#dsComentario';
	    }
	    erro = true;
	}
	
	if(!erro){
	    jQuery("#formComentario").attr('method','post');
	    jQuery("#formComentario").submit();
	}else{
	    window.alert (mensagem);
	    jQuery(objeto).focus();
	    return false;
	}
    });
});

/**
 * Para forçar o fechamento das janelas "modais"
 */
function closeBox() {
    jQuery.prettyPhoto.close();
}

/**
 * Para forçar somente números em campos de preenchimento
 * Para usar:
 * $("#fieldId").keypress(verificaNumero);
 */
function verificaNumero(e){
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
	return false;
    }else{
	return true;
    }	
}

/**
 * Para reCapctha
 */
var RecaptchaOptions = {
   theme: 'custom',
   lang: 'pt',
   custom_theme_widget: 'recaptcha_widget'
};
