
$(document).ready(function($)
{
	
	//jCarousel Plugin
	    $('#carousel').jcarousel({
			vertical: true,
			scroll: 1,
			auto: 2,
			wrap: 'last',
			initCallback: mycarousel_initCallback
	   	});

	$('.slide').css("display","block").nivoSlider(
	{
		effect:'random', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:7000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} 
	}
	
	);	

	//Front page Carousel - Initial Setup
   	$('div#slideshow-carousel a img').css({'opacity': '0.5'});
   	$('div#slideshow-carousel a img:first').css({'opacity': '1.0'});
   	$('div#slideshow-carousel li a:first').append('<span class="arrow"></span>')

  
  	//Combine jCarousel with Image Display
    $('div#slideshow-carousel li a').hover(
       	function () {
        		
       		if (!$(this).has('span').length) {
        		$('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
   	    		$(this).stop(true, true).children('img').css({'opacity': '1.0'});
       		}		
       	},
       	function () {
        		
       		$('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
       		$('div#slideshow-carousel li a').each(function () {

       			if ($(this).has('span').length) $(this).children('img').css({'opacity': '1.0'});

       		});
        		
       	}
	).click(function () {

	      	$('span.arrow').remove();        
		$(this).append('<span class="arrow"></span>');
       	$('div#slideshow-main li').removeClass('active');        
       	$('div#slideshow-main li.' + $(this).attr('rel')).addClass('active');	
        	
       	return false;
	});
	
	
	
	
	
	
	
	$(".cat-select div.jqTransformSelectWrapper ul li a").click(function(){
		var value= $(".cat-select div.jqTransformSelectWrapper span").text()
		if(value != "Selecione uma categoria"){
			$("#nome_categoria").val(value);
			$("form#categoria").submit();
		}
		return false; //prevent default browser action
	});

	
	
	$("#add_dependente").click(function(){
	
		var x=1;
		$(".item-dependente").each(function(i){
			x++;
		})
		if(x>=6){
		return false;
		}
		
		$(".lista-dependentes").prepend('<div class="item-dependente" id="dependente-'+x+'"><div class="titulo-dependente">Dependente 0'+x+'</div><div class="exclui-dependente" id="exclui-dependente'+x+'" title="'+x+'">[X]</div><div class="clear"></div><div class="separador" style="width:200px"><label>Nome</label><input type="text" name="dependente_nome'+x+'" /></div><div class="separador" style="width:200px"><label>Data Nascimento</label> <input type="text" class="data" name="dependente_data_nasc'+x+'" /> </div><div class="separador" style="width:200px"><label>Situação</label><input type="text" name="dependente_situacao'+x+'" /></div><div class="separador" style="width:200px"> <label>Valor Pecúlio</label><input type="text"  name="dependente_valor'+x+'" /></div><div class="clear"></div></div>');
		$('.data').mask('99/99/9999');
		
		$("#exclui-dependente"+x).click(function(){
			
			var y=0;
			$(".item-dependente").each(function(i){
				y++;
			})
			
			if(y == $("#exclui-dependente"+x).attr("title")){
				$("#dependente-"+$("#exclui-dependente"+x).attr("title")).fadeOut(1000).remove();
			}else{
				alert("Exclua o último dependente inserido!");
			}
		
		});
		
		
	});
	
	
	
	$("#add_conta").click(function(){
	
		var x=1;
		$(".item-conta").each(function(i){
			x++;
		})
			
		$(".lista-contas").prepend('<div class="item-conta" id="conta-'+x+'"><div class="titulo-conta">Conta 0'+x+'</div><div class="exclui-conta" id="exclui-conta'+x+'" title="'+x+'">[X]</div><div class="clear"></div><div class="separador" style="width:200px"><label>Número da Conta</label><input type="text" name="conta_numero'+x+'" /></div><div class="separador" style="width:200px"><label>Número Agência</label> <input type="text" name="conta_agencia'+x+'" /> </div><div class="separador" style="width:400px"><label>Titular</label><input type="text" name="titular'+x+'" style="width:400px" /></div><div class="clear"></div></div>');
		$('.data').mask('99/99/9999');
		
		$("#exclui-conta"+x).click(function(){
			
			var y=0;
			$(".item-conta").each(function(i){
				y++;
			})
			
			if(y == $("#exclui-conta"+x).attr("title")){
				$("#conta-"+$("#exclui-conta"+x).attr("title")).fadeOut(1000).remove();
			}else{
				alert("Exclua a última conta inserida!");
			}
		
		});
		
		
	});
	
	$("#add_plano").click(function(){
	
		var x=1;
		$(".item-plano").each(function(i){
			x++;
		})
			
		$(".lista-planos").prepend('<div class="item-plano" id="plano-'+x+'"><div class="titulo-plano">Plano de Saúde 0'+x+'</div><div class="exclui-plano" id="exclui-plano'+x+'" title="'+x+'">[X]</div><div class="clear"></div><div class="separador" style="width:200px"><label>Nome do Convênio:</label><input type="text" name="plano_convenio'+x+'" /></div><div class="separador" style="width:200px"><label>Instituição</label> <input type="text" name="plano_instituicao'+x+'" /> </div><div class="clear"></div></div>');
		$('.data').mask('99/99/9999');
		
		$("#exclui-plano"+x).click(function(){
			
			var y=0;
			$(".item-plano").each(function(i){
				y++;
			})
			
			if(y == $("#exclui-plano"+x).attr("title")){
				$("#plano-"+$("#exclui-plano"+x).attr("title")).fadeOut(1000).remove();
			}else{
				alert("Exclua o último plano inserido!");
			}
		
		});
		
		
	});
	
	

	$("#bt-pg-anterior").click(function(){
		var atual = $(".number-pg").css("margin-left");
		var wi = atual.split("px");
		var width = parseInt(wi[0])+16;
		
		$(".number-pg").css("margin-left",width+"px");
	
	});
	$("#bt-pg-proximo").click(function(){
		var atual = $(".number-pg").css("margin-left");
		var wi = atual.split("px");
		var width =  parseInt(wi[0])-16;
		
		$(".number-pg").css("margin-left",width+"px");
	
	});
	
	$("#categoria-info").change(function(){

		var value= $(this).val();

		window.location="index.php?metodo=informativos&id="+value;

	});

	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	
	
	$('.data').mask('99/99/9999');
	$('.telefone').mask('(99) 9999-9999');
	
	
	// Monta janelas DIALOG JQUERY UI
	$(".dialog").dialog({
		bgiframe: true,
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	$(".dialog-info").dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	
	
	

});
function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	
}
function mycarousel_initCallback(carousel) {
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
}

function validaSenha(f){
	
	if(document.f.senha.value == ""){
		alert("Digite a nova senha!");
		return false;
	}
	if(document.f.senha2.value == ""){
		alert("Digite a repetição da senha!");
		return false;
	}
	
	if(document.f.senha.value != document.f.senha2.value){
		alert("As senhas digitadas não coincidem!");
		return false;
	}
	return true;
	
}

function validaLogin(){
	
	if(document.form.login.value == ""){
		alert("Digite seu Login!");
		return false;
	}
	if(document.form.senha.value == ""){
		alert("Digite sua senha!");
		return false;
	}
	return true
}


