/*

#################################################################################################################

#***************************************************************************************************************#

#***************************************************************************************************************#

#**********************************                                       **************************************#

#----------------------------------                 SCRIPTS               --------------------------------------#  

#**********************************                                       ************************************* #

#***************************************************************************************************************#

#***************************************************************************************************************#

#################################################################################################################

*/



$(window).load(function() {
	
	$('#slider img').show();

////
});




/*------------------------START DOC READY*/

$(document).ready(function(){
	
	
	
	
/*------------------------HOVER NAV*/
	
//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

       /* $(this).find(".sub").css({'width' :biggestRow}); //Set width*/
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

       /*$(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width*/

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}	



//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
/*------------------------END HOVER NAV*/	


/*------------------------IMAGE SLIDE*/	

var actual_about = 1;
	
function gallerySlideFunc() {
	

var total_about = $("#home-slide img").length;
     
	if ( actual_about < total_about ) {
		
		var next = actual_about + 1; 

	} else {
		
		var next = 1;
	}

	function switchSlide(next){
		
		$(".img_" + next).css('z-index', 1).css('opacity',1).addClass("current");
		
		$(".img_" + actual_about).css('z-index', 2).animate({ opacity: 0 }, 500 , "linear" , function(){
			$(this).removeClass("current");
		});
		
		actual_about = next;
		
	} /* end switchSlide */
	switchSlide(next);
} /* end gallerySlideFunc */
	
setInterval(gallerySlideFunc, 5000);	
	
/*------------------------END IMAGE SLIDE*/	
	
	
/*------------------------ PROFILE*/		
	
$('.profile').hoverIntent( hovProfile, outProfile ); //Trigger Hover intent with custom configurations



function hovProfile() {
	
	if ( $(this).find('.prof-content').css('display')=='none' ) {
		$(this).css('background-color', '#dedede');
	};
}

function outProfile() {
	$(this).css('background-color', '#f3eeee')
}

var active = true;

$('.profile').click( function() {
	
	var profile = $(this).find('.prof-content');
		
	if (active == true) {
		
		$(this).css('background-color', '#f3eeee');
	
	
		if ( $(profile).css('display')=='none' ) {
			
			if(!$(this).hasClass('currentProfile')){
				
				active = false;
				
				$('.currentProfile .prof-content *').fadeTo(300, 0, function() {
					$(this).parent().parent().removeClass('currentProfile');
    				$(this).parent().hide('slow');
    				
    				active = true;
    			});
				$(this).addClass('currentProfile');
				$(profile).slideDown('slow', function() {
					
    				$(this).find('*').fadeTo(300, 1, function() {
    					$(this).css('filter','');

    					active = true;
    				});
					
  				});
  			}
			
		} else {
			active = false;
			$(this).removeClass('currentProfile');
    		$(this).find('.prof-content *').fadeTo(300, 0, function() {
    		$(this).parent().hide('slow');
    		active = true;
    		});

		}
	};
	
});

/*------------------------ END PROFILE*/

$('a.Q').click (function() {
	
	$(this).parent().next().slideToggle(600);
	
});

/*------------------------ FAQS*/



/*------------------------ END FAQS*/	



/*------------------------ TREATMENTS */


$('.thumb-small , .thumb-big').hoverIntent( hovThumb, outThumb ); 
	


function hovThumb () {
	$(this).addClass('hover');
	$(this).find('.img-color').css("opacity" , 0);
	$(this).find('.img-color').animate({ 'opacity' : 1}, 200);
};

function outThumb () {
	$(this).removeClass('hover');
	$(this).find('.img-color').animate({ 'opacity' : 0});
	
};


/*------------------------ END TREATMENTS */

/*------------------------ CONTACT 

$('.map').hoverIntent( hovMap, outMap ); 

function hovMap () {
	$('.tool-tip').fadeIn(500);
};

function outMap () {
	$('.tool-tip').fadeOut(500);
};
------------------------ END CONTACT */	





	
});  /* end DOM Ready*/ 

/*-----------------END START DOC READY*/





/*VALIDATION EMAIL*/
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {

   if(nm == "name"){
      if(val=="Nombre"){
	      $("#name_error").show("slow");
		  $("#name_ok").hide("slow");
		  errors += "name"
	  }
  else if (val=="Name"){
		  $("#name_error").show("slow");
		  $("#name_ok").hide("slow");
		  errors += "name"
		  }
	  
	   else{
	     $("#name_error").hide("slow");
		  $("#name_ok").show("slow");
	  }
	
	};
	  
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) {
		  $("#email_ok").hide("slow");
		  $("#email_error").show("slow");
		  errors += "email"
		} else 
		{
		  $("#email_error").hide("slow");
		  $("#email_ok").show("slow");
		}
		 
        } else if (test!='R') { num = parseFloat(val);
         
	
		
     if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors){
	document.MM_returnValue = (errors == '');}
	else{
	document.forms[0].submit();
	}
} }
//-->

function gup( name ){
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp ( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return"";
	else
		return results[1];
}


function evalmail(){

var message = gup( 'email' );

if (message == "sent"){
	$("#msg_mail").show("slow");

}

}

















