///////////////////////////////////////////////////////////////////////////////////////////
// FUNÇOES JQUERY
///////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() {
	// FANCYBOX
	/////////////////////////////////////////////////////////////////////////////////////
	$("a[rel=galeria01]").fancybox({
		'padding'			: 10,						 
		'overlayColor'		: '#fff',
		'overlayOpacity'	: 0.9,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-inside">' + (title.length ? '' + title : '') + '<span class="cinza11C"></span>';
		}
	});
	$("a[rel=tecnica]").fancybox({
		'padding'			: 10,						 
		'overlayColor'		: '#fff',
		'overlayOpacity'	: 0.9,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-inside">' + (title.length ? '' + title : '') + '<span class="cinza11C"></span>';
		}
	});
	$(".lightbox01").fancybox({
		'margin'			: 0,
		'padding'			: 0,
		'overlayColor'		: '#ffffff',
		'overlayOpacity'	: 0.8,
		'width'				: 600,
		'height'			: 450,
		'autoScale'			: false,
		'scrolling'			: 'no',	
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
		
	
	
	// MENU SANFONA
	/////////////////////////////////////////////////////////////////////////////////////
	$("dd").hide();
	$("dd:#aberto").show();
	$("dt a").click(function(){
		$("dd:visible").slideUp("slow");
        $(this).parent().next().slideDown("slow");
        return false;
	});
	
	
	$("#slideshow span").css("opacity","0");	
   	$("#slideshow").mouseover(function () {								
       	$("#slideshow span").stop().animate({opacity: 1}, 'slow');
    });
	$("#slideshow").mouseout(function () {								
      	$("#slideshow span").stop().animate({opacity: 0}, 'slow');
    });

              

	// label forms
	/////////////////////////////////////////////////////////////////////////////////////
	$("#f-nome").inputLabel();
	$("#f-email").inputLabel();	
	$("#f-telefone").inputLabel();	
	$("#f-mensagem").inputLabel();
	$("#mensagem").inputLabel();
	$("#cidade").inputLabel();	
	$("#nasc").inputLabel();
	$("#uf").inputLabel();
	$("#telcont").inputLabel();	
	$("#telrec").inputLabel();
	$("#convenio").inputLabel();
	$("#cirurgia").inputLabel();	
	$("#detcirurgia").inputLabel();
	$("#descricao").inputLabel();
	
	// CYCLE INDEX - BANNER ROTATIVO
	/////////////////////////////////////////////////////////////////////////////////////
	$('#slideshow2').cycle({
		timeout: 10000, 			//Tempo da transição
		speed:   700,  				//Velocidade da transição
		fx:      'scrollHorz', 		//Tipo
		pager:   '#banner_nav', 	//A div que vai aprensetar os números do slides
		prev:    '#banner-prev', 	//Link para voltar ao slide anterior
		next:    '#banner-next' 	//Link para próximo slide
	});
	
	$('#ul-trabalhos').cycle({
		timeout: 100000, 			//Tempo da transição
		speed:   1000,  				//Velocidade da transição
		fx:      'scrollHorz', 		//Tipo
		prev:    '#seta-esq', 		//Link para voltar ao slide anterior
		next:    '#seta-dir' 		//Link para próximo slide
	});
	
	$('#ul-nossos-clientes').cycle({
		timeout: 100000, 			//Tempo da transição
		speed:   1000,  				//Velocidade da transição
		fx:      'scrollHorz', 		//Tipo
		prev:    '#clie-esq', 		//Link para voltar ao slide anterior
		next:    '#clie-dir' 		//Link para próximo slide
	});
	
	$('#slider-quem').cycle({
		timeout: 100000, 			//Tempo da transição
		speed:   1000,  				//Velocidade da transição
		fx:      'scrollHorz', 		//Tipo
		prev:    '#quem-esq', 		//Link para voltar ao slide anterior
		next:    '#quem-dir' 		//Link para próximo slide
	});
	
	$('#ul-nossos-clientes2').cycle({
		timeout: 100000, 			//Tempo da transição
		speed:   1000,  				//Velocidade da transição
		fx:      'scrollHorz', 		//Tipo
		prev:    '#clie2-esq', 		//Link para voltar ao slide anterior
		next:    '#clie2-dir' 		//Link para próximo slide
	});
	
	
	
	
	
});


///////////////////////////////////////////////////////////////////////////////////////////
// GERAL EFEITO MENU
///////////////////////////////////////////////////////////////////////////////////////////
/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

$(function(){
	
	$('#header-menu li a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px -31px)"}, {duration:200})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
		})
		
});
///////////////////////////////////////////////////////////////////////////////////////////
// LABEL FORMULARIO
///////////////////////////////////////////////////////////////////////////////////////////
/**
 * jQuery Initial input value replacer
 * 
 * Sets input value attribute to a starting value  
 * @author Marco "DWJ" Solazzi - hello@dwightjack.com
 * @license  Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * @copyright Copyright (c) 2008 Marco Solazzi
 * @version 0.1
 * @requires jQuery 1.2.x
 */
