var WellClinic = {
	_init: function(){
		try{
			this._util();
			this._menu_navegation();
			this._home_webdoor();
			this._expander_content();
		}catch(e){
			alert(
				'Arquivo   : ' + e.fileName + ' \n ' +
				'Linha     : ' + e.lineNumber + ' \n ' +
				'Nome      : ' + e.name + ' \n ' +
				'Descrição : ' + e.message + ' \n '
			);
		};
	},
	
	_util: function(){
		/* IE png fix */
		if(!/msie [^6]\.0/i.test(navigator.userAgent) && /msie 6\.0/i.test(navigator.userAgent)){
			DD_belatedPNG.fix('.pngfix, header .idioma a, header nav ul li.drop');
		};
		$('a.topo_pag').click(function(){
			$('html,body').animate( { scrollTop: 0 }, 'slow' );
		});
		if($("#galeria_thumbs a.fancybox").length){
			//alert($("#galeria_thumbs a.fancybox").length);
			$("#galeria_thumbs a.fancybox").attr('rel', 'gallery').fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.2,
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			$('#fancybox-right-ico, #fancybox-left-ico, #fancybox-title-over, #fancybox-close').addClass('pngfix');
		}
	},
	
	_expander_content: function(){
		// verifica se a página tem o texto expandível (em parceiros)
		if($('div.box_expande .txt p').length){
			//remover espaços em branco no início ou no fim da tag <p>
			$('div.box_expande .txt p').html(jQuery.trim($('div.box_expande .txt p').html()));
			$('div.box_expande .txt p').expander({
				slicePoint:			100,  // default is 100
				expandText:			'<a href="javascript:;" class="saiba cufonBookC">» Saiba Mais</a>', // default is 'read more...'
				expandPrefix:		'',
				expandEffect:		'slideFadeToggle', // função criada
				expandSpeed:		'slow', // velocidade para expandir
				userCollapseText:	'<a href="javascript:;" class="saiba cufonBookC">» Fechar</a>'  // default is '[collapse expanded text]'
			});
		}
	},
	
	_menu_navegation: function(){
		$('header nav ul li.drop').hover(function(){
			//$(this).find('a').addClass('active');
			$(this).addClass('mark');
			$(this, 'ul').find('ul').show().stop(true).animate({opacity:'1'},200);//.fadeIn('fast');
			$(this).find('ul li a').css({color:'#036e72'});
		}, function(){
			//$(this).find('a').removeClass('active');
			$(this).removeClass('mark');
			$(this, 'ul').find('ul').stop(true).animate({opacity:'0'},200, function(){ $(this).hide(); });//.hide();
		})
	},
	
	_home_webdoor: function(){
		if($('.webdoor #banner').length){
			$('.webdoor #banner').cycle({
                speedIn:	600,
                fx:			'fade',
                timeout:	6000,
                fit:		true,
                height:		406,
                width: 		950,
				next: 		'.next',
				prev: 		'.prev'
            });
		}
	}
};

function onCufon(){
	 /* Garamond_Bold_Condensed_700 */
	Cufon.replace('.cufonBoldC', {
		fontFamily: 'Garamond Bold Condensed'
	});
	
	/* Garamond_Book_Condensed_400 */
    Cufon.replace('.cufonBookC', { 
		fontFamily: 'Garamond Book Condensed'
	});
	
	/* MENU Garamond_Book_Condensed_400 */
    Cufon.replace('header nav ul:has(ul) > li a', { //Seleciona apenas o primeiro nível
		fontFamily: 'Garamond Book Condensed', textShadow: '#266e73 0px -1px', letterSpacing: '-0.5px'
	});

	/* Garamond_Light_Condensed_200 */
    Cufon.replace('.cufonLightC, article h3', { 
		fontFamily: 'Garamond Light Condensed'
	});
	Cufon.replace('.texto_central h2', { 
		fontFamily: 'Garamond Light Condensed', letterSpacing: '-0.7px'
	});
}

function onCufonHover(){
	 $('header nav ul:has(ul) > li.drop').hover(function(){
		Cufon.replace($(this).children('a'), {fontFamily: 'Garamond Book Condensed', color: '#036e72', letterSpacing: '-0.5px'});
		}, function(){
			if ( $(this).children('a').hasClass('active') )
				Cufon.replace($(this).children('a'), {fontFamily: 'Garamond Book Condensed', color: '#00f6ff', textShadow: '#266e73 0px -1px', letterSpacing: '-0.5px'});
			else
				Cufon.replace($(this).children('a'), {fontFamily: 'Garamond Book Condensed', color: '#FFF', textShadow: '#266e73 0px -1px', letterSpacing: '-0.5px'});
	});
	$('header nav ul:has(ul) > li').not('.drop').hover(function(){
		Cufon.replace($(this).children('a'), {fontFamily: 'Garamond Book Condensed', color: '#00f6ff', textShadow: '#266e73 0px -1px', letterSpacing: '-0.5px'});
		}, function(){
		Cufon.replace($(this).children('a'), {fontFamily: 'Garamond Book Condensed', color: '#FFF', textShadow: '#266e73 0px -1px', letterSpacing: '-0.5px'});
	});
}

function strip(html) {
   var tmp = document.createElement("DIV");
   tmp.innerHTML = html;
   return tmp.textContent||tmp.innerText;
}

function sendAjaxData(oForm){
	$.ajax({
		type	: "POST",
		cache	: false,
		url		: $(oForm).attr('action'),
		data	: $(oForm).serializeArray(),
		success	: function(data) {
			retAjaxData($(oForm).attr('id'),data);
		},
		error	: function(XMLHttpRequest, textStatus, errorThrown) {
			retAjaxData($(oForm).attr('id'),0);
		}
	});
}

function retAjaxData(formId,data){
	if(formId == 'form_contato'){
		if(data > 0){
			alert('Obrigado pelo contato!');
			$(':input','#'+formId).not(':button, :submit').val('');
		} else {
			alert('Ocorreu um erro! Tente novamente.');
			$('#'+formId).find(':submit').removeAttr("disabled");
		}
	}
}

jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function() {
	WellClinic._init();
	onCufon();
	onCufonHover();
});
