/*----- Função que gera os submenus -----*/

function alterarPeriodicidade(idgruposplanos,val) {
	$('#resultPlanos').load('/exec.php?modulo=planos/atualizaPlanos&idgruposplanos='+idgruposplanos+'&val='+val);
}

$(function(){

	function megaHoverOver(){
		$(this).find(".dropDownMenu").stop().fadeTo(1, 1).show();
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				$(this).find("ul").each(function() {
					rowWidth += $(this).width();
				});
			};
		})(jQuery); 

		if ( $(this).find(".row").length > 0 ) {

			var biggestRow = 0;	

			$(this).find(".row").each(function() {
				$(this).calcSubWidth();

				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});

			$(this).find(".dropDownMenu").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0', 'border':'none'});

		} else {

			$(this).calcSubWidth();
			$(this).find(".dropDownMenu").css({'width' : rowWidth});

		}
	}

	function megaHoverOut(){
	  $(this).find(".dropDownMenu").stop().fadeTo(1, 0, function() {
		  $(this).hide();
	  });
	}



	//Set custom configurations
	var config = {
		 sensitivity: 2, 
		 interval: 0, 
		 over: megaHoverOver,
		 timeout: 0,
		 out: megaHoverOut
	};

	$("#menu li .dropDownMenu").css({'opacity':'0'});
	$("#menu li").hoverIntent(config);
	
$("#menu > li > a").hover(fnOverMenu, fnOutMenu);
	
	cssMenuOver = {background: "#fff", border: "1px solid #5d5d5d", color: "#000", borderRadius: "5px 5px 0px 0px"}
	cssMenuOut = {background: "transparent", border: "1px solid transparent", color: "#fff"}
	
	function fnOverMenu () {
		menuSelected = $(this);
		$(this).css(cssMenuOver);
			
		$(".dropDownMenu").hover(fnDropDown, fnDropDownOut)
	}
	
	function fnDropDown () {
		$(menuSelected).css(cssMenuOver);
	}
	
	function fnDropDownOut (){
		$(menuSelected).css(cssMenuOut);
	}
		
	function fnOutMenu () {
		$(this).css(cssMenuOut);		
	}

});



/*------ Painel do Cliente ------*/

$('.painelCliente_conta').click(function(){
	$('.painelCliente_acesso').stop().animate({top: "0px"}, 300);
});

$('.over_painel').click(function(){
	$('.painelCliente_acesso').animate({top: "-140px"}, 300);
});


/*----- Twitter -----*/

$("#twitter").tweet({
	username: "hostdesk", 
	callback: function() { 
		$('.tweet_list').cycle({
			speed: 'slow', 
			timeout: 8000
		});
	}
});		

$("#button").button();


/*----- Ajusta min-heigh do body de acordo com resolucao -----*/

$("body").css("min-height", window.innerHeight);


/*----- jCarousel -----*/

$(function() {
	$('.gerarBox').jcarousel({
		scroll: 5,
		visible: 5,
		animation: "slow"
	});
	
	$('.jcarousel-skin-aplicativos').jcarousel({
		scroll: 1,
		visible: 4,
		animation: "slow"
	});
	
	$('.jcarousel-skin-duvidasTexto').jcarousel({
		vertical: true,
		scroll: 1,
		visible: 4,
		animation: "slow",
		buttonNextHTML: "<div><span class='duvidasNextButton duvidasButton'></span></div>",
		buttonPrevHTML: "<div><span class='duvidasPrevButton duvidasButton'></span></div>",
	});	
	
	$('.tireDuvidasVideo').jcarousel({
		vertical: true,
		scroll: 1,
		visible: 2,
		animation: "slow",
		buttonNextHTML: "<div><span class='duvidasNextButton duvidasButton'></span></div>",
		buttonPrevHTML: "<div><span class='duvidasPrevButton duvidasButton'></span></div>",
	});
	
});