(function (jQuery) {
	/**
	 * Setting input initialization
	 *  
	 * @param {String|Object|Bool} text Initial value of the field. Can be either a string, a jQuery reference (example: $("#element")), or boolean false (default) to search for related label
	 * @param {Object} [opts] An object containing options: 
	 * 							color (initial text color, default : "#666"), 
	 * 							e (event which triggers initial text clearing, default: "focus"), 
	 * 							force (execute this script even if input value is not empty, default: false)
	 * 							keep (if value of field is empty on blur, re-apply initial text, default: true)  
	 */
	jQuery.fn.inputLabel = function(text,opts) {
		o = jQuery.extend({ color: "#858585", e:"focus", force : false, keep : true}, opts || {});
		var clearInput = function (e) {
			var target = jQuery(e.target);
			var value = jQuery.trim(target.val());
			if (e.type == e.data.obj.e && value == e.data.obj.innerText) {
				jQuery(target).css("color", "").val("");
				if (!e.data.obj.keep) {
					jQuery(target).unbind(e.data.obj.e+" blur",clearInput);
				}
			} else if (e.type == "blur" && value == "" && e.data.obj.keep) {
				jQuery(this).css("color", e.data.obj.color).val(e.data.obj.innerText);
			}
		};
		return this.each(function () {
					o.innerText = (text || false);
					if (!o.innerText) {
						var id = jQuery(this).attr("id");
						o.innerText = jQuery(this).parents("form").find("label[for=" + id + "]").hide().text();
					}
					else 
						if (typeof o.innerText != "string") {
							o.innerText = jQuery(o.innerText).text();
						}
			o.innerText = jQuery.trim(o.innerText);
			if (o.force || jQuery(this).val() == "") {
				jQuery(this).css("color", o.color).val(o.innerText);
			}
				jQuery(this).bind(o.e+" blur",{obj:o},clearInput);
			
		});
	};
})(jQuery);

///////////////////////////////////////////////////////////////////////////////////////////
// CAIXA SCROLL
///////////////////////////////////////////////////////////////////////////////////////////
(function( $ ){

  $.fn.containedStickyScroll = function( options ) {
  
	var defaults = {  
		oSelector : this.selector,
		unstick : true,
		easing: 'linear',
		duration: 500,
		queue: false,
		closeChar: '^',
		closeTop: 0,
		closeRight: 0  
	}  
                  
	var options =  $.extend(defaults, options);
  
	if(options.unstick == true){  
		this.css('position','relative');
		this.append('<a class="scrollFixIt">' + options.closeChar + '</a>');
		jQuery(options.oSelector + ' .scrollFixIt').css('position','absolute');
		jQuery(options.oSelector + ' .scrollFixIt').css('top',options.closeTop + 'px');
		jQuery(options.oSelector + ' .scrollFixIt').css('right',options.closeTop + 'px');
		jQuery(options.oSelector + ' .scrollFixIt').css('cursor','pointer');
		jQuery(options.oSelector + ' .scrollFixIt').click(function() {
			getObject = options.oSelector;
			jQuery(getObject).animate({ top: "0px" },
				{ queue: options.queue, easing: options.easing, duration: options.duration });
			jQuery(window).unbind();
			jQuery('.scrollFixIt').remove();
		});
	} 
  	jQuery(window).scroll(function() {
  		getObject = options.oSelector;
        if(jQuery(window).scrollTop() > (jQuery(getObject).parent().offset().top) &&
           (jQuery(getObject).parent().height() + jQuery(getObject).parent().position().top - 30) > (jQuery(window).scrollTop() + jQuery(getObject).height())){
        	jQuery(getObject).animate({ top: (jQuery(window).scrollTop() - jQuery(getObject).parent().offset().top) + "px" }, 
            { queue: options.queue, easing: options.easing, duration: options.duration });
        }
        else if(jQuery(window).scrollTop() < (jQuery(getObject).parent().offset().top)){
        	jQuery(getObject).animate({ top: "0px" },
            { queue: options.queue, easing: options.easing, duration: options.duration });
        }
	});

  };
})( jQuery );
///////////////////////////////////////////////////////////////////////////////////////////
// CAIXA SCROLL - ACAO
///////////////////////////////////////////////////////////////////////////////////////////
jQuery('#dados-lateral').containedStickyScroll({
	duration: 300
});

///////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO RESPONSAVEL PELA MENSAGEM TITLE
///////////////////////////////////////////////////////////////////////////////////////////
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 10;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});
