$().ready(function (){
	$(".botao").button();
   $(".abrevideo").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$('a.galeria').colorbox();
	
    $('#fornecedores_carousel').jcarousel({
        vertical: true,
        auto: 1,
		scroll:2,
		wrap:"last"
    });
	
 

 	$(function () {
	
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 600,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Iniciar",             // Start text
			stopText: "Parar",               // Stop text
			navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
		});
		
	   
		
	});
});


function formatText(index, panel) {
	  return index + "";
}


var jAlert = function(titulo, textoHtml, objetoFoco, largura,url) {
	if(!largura) { largura = 300; }

	var div = document.createElement('div');
	$(div).addClass('alerta').html(textoHtml).hide().appendTo('body');
	$('div.alerta').dialog({
			title: titulo,
			modal: true,
			width: largura,
			overlay: {backgroundColor:'#777',opacity:'.7'},
			close: function() {
					$('div.alerta').dialog('destroy').remove();
					$(objetoFoco).focus();
					if (typeof(url)!="undefined"){
						window.location=url;
					}
			},
			buttons: {
				'OK': function(){ 
					$('div.alerta').dialog('close');
					$(objetoFoco).focus();
					if (typeof(url)!="undefined"){
						window.location=url;
					}
				} 
			}
	});
}

var jConfirm = function(titulo, textoHtml, url, largura) {
	if(!largura) { largura = 300; }

	var div = document.createElement('div');
	$(div).addClass('alerta').html(textoHtml).hide().appendTo('body');
	$('div.alerta').dialog({
			title: titulo,
			modal: true,
			width: largura,
			overlay: {backgroundColor:'#777',opacity:'.7'},
			close: function() {
					$('div.alerta').dialog('destroy').remove();
			},
			buttons: {
				
				'Cancelar': function(){ 
					$('div.alerta').dialog('close');
				},
				'OK': function(){ 
					$('div.alerta').dialog('close');
					window.location=url;
				}
				
			}
	});
}

function confirma(msg,url){
		jConfirm('Atenção',msg,url);
}
function alerta(msg,url){
	jAlert('Atenção', msg, '', 450, url);
}


validaForm = function (formulario){
	$("form  input").trimFields();
	$("form  textarea").trimFields();
	var form=document.getElementById(formulario);
	var i=0;
	for (i=0;i<form.elements.length;i++){
		if (form.elements[i].title!=""){
			if (form.elements[i].value==""){
				jAlert ('Atenção',form.elements[i].title,form.elements[i]);
				return false;
			}else if (form.elements[i].name=="email"){
					var validacao=/^[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_]+\.([a-zA-Z0-9]{2,4})\.?([a-zA-Z0-9]{2,4})?$/;
					if (!validacao.test(form.elements[i].value)){
						jAlert ('Atenção',"E-mail inválido, por gentileza informe um e-mail válido!",form.elements[i]);
						return false;
					}
			}else if ( (form.elements[i].value=="_____-___") || (form.elements[i].value=="(__) ____-____")  || (form.elements[i].value=="__/__/____") || (form.elements[i].value=="__:__") || (form.elements[i].value=="___.___.___-__") || (form.elements[i].value=="_.___.___") || (form.elements[i].value=="__.___.___/____-__") || (form.elements[i].value=="___.___.___") || (form.elements[i].value=="___-____") ){
				jAlert ('Atenção',form.elements[i].title,form.elements[i]);
				return false;
			
				
			}
			
		}
	}
}

abreJanela =function (url){
	window.open(url,"janela","width=950,height=800,resizeable=no,scrollbars=yes,toolbar=no",true);	
}

jQuery.fn.trimFields = function(){
  this.each(function(){
   $(this).val( jQuery.trim($(this).val()) );
  });
 }



focaPrimeiroCampo=function (){
	$("input").each(function (){
		if ($(this).attr("type")=="text"){
			if ($(this).val()=="" && $(this).attr("id")!="campo_busca"){
				$(this).focus();
				return false;
			}
			
		}
	});
}

function limpaCampo (elemento){
	var campo=$("#"+elemento);
	campo.val("");
}

