/*
* file: script.js
* author: Gerson Thiago| Front-End Engineer - gersonthiago.com
*/


(function($){

	var mainController = {
	
		header : {
			topo: $('header.top nav'),
			topoSpan: $('header.top span'),
			box: $('div.box'),
			titNoticia: $('.titNoticia'),
			formContato: $('#formContato'),
			href:location.href, 
			btTwitter:$('ul.boxShare a.shareTwitter'),
			btFb:$('ul.boxShare a.shareFb')
		},
		init: function(){
			
			
			mainController.header.topo.append('<span></span>'); 
			
			mainController.header.box.last().css('border','none');
			
			/* share */
			$('a.btShare').bind('click',function(e){
				e.preventDefault();
				if($(this).hasClass('active')){
					mainController.header.btTwitter.animate({top:'-70px'}, 1400, 'easeInOutElastic');
					setTimeout(function(){
						mainController.header.btFb.animate({top:'-70px'}, 1400, 'easeInOutElastic', function(){
							$('a.btShare').removeClass('active');
						});
					}, 500);
				} else {
					mainController.header.btTwitter.animate({top:'0px'}, 1300, 'easeInOutElastic');
					setTimeout(function(){
						mainController.header.btFb.animate({top:'0px'}, 1300, 'easeInOutElastic', function(){
							$('a.btShare').addClass('active');
						});
					}, 500);
				}
				
			});
			
			
			/* hover menu */
			if(mainController.header.href.search('a-netuno.php')>0){ $('.nav-netuno').css('background-position','0 0');} 
			else if(mainController.header.href.search('estrutura.php')>0){ $('.nav-estrutura').css('background-position','-186px 0');} 
			else if(mainController.header.href.search('produtos.php')>0){ $('.nav-produtos').css('background-position','-280px 0'); } 
			else if(mainController.header.href.search('novidades.php')>0){ $('.nav-novidades').css('background-position','-376px 0'); } 
			else if(mainController.header.href.search('loja.php')>0){ $('.nav-loja').css('background-position','-483px 0'); } 
			else if(mainController.header.href.search('contato.php')>0){ $('.nav-contato').css('background-position','-541px 0');}
			
			/* noticia */
			mainController.header.titNoticia.bind('click', function(e){
				e.preventDefault();
				$(this).next('p').fadeOut();
				$(this).next().next('div.scroll').slideDown('300', function(){ $(this).parent().find('.scroll').jScrollPane({showArrows:true,dragMinHeight:'37px'}); });
			});
			
			/* contato */
			mainController.header.formContato.bind('submit', function(e){
				
				e.preventDefault();
				if($(this).find('input[type=submit]').hasClass('enviado')){} else {
					
					var nome = $(this).children('#nome').val();
					var email = $(this).children('#email').val();
					var setor = $('#campo_setor').val();
					var telefone = $(this).children('#telefone').val();
					var msg = $(this).children('#msg').val();
					
					
					if(nome==" " || nome.length==0){
						
						$(this).children('#nome').css({'background':'#ff7e7e', 'color':'#fff'}).focus();
						return false;
						
					} else if(email==" " || email.length<5 || email.indexOf("@")<0){
						
						$(this).children('#nome').css({'background':'#fff', 'color':'#000'});
						$(this).children('#email').css({'background':'#ff7e7e', 'color':'#fff'}).focus();
						return false;
						
					} else if(telefone==" " || telefone.length==0){
						
						$(this).children('#nome, #email').css({'background':'#fff', 'color':'#000'});
						$(this).children('#telefone').css({'background':'#ff7e7e', 'color':'#fff'}).focus();
						return false;
						
					} else if(msg==" " || msg.length==0){
						
						$(this).children('#nome, #email, #telefone').css({'background':'#fff', 'color':'#000'});
						$(this).children('#msg').css({'background':'#ff7e7e', 'color':'#fff'}).focus();
						return false;
						
					} else {
						
						/* enviando email */
						$(this).children('#nome, #email, #telefone, #msg').css({'background':'#fff', 'color':'#000'});
						$(this).find('.btEnviar').val('Enviando email...').css({'background':'#e37911'});
						
						$.ajax({
							type:"POST",
							url: "../includes/php/email.php",
							data: "nome="+nome+"&email="+email+"&setor="+setor+"&telefone="+telefone+"&msg="+msg,
							success: function(data){
								if (data=="0"){
									$('.btEnviar').val('Email Enviado').css({'background':'#379d10'}).addClass('enviado');
								} else if (data=="1"){
									$('.btEnviar').val('Ocorreu algum erro.').css('background','#ff0000');
								} else {
									$('.btEnviar').val('Ocorreu algum erro.').css('background','#ff0000');
								}
							}
						});
					
					
					}
					
					
					
				}
				
			});
			
			
			
		}
	
	}
	
	$(document).ready(function(){
		
			mainController.init();
			
			var setaDefault = function(){
				$('header.top span').stop().animate({ left:'198px' }, 300);
			}
			
			$('header.top nav ul li:eq(0)').hover(function(){
				$('header.top span').stop().animate({ left:'65px' }, 300);
			}, function(){ setaDefault(); });
			
			$('.maskImage').append('<span></span>');
			$('#news article:eq(0)').addClass('mNewsL'); $('#news article:eq(1)').addClass('mNews'); $('#news article:eq(2)').addClass('mNewsR');
			
			
			$('article.noticia:eq(0), article.noticia:eq(1), article.noticia:eq(2)').css('padding-top','0');
			$('article.noticia:eq(0), article.noticia:eq(3)').addClass('newLeft');
			$('article.noticia:eq(1), article.noticia:eq(4)').addClass('newMeio');
			$('article.noticia:eq(2), article.noticia:eq(5)').addClass('newRight');
		
	});

	
	
})(jQuery);