/*---- Adiciona PlaceHolder aos Inputs/Textareas  ----*/

$(function(){
	if(!Modernizr.input.placeholder){
		$("input[placeholder], textarea[placeholder]").each(function(){
			this.value= $(this).attr('placeholder');
			$(this).focus(removerPlaceholder);
			$(this).blur(devolverPlaceholder);
		});
	}
	
	function removerPlaceholder() {
		if ( this.value == $(this).attr('placeholder') )
			this.value= "";
	}

	function devolverPlaceholder() {
		if ( this.value == "" )
			this.value= $(this).attr('placeholder');
	}
});


/*---- Verifica Navegador e adiciona classe ao body  ----*/

$(function(){
		
var userAgent = navigator.userAgent.toLowerCase();
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());

// Esse navegador é uma versão do IE?
if($.browser.msie){
	$('body').addClass('browserIE'); 
	// Adicionar Versão do IE
	$('body').addClass('browserIE' + $.browser.version.substring(0,1));
}

// Esse navegador é uma versão do Chrome?
if($.browser.chrome){ 
	$('body').addClass('browserChrome'); 
	// Adicionar Versão do Chrome
	userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
	userAgent = userAgent.substring(0,1);
	$('body').addClass('browserChrome' + userAgent); 
	$.browser.safari = false;
}

// Esse navegador é uma versão do Safari?
if($.browser.safari){
	$('body').addClass('browserSafari'); 
	// Adicionar Versão do Safari
	userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
	userAgent = userAgent.substring(0,1);
	$('body').addClass('browserSafari' + userAgent);
}

// Esse navegador é uma versão do Mozilla?
if($.browser.mozilla){ 
	if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
		$('body').addClass('browserFirefox'); 
		// Adicionar Versão do Mozilla
		userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
		userAgent = userAgent.substring(0,1);
		$('body').addClass('browserFirefox' + userAgent);
	}
	else{
		$('body').addClass('browserMozilla');
	}
}

// Esse navegador é uma versão do Opera?
if($.browser.opera){
	$('body').addClass('browserOpera');
} 
		
});



/*----- Loader cycle ----*/

$(function(){


$(".loader span").hide();
$(".loader").fadeOut(1000).prev().animate({opacity: 1}, 1000);

	
});


/*------ Função de deslizar Tabela de Mais detalhes (planos) -----*/

$(function(){

	$(".maisDetalhesShow").toggle(mostrarDetalhes, esconderDetalhes);	
	
	buttonShow = $(".maisDetalhesButton").text();
	buttonHide = "Ocultar tabela de recursos";
	
	function mostrarDetalhes() {
		$(".tabelaComparativa table:first-child tr:last-child").css("border-bottom", "1px solid #fff");
		$(".tabelaComparativa table:last-child tr:first-child").css("border-top", "1px solid #ddd");
		$(".tabelaComparativaDetalhes").slideDown(1000);
		$(this).removeClass("maisDetalhesShow").addClass("maisDetalhesHide").text(buttonHide);
		console.log()
	}
	
	function esconderDetalhes() {
		$(".tabelaComparativaDetalhes").slideUp(1000);
		$(this).removeClass("maisDetalhesHide").addClass("maisDetalhesShow").text(buttonShow);
	}
	
	return false;
});

/*----- Tabs Informaçoes Técnicas - Página Planos -----*/

$(function() {
	$( "#tabsInfoTecnica" ).tabs();
});



$(function() {
		$( "#accordionLista" ).accordion();
	});

/*----- DropDown -----*/

$(function(){
	
	$(".dropDownItem").click(function(){
		$(this).find(".dropDownInfo").slideToggle();
		$(this).find(".dropDownMore").toggleClass("dropDownHide");

		if($(this).find(".dropDownMore").text() != "-") {
			$(this).find(".dropDownMore").text("-")
		}
		else {
			$(this).find(".dropDownMore").text("+")
		}
	})
	
})










