/** 
 * -------------------------------------- 
 * KRIACAO
 * @file: GENERIC JS FUNCTIONS
 * @author: João
 * @date: 09-03-2011
 *
 * --------------------------------------
*/

$(function() {
	$.datepick.setDefaults( $.datepick.regional[ "" ] );
	$( "#admissaoPedido" ).datepick( $.datepick.regional[ "pt" ] );
});



$(function() {
	$('#admissaoPedido').datepick();
	$('#nascimentoPedido').datepick();
});


/** 
VALIDAÇÃO DO FORMULÁRIO DE CONTACTOS
*/
	function validaFormularioContacto(){
		var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if($('#nomeContacto')[0].value == ''){
			alert("campo nome inválido!");
			return;
		}
		
		if(email_reg.test($('#emailContacto').val()) == false){
			alert("campo email inválido!");
			return;
		}
		
		if(isNaN($('#telefoneContacto')[0].value) || $('#telefoneContacto')[0].value == ''){
			alert("campo telefone inválido!");
			return;
		}

		$('#formularioContacto')[0].submit(); return false;

	}
/** 
VALIDAÇÃO DO FORMULÁRIO DE CONTACTOS
*/

/** 
VALIDAÇÃO DO FORMULÁRIO DE CARREIRAS
*/
	function validaFormularioCarreiras(){
		var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if($('#nomeCarreira')[0].value == ''){
			alert("campo nome inválido!");
			return;
		}
		
		if(email_reg.test($('#emailCarreira').val()) == false){
			alert("campo email inválido!");
			return;
		}
		
		if(isNaN($('#telefoneCarreira')[0].value) || $('#telefoneCarreira')[0].value == ''){
			alert("campo telefone inválido!");
			return;
		}

		$('#formularioCarreira')[0].submit(); return false;

	}
/** 
VALIDAÇÃO DO FORMULÁRIO DE CARREIRAS
*/

/** 
VALIDAÇÃO DO FORMULÁRIO DE CONSULTAS
*/
	function validaFormularioConsulta(){

		var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if($('#nomePedido')[0].value == ''){
			alert("campo nome inválido!");
			return;
		}
		
		if(isNaN($('#telefonePedido')[0].value) || $('#telefonePedido')[0].value == '' && email_reg.test($('#emailPedido').val()) == false){
			alert("campo telefone ou email inválido!");
			return;
		}
		
		if($('#empresaPedido')[0].value == '' && $('#contratoPedido')[0].value == ''){
			alert("campo empresa ou contrato inválido!");
			return;
		}

		$('#formularioConsulta')[0].submit(); return false;

	}
/** 
VALIDAÇÃO DO FORMULÁRIO DE CONSULTAS
*/

/** 
VALIDAÇÃO DO FORMULÁRIO DE CONTACTOS
*/
	function validaFormularioProposta(){
		var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if($('#nomeProposta')[0].value == ''){
			alert("campo nome inválido!");
			return;
		}
		
		if(email_reg.test($('#emailProposta').val()) == false){
			alert("campo email inválido!");
			return;
		}
		
		if(isNaN($('#telefoneProposta')[0].value) || $('#telefoneProposta')[0].value == ''){
			alert("campo telefone inválido!");
			return;
		}

		$('#formularioProposta')[0].submit(); return false;

	}
/** 
VALIDAÇÃO DO FORMULÁRIO DE CONTACTOS
*/



