$(document).ready(function() {
	if($.browser.msie && ($.browser.version < 7)){ 
		$("body").addClass("ie");
		$("ul.redesSociais li a").click(function(){
			window.location = $(this).attr("href");
			return false;
		});
	}
	$("#flashHome").each(function(){
		$link = $(this).attr("rel");
		$(this).flash({ src: '/swf/home.swf', width: 1000, height: 594, wmode: 'transparent', scale: 'noscale', salign: 'tl', flashvars: {
			link: [$link].join(' '),
			oque: ['/oqueRinite/index.php'].join(' '),
			comoConviver: ['/oqueRinite/comoConviver.php'].join(' '),
			mitosVerdades: ['/oqueRinite/mitosVerdades.php'].join(' '),
			tratamentos: ['/oqueRinite/tratamentos.php'].join(' '),
			euTenho: ['/euTenhoRinite.php'].join(' '), 
			games: ['/games/index.php'].join(' '), 
			downloads: ['/downloads.php'].join(' '), 
			indiqueAmigo: ['/indiqueAmigo.php'].join(' '), 
			contato: ['/contato.php'].join(' ') 
		}}, { version: 8 });
	});

	$("#menu").each(function(){
		$link = $(this).attr("rel");
		$(this).flash({ src: '/swf/menu.swf', width: 1000, height: 210, wmode: 'transparent', scale: 'noscale', salign: 'tl', flashvars: {
			link: [$link].join(' '),
			oque: ['/oqueRinite/index.php'].join(' '),
			comoConviver: ['/oqueRinite/comoConviver.php'].join(' '),
			mitosVerdades: ['/oqueRinite/mitosVerdades.php'].join(' '),
			tratamentos: ['/oqueRinite/tratamentos.php'].join(' '),
			euTenho: ['/euTenhoRinite.php'].join(' '), 
			games: ['/games/index.php'].join(' '), 
			downloads: ['/downloads.php'].join(' '), 
			indiqueAmigo: ['/indiqueAmigo.php'].join(' '), 
			contato: ['/contato.php'].join(' ') 
		}}, { version: 8 });
	});
	
	$("#flashTetris").flash({ src: '/swf/tetris.swf', width: 1000, height: 594, wmode: 'transparent' }, { version: 8 });
	$("#flashEspirro").flash({ src: '/swf/espirro.swf', width: 1000, height: 594, wmode: 'transparent' }, { version: 8 });
	$("#flashInvaders").flash({ src: '/swf/nose-invaders.swf', width: 1000, height: 594, wmode: 'transparent' }, { version: 8 });
	$("#flashComoFunciona").flash({ src: '/swf/como_funciona.swf', width: 1000, height: 594, wmode: 'transparent' }, { version: 8 });
	$(".boxContato").append('<img src="/img/bg-contato.png" width="634" height="273" alt="" class="png" />');
	$(".boxIndique").append('<img src="/img/bg-indique.png" width="624" height="283" alt="" class="png" />');
	$(".box453x355").append('<img src="/img/bg-box453x355.png" width="453" height="355" alt="" class="png" />');
	$(".box423x303").append('<img src="/img/bg-box423x303.png" width="423" height="303" alt="" class="png" />');
	$(".box444x297").append('<img src="/img/bg-box444x297.png" width="444" height="297" alt="" class="png" />');
	$(".box553x338").append('<img src="/img/bg-box553x338.png" width="553" height="338" alt="" class="png" />');
	$(".box553x338a").append('<img src="/img/bg-box553x338a.png" width="463" height="338" alt="" class="png" />');


	$("#scrollComoConviver").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 12, showArrows: false });
	$("#scrollTratamentos").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 12, showArrows: false });

	$("#formContato").validate({ errorContainer: $("p.camposObrigatorios"), errorLabelContainer: $(".msgError"), 
		submitHandler: function() {
			$.ajax({  
				type: "post",
				data: $("#formContato").serialize(), 
				dataType: "json",
				url: "inc/formContato.php",
				success: function(json) {
					if(json.msg == "true"){
						$("#formContato textarea").val("");
						$("#boxFormContato").hide();
						$("#boxSucessoContato").fadeIn();
					}else{
						alert("Erro ao enviar mensagem.")
					}
				}  
			}); 
		}
	});	

	$("#formIndique").validate({ errorContainer: $("p.camposObrigatorios"), errorLabelContainer: $(".msgError"),
		submitHandler: function() {
			$.ajax({  
				type: "post",
				data: $("#formIndique").serialize(), 
				dataType: "json",
				url: "inc/formIndique.php",
				success: function(json) {
					if(json.msg == "true"){
						$("#boxFormIndique").hide();
						$("#boxSucessoIndique").fadeIn();
						$("#formIndique input[name^=name_to], #formIndique input[name^=email_to]").val("");
					}else{
						alert("Erro ao enviar mensagem.")
					}
				}  
			}); 
		}
	});	

	$("#formIndique input.opt").keyup(function(){
		if($(this).val() != ''){
			$(this).addClass("required").next().addClass("required");
		}
	});

	$("a.btnFasesTrat").click(function(){
		$fase = $(this).attr("href").split("#")[1];
		$(".fasesTratamento, .antesEraAssim, .tratamento2009, .tratAnos").hide();
		switch($fase){
			case '1':
				$(".antesEraAssim").show();
				$(".prevTratamento").hide();
				$(".prevTratamento").attr("href", "#1");
				$(".nextTratamento").attr("href", "#2");
			break;
			case '2':
				$(".tratAnos").show();
				$(".prevTratamento, .nextTratamento").show();
				$(".prevTratamento").attr("href", "#1");
				$(".nextTratamento").attr("href", "#3");
			break;
			case '3':
				$(".tratamento2009").show().ifixpng();
				$(".prevTratamento, .nextTratamento").attr("href", "#2");
				$(".nextTratamento").hide();
			break;
		}
		$(".fasesTratamento[rel='"+ $fase +"']").fadeIn();
		$("#scrollTratamentos").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 12, showArrows: false });
		return false;
	});

	/* Remove os "hints" para minimizar o bug da validacao... */
	/*$(".btnEnviar").hover(function () {
		$(".hint").each(function(){
			if($(this).val() == $(this).attr("title")){
				$(this).val("");
			}
		});
	}, function () {
		$("input.hint").hint();
	});*/
	/* Remove os "hints" para minimizar o bug da validacao... */

	$("ol#mitosVerdades li a").click(function(){
		$("ol#mitosVerdades li a").removeClass("hover");
		$(this).addClass("hover");
		$item = $(this).attr("href").split("#")[1];
		$(".mito, .verdade").find("div[rel]").hide().end().find("div[rel="+ $item +"]").fadeIn();
		$(".scrollVerdade").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 12, showArrows: false });
		return false;
	});
	$("ol#mitosVerdades li a:first").trigger("click"); // mostra o primeiro item

	$("ul#anosTratamentos li a").click(function(){
		$(".box444x297 .content span[rel], #scrollTratamentos div[rel]").hide();
		$("ul#anosTratamentos li a").removeClass("hover");
		$(this).addClass("hover");
		$item = $(this).attr("href").split("#")[1];
		$(".box444x297 .content span[rel="+ $item +"]").fadeIn();
		$("#scrollTratamentos").find("div[rel]").hide();
		$("#scrollTratamentos").find("div[rel="+ $item +"]").fadeIn();
		$("#scrollTratamentos").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 12, showArrows: false });
		return false;
	});
	$("ul#anosTratamentos li a[href]:first").trigger("click"); // mostra o primeiro item

	$(".btnEnviarOutra").click(function(){
		$("#boxFormContato").fadeIn();
		$("#boxSucessoContato").hide();
	});

	$(".btnIndiqueOutros").click(function(){
		$("#boxFormIndique").fadeIn();
		$("#boxSucessoIndique").hide();
	});

	$(".fix, p.btnOrkut, .comunidadesOrkut, .tratamento2009").ifixpng();
	$("input.hint").hint();
});

function fechajogo(){
	parent.tb_remove();
}

function abreGame(ID){
	switch(ID){
		case 'tetris':
			$url = 'alegroTetris.php';
		break;
		case 'espirro':
			$url = 'espirroAlvo.php';
		break;
		case 'invaders':
			$url = 'noseInvaders.php';
		break;
		default:
			$url = 'alegroTetris.php';
		break;
	}
	tb_show('', '/games/'+ $url +'?keepThis=true&TB_iframe=true&width=1000&height=594&modal=true', false);
}

function comoFunciona(){
	tb_show('', '/oqueRinite/comoFunciona.php?keepThis=true&TB_iframe=true&width=1000&height=594&modal=true', false);
}

/* HINT */
jQuery.fn.hint = function() {
	return this.each(function(){
		var t = $(this);
		var title = t.attr('title');
		if (title) {
			t.focus(function(){
				if (t.val() == title) {
				  t.val('');
				  t.removeClass('blur');
				}
			})
			t.blur(function(){
				if (t.val() == '') {
				  t.val(title);
				  t.addClass('blur');
				}
			})
			t.parents('form:first()').submit(function(){
				if (t.val() == title) {
					t.val('');
					t.removeClass('blur');
				}
			});
			t.blur();
		}
	})
};
