// JavaScript Document
$(function(){
	
	// Efeito no menu principal
	$('#header ul li a').corner('all').css({opacity: 0.5}).hover(
		function(){
			$(this).animate({ opacity: 1 },	300);
		}, 
		function(){
			$(this).animate({ opacity: 0.5 }, 300);
		}
	);	
	
	// Pega os Twittes da Infinity

	$.ajax({  
		url : "http://twitter.com/statuses/user_timeline/infinity_br.json?&count=5&callback=?",  
		dataType : "json",  
		timeout:15000,  
		success : function(data)
		{  
			$("#data").html("Data successfully obtained! <br />");  
			for (i=0; i<data.length; i++){  
				$("#tweets").append("<p>" + data[i].text) +"</p>";  
			}  			
			$('#tweets').cycle();
		},  
		error : function()
		{  
		   $('#tweets').html("");
		},  
	});  
	
	// Home
	$('#container-home').corner('all');
	$('#destaques').cycle({pager:  '#pager', next: '#next2', prev: '#prev2'});
	$('#slider-code').tinycarousel({
		interval: true,
		display: 2
	}).corner('all');
	
	// Internas
	$('.conteudo').corner('all');
	$('#paginacao a, #paginacao .current').corner('all');
	$('.cliente').tooltip({

		// place tooltip on the right edge
		position: "bottom center",
	
		// a little tweaking of the position
		offset: [-30, 0],
	
		// use the built-in fadeIn/fadeOut effect
		effect: "fade"
		// custom opacity setting
		//opacity: 0.9
	});
	
	/****
	CONTATO
	****/	
	$('#frm-contato input, #frm-contato textarea').corner('all');
	$('#frm-contato input, #frm-contato textarea').focus(
		function(){	
			$(this).addClass('activeInput');
			lastInputValue = $(this).val();
			$(this).val('');
		}
	).blur(
		function(){
			$(this).removeClass('activeInput');
			var va = $(this).val();
			if(va == lastInputValue || va == ''){
				$(this).val(lastInputValue);
			}
		}
	);
	
	$("#frm-contato input, #frm-contato textarea").tooltip({
	
		// place tooltip on the right edge
		position: "center right",
	
		// a little tweaking of the position
		offset: [-2, 10],
	
		// use the built-in fadeIn/fadeOut effect
		effect: "fade",
	
		// custom opacity setting
		opacity: 0.7,
		
		// CSS class name for the generated tooltip element. 
		tipClass: 'frm-tooltip'
	});
	
	jQuery.validator.addMethod("nome", function(value, element, params){ 
	//	alert(element.id+" :"+element.name+" "+value);
			switch(element.id){
				case 'fr-nome':
					return (value != 'Nome');
				break;
				case 'fr-email':
					return (value != 'Email');
				break;
				case 'fr-mensagem':
					return (value != 'Mensagem');
				break; 
			}
			return false;
		}, 
		jQuery.format("Please enter the correct value for ")
	);
		
	
	
	$("#frm-contato").validate(
	{
		errorLabelContainer: $("div.errors"),
		wrapper: 'p',
		rules: {
			Nome: {required: true, nome: true},
			Email: {required: true, email: true, nome: true},
			Mensagem: {required: true, nome: true}
		},
		messages: {
			Nome: "Qual o seu nome?",
			Email: {required: "Qual seu e-mail?", email: "Informe-nos um email válido"},
			Mensagem: "Diga-nos algo!"
		},
		submitHandler: function(form) {
			$('div.errors').html('<p align="center"><img src="imagens/ajax-loader.gif" /><br />Aguarde</p>').show('fast');
			$(form).ajaxSubmit({
				resetForm: true,
				dataType:  'json',
				beforeSubtmit: function(){
				},
				error: function(){
					$('div.errors').html('<p class="error">Falha ao enviar a mensagem, tente novamente.</p>');
				},
				success: function(data, textStatus, XMLHttpRequest){
					var cl = (data.act == true)? 'state-ok':'error';
					var html = '<p class="'+cl+'">'+data.msg+'</p>';
					$('div.errors').html(html);
				}
			});
		}
	});	

	
});
