/** Abrir links com o rel="external" ou rel="download" em outra janela com tageamento no Analytics **/
$("a[rel~=external]").attr("target","_blank").click(function(){
	_gaq.push(['_trackPageview', "/link-externo/" + $(this).attr("href").replace("http://","")]);
});
$("a[rel~=download]").attr("target","_blank").click(function(){
	_gaq.push(['_trackPageview', "/download/" + $(this).attr("href")]);
});
/* Tageamento no Analytics de links de email */
$("a[href^='mailto:']").click(function(){
	_gaq.push(['_trackPageview', "/email/" + $(this).attr("href").replace("mailto:","")]);
});

/* Script para troca do texto de mudança de lingua */
$('.idioma li').has('a[lang=en]').hover(function(){
	$('.idioma span').hide();
	$('.idioma span[lang=en]').show();
},function(){
	$('.idioma span').show();
	$('.idioma span[lang=en]').hide();
});

/* Script para simular a função do placeholder nos inputs */
$('.ie [placeholder]').each(function () {
	$(this).val($(this).attr('placeholder'));
	$(this).focus(function () {
		if ($(this).val() == $(this).attr('placeholder')) {
			$(this).val('');
		}
	});
	$(this).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('placeholder'));
		}
	});
});

/* validação do formulário de contato */
$(function(){
	$("#nome, #empresa, #assunto, #mensagem").validate({
		errorClass: "err",
		valid: function(val){
			return val != "" && !val.match(/^\s+$/);
		}
	});
	$("#email").validate({
		errorClass: "err",
		valid: function(val){
			return val.match(/^[a-zA-Z0-9._%+-]+\@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
		}
	});
	$('.contato form').submit(function(){
		$('#nome, #empresa, #email, #assunto, #mensagem').focus().blur();
		if ($('.err',this).length > 0 ) {
			$('.msg').show();
			return false;
		}
		return true;
	});
});

/* Carrossel interna */
var timeoutHandle;
function proximaFrase() {
	$('.index .jcarousel-next').click();
}
function proxFundoHome() {
	var num = parseInt( $('#header').css('background-image').replace(/.*bg-header/,'').replace(/\.jpg.*/,'') );
	num = (num+1 > 3) ? 1 : num+1;
	$('#header').css('background-image','url(img/bg-header'+num+'.jpg)');
	window.clearTimeout(timeoutHandle);
	timeoutHandle = window.setTimeout(proximaFrase,10000);
}
function prevFundoHome() {
	var num = parseInt( $('#header').css('background-image').replace(/.*bg-header/,'').replace(/\.jpg.*/,'') );
	num = (num-1 < 1) ? 3 : num-1;
	$('#header').css('background-image','url(img/bg-header'+num+'.jpg)');
	window.clearTimeout(timeoutHandle);
	timeoutHandle = window.setTimeout(proximaFrase,10000);
}

$('.destaque').jcarousel({
	wrap: 'circular',
	scroll: 1,
	animation: 'slow'
});
timeoutHandle = window.setTimeout(proximaFrase,10000);
$('.index .jcarousel-next').bind('click', proxFundoHome);
$('.index .jcarousel-prev').bind('click', prevFundoHome);