/** 
PAGINAÇÃO
*/
	// This is a very simple demo that shows how a range of elements can
	// be paginated.
	// The elements that will be displayed are in a hidden DIV and are
	// cloned for display. The elements are static, there are no Ajax 
	// calls involved.

	/**
	 * Callback function that displays the content.
	 *
	 * Gets called every time the user clicks on a pagination link.
	 *
	 * @param {int} page_index New Page index
	 * @param {jQuery} jq the container with the pagination links as a jQuery object
	 */
	function pageselectCallback(page_index, jq){
		var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
		$('#Searchresult').empty().append(new_content);
		return false;
	}
   
	/** 
	 * Initialisation function for pagination
	 */
	function initPagination() {
		// count entries inside the hidden content
		var num_entries = jQuery('#hiddenresult div.result').length;
		// Create content inside pagination element
		$(".areaPaginacao").pagination(num_entries, {
			callback: pageselectCallback,
			items_per_page:1 // Show only one item per page
		});
	 }
	
	// When document is ready, initialize pagination
	$(document).ready(function(){      
		initPagination();
	});
/** 
PAGINAÇÃO
*/



jQuery(function () {

	jQuery('.subMenuItemCont').each(function () {
		var topo = jQuery(this).find('.subMenuItemTopo');
		var bottom = jQuery(this).find('.subMenuItemBottom');
		var menuTxt = jQuery(this).find('.subMenuItem');	        
	
		jQuery(this).hover(
			function () {
				topo.addClass("subMenuItemTopoSelect");
				bottom.addClass("subMenuItemBottomSelect");
				menuTxt.addClass("subMenuItemSelect");
			},
			function () {
				topo.removeClass("subMenuItemTopoSelect");
				bottom.removeClass("subMenuItemBottomSelect");
				menuTxt.removeClass("subMenuItemSelect");
			}
		);
	});
	

	jQuery('.menuItemCont').each(function () {
		var left = jQuery(this).find('.menuItemLeft');
		var right = jQuery(this).find('.menuItemRight');
		var menuTxt = jQuery(this).find('.menuItemTxt');	        
	
		jQuery(this).hover(
			function () {
				left.addClass("menuItemLeftSelect");
				right.addClass("menuItemRightSelect");
				menuTxt.addClass("menuItemTxtSelect");
			},
			function () {
				left.removeClass("menuItemLeftSelect");
				right.removeClass("menuItemRightSelect");
				menuTxt.removeClass("menuItemTxtSelect");
			}
		);
	});

	

	jQuery('.menuFooterItemCont').each(function () {
		var left = jQuery(this).find('.menuFooterItemLeft');
		var right = jQuery(this).find('.menuFooterItemRight');
		var menuTxt = jQuery(this).find('.menuFooterItemTxt');	        
	
		jQuery(this).hover(
			function () {
				left.addClass("menuFooterItemLeftSelect");
				right.addClass("menuFooterItemRightSelect");
				menuTxt.addClass("menuFooterItemTxtSelect");
			},
			function () {
				left.removeClass("menuFooterItemLeftSelect");
				right.removeClass("menuFooterItemRightSelect");
				menuTxt.removeClass("menuFooterItemTxtSelect");
			}
		);
	});
	
	
	jQuery('.menuItemEspecial').each(function () {
		jQuery(this).hover(
			function () {
				jQuery(this).addClass("menuItemEspecialSelect");
			},
			function () {
				jQuery(this).removeClass("menuItemEspecialSelect");  			   
			}
		)
	});



	jQuery('.eventoBtnVoltar').each(function () {
		
		jQuery(this).hover(
			function () {
				jQuery(this).addClass("eventoBtnVoltarSelect");
			},
			function () {
				jQuery(this).removeClass("eventoBtnVoltarSelect");
			}
		);
	});
	
	
	jQuery('.destaqueItemTitulo').each(function () {
		
		jQuery(this).hover(
			function () {
				jQuery(this).addClass("destaqueItemTituloSelect");
			},
			function () {
				jQuery(this).removeClass("destaqueItemTituloSelect");
			}
		);
	});



/** 
MUDAR AS FOTOS NOS EVENTOS
*/
	var total = jQuery('.eventoImgNum').size();

	var imgs = jQuery('.eventoImg  img');
	imgs.not(jQuery(imgs.get(0))).css('opacity', 0);
	
	var numero = jQuery('.eventoImgNum');
	
	var numSelectInicio = jQuery(numero.get(0));
	numero.not(numSelectInicio).removeClass('eventoImgNumSelect');
	numSelectInicio.addClass('eventoImgNumSelect');
	
	jQuery('.eventoImgNum').click(function() {
		
		var index = numero.index(jQuery(this));				
		var img = jQuery(imgs.get(index));
		var numSelect = jQuery(numero.get(index));				
		
		imgs.not(img).stop().animate({
			opacity: 0
		}, 300, 'swing');
		
		img.stop().animate({
			opacity: 1
		}, 500, 'swing');
		
		numero.not(numSelect).removeClass('eventoImgNumSelect');
		numSelect.addClass('eventoImgNumSelect');			
	});

/** 
MUDAR AS FOTOS NOS EVENTOS
*/	



/** 
MUDAR O TEXTO DAS FAQS
*/		
	var destaques = jQuery('.detalheFaqContainer  .detalheFaqItem');
	destaques.not(jQuery(destaques.get(0))).css('display', 'none');
	
	var numeros = jQuery('.linkItem');
	
	jQuery('.linkItem').click(function() {
		
		var index = numeros.index(jQuery(this));
		var dest = jQuery(destaques.get(index));				
		var img = jQuery(imgs.get(index));
		var numSelect = jQuery(numeros.get(index));
		
		destaques.not(dest).css('display','none');
		dest.css('display','block');							
	});	
/** 
MUDAR O TEXTO DAS FAQS
*/	
	


/** 
FAZER SCROLL ÀS FAQS
*/	
	var index = 0;
	
	var num = jQuery('.linkItem').size() - 1;
	
	jQuery('.scrollBtnUp').css('cursor', 'default');
	jQuery('.scrollBtnUp').css('background-image', 'none');
	
	jQuery('.logotipo').each(function () {
		if(num <= 0)
		{
			jQuery('.scrollBtnDown').hide();
			jQuery('.scrollBtnUp').css('cursor', 'default');
			jQuery('.scrollBtnUp').css('background-image', 'none');
		}
	});
	
	jQuery('.scrollBtnDown').click(function() {
		if(index != num)
		{
			index = index + 1;
		}
		if(index == num)
		{
			jQuery('.scrollBtnDown').hide();
		}
		if(index > 0)
		{
			jQuery('.scrollBtnUp').css('cursor', 'pointer');
			jQuery('.scrollBtnUp').css('background-image', 'url(/image/setaAzulUp.png)');
		}
		
		var value = index * (-25);
		jQuery('.faqScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
		
	jQuery('.scrollBtnUp').click(function() {
		if(index != 0)
		{
			index = index - 1;
		}
		if(index == num-1)
		{
			jQuery('.scrollBtnDown').show();
		}
		if(index == 0)
		{
			jQuery('.scrollBtnUp').css('cursor', 'default');
			jQuery('.scrollBtnUp').css('background-image', 'none');
		}
		
		var value = index * (-25);
		jQuery('.faqScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
/** 
FAZER SCROLL ÀS FAQS
*/


/** 
FAZER SCROLL ÀS OPORTUNIDADES DE CARREIRA
*/	
	var index = 0;
	
	var num = jQuery('.carreirasItem').size() - 1;
	
	jQuery('.carreirasItemBtnUp').css('cursor', 'default');
	jQuery('.carreirasItemBtnUp').css('background-image', 'none');
	
	jQuery('.logotipo').each(function () {
		if(num <= 0)
		{
			jQuery('.carreirasItemBtnDown').hide();
			jQuery('.carreirasItemBtnUp').css('cursor', 'default');
			jQuery('.carreirasItemBtnUp').css('background-image', 'none');
		}
	});
	
	jQuery('.carreirasItemBtnDown').click(function() {
		if(index != num)
		{
			index = index + 1;
		}
		if(index == num)
		{
			jQuery('.carreirasItemBtnDown').hide();
		}
		if(index > 0)
		{
			jQuery('.carreirasItemBtnUp').css('cursor', 'pointer');
			jQuery('.carreirasItemBtnUp').css('background-image', 'url(/image/setaAzulUpV2.png)');
		}
		
		var value = index * (-116);
		jQuery('.carreirasScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
		
	jQuery('.carreirasItemBtnUp').click(function() {
		if(index != 0)
		{
			index = index - 1;
		}
		if(index == num-1)
		{
			jQuery('.carreirasItemBtnDown').show();
		}
		if(index == 0)
		{
			jQuery('.carreirasItemBtnUp').css('cursor', 'default');
			jQuery('.carreirasItemBtnUp').css('background-image', 'none');
		}
		
		var value = index * (-116);
		jQuery('.carreirasScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
/** 
FAZER SCROLL ÀS OPORTUNIDADES DE CARREIRA
*/


/** 
FAZER SCROLL AOS DESTAQUES DOS EVENTOS
*/	
	var indexEvento = 0;
	
	var numEvento = jQuery('.destaqueItemEvento').size() - 1;
	
	jQuery('#eventosItemBtnUp').css('cursor', 'default');
	jQuery('#eventosItemBtnUp').css('background-image', 'none');
	
	jQuery('.logotipo').each(function () {
		if(numEvento <= 0)
		{
			jQuery('#eventosItemBtnDown').hide();
			jQuery('#eventosItemBtnUp').css('cursor', 'default');
			jQuery('#eventosItemBtnUp').css('background-image', 'none');
		}
	});
	
	jQuery('#eventosItemBtnDown').click(function() {
		if(indexEvento != numEvento)
		{
			indexEvento = indexEvento + 1;
		}
		if(indexEvento == numEvento)
		{
			jQuery('#eventosItemBtnDown').hide();
		}
		if(indexEvento > 0)
		{
			jQuery('#eventosItemBtnUp').css('cursor', 'pointer');
			jQuery('#eventosItemBtnUp').css('background-image', 'url(/image/setaAzulUp.png)');
		}
		
		var value = indexEvento * (-51);
		jQuery('.destaqueEventoScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
		
	jQuery('#eventosItemBtnUp').click(function() {
		if(indexEvento != 0)
		{
			indexEvento = indexEvento - 1;
		}
		if(indexEvento == numEvento-1)
		{
			jQuery('#eventosItemBtnDown').show();
		}
		if(indexEvento == 0)
		{
			jQuery('#eventosItemBtnUp').css('cursor', 'default');
			jQuery('#eventosItemBtnUp').css('background-image', 'none');
		}
		
		var value = indexEvento * (-51);
		jQuery('.destaqueEventoScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
/** 
FAZER SCROLL AOS DESTAQUES DOS EVENTOS
*/



/** 
FAZER SCROLL AOS DESTAQUES DAS NOTÍCIAS
*/	
	var indexNoticias = 0;
	
	var numNoticias = jQuery('.destaqueItem').size() - 3;
	
	jQuery('#noticiasItemBtnUp').css('cursor', 'default');
	jQuery('#noticiasItemBtnUp').css('background-image', 'none');
	
	jQuery('.logotipo').each(function () {
		if(numNoticias <= 0)
		{
			jQuery('#noticiasItemBtnDown').hide();
			jQuery('#noticiasItemBtnUp').css('cursor', 'default');
			jQuery('#noticiasItemBtnUp').css('background-image', 'none');
		}
	});
	
	jQuery('#noticiasItemBtnDown').click(function() {
		if(indexNoticias != numNoticias)
		{
			indexNoticias = indexNoticias + 1;
		}
		if(indexNoticias == numNoticias)
		{
			jQuery('#noticiasItemBtnDown').hide();
		}
		if(indexNoticias > 0)
		{
			jQuery('#noticiasItemBtnUp').css('cursor', 'pointer');
			jQuery('#noticiasItemBtnUp').css('background-image', 'url(/image/setaAzulUp.png)');
		}
		
		var value = indexNoticias * (-51);
		jQuery('.destaqueNoticiasScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
		
	jQuery('#noticiasItemBtnUp').click(function() {
		if(indexNoticias != 0)
		{
			indexNoticias = indexNoticias - 1;
		}
		if(indexNoticias == numNoticias-1)
		{
			jQuery('#noticiasItemBtnDown').show();
		}
		if(indexNoticias == 0)
		{
			jQuery('#noticiasItemBtnUp').css('cursor', 'default');
			jQuery('#noticiasItemBtnUp').css('background-image', 'none');
		}
		
		var value = indexNoticias * (-51);
		jQuery('.destaqueNoticiasScroller').stop().animate({
			top: value
		});
	}, 350, jQuery.easing.def);
/** 
FAZER SCROLL AOS DESTAQUES DAS NOTÍCIAS
*/	





	jQuery(function() {
		var indexDest = 0;
		
		var numDest = jQuery('.destaqueHomeItem').size() - 1;
		
		jQuery('.btnDestaqueHomeLeft').css('cursor', 'default');
		jQuery('.btnDestaqueHomeLeft').css('background-image', 'none');
		
		jQuery('.logotipo').each(function () {
			if(numDest <= 0)
			{
				jQuery('.btnDestaqueHomeRight').hide();
				jQuery('.btnDestaqueHomeLeft').css('cursor', 'default');
				jQuery('.btnDestaqueHomeLeft').css('background-image', 'none');
			}
		});


		jQuery('.btnDestaqueHomeRight').click(function() {
			if(indexDest != numDest)
			{
				indexDest = indexDest + 1;
			}
			if(indexDest == numDest)
			{
				jQuery('.btnDestaqueHomeRight').hide();
			}
			if(indexDest > 0)
			{
				jQuery('.btnDestaqueHomeLeft').css('cursor', 'pointer');
				jQuery('.btnDestaqueHomeLeft').css('background-image', 'url(/image/setaLeft.png)');
			}
			
			var valueDest = indexDest * (-630);
			jQuery('.destaqueHomeScroller').stop().animate({
				left: valueDest
			});
		}, 350, jQuery.easing.def);
			
		jQuery('.btnDestaqueHomeLeft').click(function() {
			if(indexDest != 0)
			{
				indexDest = indexDest - 1;
			}
			if(indexDest == numDest-1)
			{
				jQuery('.btnDestaqueHomeRight').show();
			}
			if(indexDest == 0)
			{
				jQuery('.btnDestaqueHomeLeft').css('cursor', 'default');
				jQuery('.btnDestaqueHomeLeft').css('background-image', 'none');
			}
			
			var valueDest = indexDest * (-630);
			jQuery('.destaqueHomeScroller').stop().animate({
				left: valueDest
			});
		}, 350, jQuery.easing.def);


		var controlo = 0;
		jQuery('.logotipo').everyTime('5s', function() {
			
			if(indexDest != numDest)
			{
				indexDest = indexDest + 1;
			}
			if(controlo == 1)
			{
				controlo = 0;
				indexDest = 0;
				jQuery('.btnDestaqueHomeRight').show();
				jQuery('.btnDestaqueHomeLeft').css('cursor', 'default');
				jQuery('.btnDestaqueHomeLeft').css('background-image', 'none');
			}
			if(indexDest == numDest)
			{
				controlo = 1;
				jQuery('.btnDestaqueHomeRight').hide();
			}
			if(indexDest > 0)
			{
				jQuery('.btnDestaqueHomeLeft').css('cursor', 'pointer');
				jQuery('.btnDestaqueHomeLeft').css('background-image', 'url(/image/setaLeft.png)');
			}
			
			var valueDest = indexDest * (-630);
			jQuery('.destaqueHomeScroller').stop().animate({
				left: valueDest
			});
		}, 350, jQuery.easing.def);

		
	});
});
