﻿var $ = jQuery.noConflict();
var cerrado = true;
var abierto = false;
var imagex = "";

$(document).ready(function(){
	navFunctions();
	
	if($("body").hasClass("home")){
		homeFunctions();
	}
	
})

function navFunctions(){
	$('#menu-principal').spasticNav();
	/*var valorAnterior = "";
	$("#menu-paciente").mouseover(function(){
			valorAnterior = $("#menu-paciente a").html();
			$("#menu-paciente a").html("PR&Oacute;XIMAMENTE");
		}).mouseout(function(){
			$("#menu-paciente a").html(valorAnterior);
		})
	*/
}

function homeFunctions(){
	setInterval( "slideSwitch()", 3000 );
	setInterval( "slideSwitch2()", 6000 );
	notelopierdas();
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitch2(){
    var $active = $('#destacado4 a.active');

    if ( $active.length == 0 ) $active = $('#destacado4 a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#destacado4 a:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}

function notelopierdas() {
	  parpadeoA()
	  imagex = $("#imagen_interior").attr('width');
	  $("#notelopierdas").css('right', 0-imagex-8);
	  
	  
	$("#notelopierdas").click(function(){
	
		$("#notelopierdas").stop;
			
		if (cerrado){
			parpadeoB();
		$("#notelopierdas").animate({
			right:0}
			,1000, function(){
				
				cerrado = false
				abierto = true
			})}
			if (abierto)
			{
		$("#notelopierdas").animate({
			right:0-imagex-8}
			,1000, function(){
				
				
				cerrado = true
				abierto = false
				parpadeoA()
			})}
		})
  };
  function parpadeoA(){
	  if (cerrado){
		  
		  $(".pestananote").fadeOut(1000, function(){
		  
		parpadeoB()
		  })}
		  
	  
	  }
function parpadeoB(){
	 
		  
		  $(".pestananote").fadeIn(1000, function(){
		  
		 setTimeout("parpadeoA()",2000)
		  })
		  
	  
	  }
