/* check for IE versions */
var doc = document.documentElement;
doc.setAttribute('data-useragent',  navigator.userAgent);
doc.setAttribute('data-platform', navigator.platform );

/* User agents:
  IE 10 == Mozilla/5.0 (compatible; MSIE 10. ...
  IE  9 == Mozilla/5.0 (compatible; MSIE 9. ...
  IE  8 == Mozilla/5.0 (compatible; MSIE 8. ...
  IE  8 == Mozilla/4.0 (compatible; MSIE 8. ...
  IE  7 == Mozilla/5.0 (compatible; MSIE 7. ...
  IE  7 == Mozilla/4.0 (compatible; MSIE 7. ...
  IE  6 == Mozilla/5.0 (compatible; MSIE 6. ...
  IE  6 == Mozilla/4.0 (compatible; MSIE 6. ...
*/

/* other stuff */
var I = {dom : {},fn: {} };
var ie6 = /MSIE 6/i.test(navigator.userAgent);

$(function(){

  $(".main_menu .childs").dropdownize();
  
  if ($.fn.flexipage != undefined) {
	// flexipage gives javascript errors at last item (Uncaught Error: Syntax error, unrecognized expression: .pager .next)
	// TODO: fix or replace script
    $('.mod_brand_carousel .viewport ul').flexipage({
       perpage: 1,
       carousel: true,
       speed: 800,
       pager_selector : '.pager',
       counter : false
    });
    
    $('.mod_highlighted_news .viewport ul').flexipage({
       perpage: 1,
       carousel: true,
       pager_selector : '.pager',
       navigation : true,
       speed: 400,
       delay: 2000
    });
    
  };
  
 
  
  var desplegables = $('.desplegable');
  
  if (desplegables.length) {
    
    desplegables.find('.inner').hide();
    
    desplegables.find('h3 a').click(function(e) {
      e.preventDefault();
      $(this).parents('.desplegable').find('.inner').slideToggle();
    });
    
    
    
    
  }
  
  
  $('.overlayfield').overlayfield();
  
  if (ie6) {
    $('.btn').hover(function() {
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
    });
    
  }
   
});



$(document).ready(function(){
	$('.ui-breadcrumb ul li a').removeClass("ui-icon");
	$('.ui-breadcrumb ul li a').removeClass("ui-icon-home");

	$('#loginForm\\:username,#loginForm\\:password').val("");
	/*
	 * Função utilizado para apresentar o placeholder nas páginas na qual o browsers não suportam, ex: MSIE 8 
	 * no formulário de login
	 * */
	//PrimeFaces.showWatermarks();
});

function enableWatermarksIfNecessary() {
	var $watermarkFields = $(".watermark");
	if ($watermarkFields.length>0) {
		PrimeFaces.showWatermarks();
	}
}

window.onload = function() {
	enableWatermarksIfNecessary();
}

function disableButtonWithoutText(searchButton, searchField){
	$(function() {
			$(searchButton).click(
				function(){
					if($(searchField).val() === '') {
						return false;
					}
				}
			)
			})
}

function alfaMainMenu(x) {
    x.classList.toggle("change");
    $(".alfaMainMenu").toggleClass("open");
    $(".alfaMainMenuContainer").toggleClass("open");
    
    var alturaTotal = $('.alfaContents').height();
    $(".alfaMainMenuContainer.open").css("height", alturaTotal);
}


function redirectTo(seccao){
	if (seccao) {
		if (seccao === 'company') {companyRedirect();}
		if (seccao === 'fenomenos') {fenomenosRedirect();}
		if (seccao === 'profile') {profileRedirect();}
	}
	return false;
}	


$(window).scroll(function () {
	if ($(window).scrollTop() > 520) {
    	$('.alfaWarningsPanel').addClass('navbar-fixed');
	}
  	if ($(window).scrollTop() < 521) {
  		$('.alfaWarningsPanel').removeClass('navbar-fixed');
  	}
});

