$(document).ready(function() {
	if(jQuery('.player-cartoon').html() != null) {
		jQuery('.player-cartoon').each(function(i) {
			var _self = jQuery(this);
			_self.height(_self.next('.player-text-container').height());
			_self.children().css({'position':'absolute','bottom':'-50px'});
			_self.css('margin','0 250px 0 0');
		});
	}
	if($("#fun-list").html() != undefined && $("#fun-list").html() != null){
		$(function(){
			var div = $('#fun-list'),
				ul = $('#fun-list ul'),
				ulPadding = 15;
			var divWidth = div.width();
			div.css({overflow: 'hidden'});
			var lastLi = ul.find('li:last-child');
			div.mousemove(function(e){
				var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
				var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
				div.scrollLeft(left);
			});
		});
	}

	Cufon.replace('.fonte01', {
		fontFamily: 'Helvetica',hover:true
	});
	Cufon.replace('.fonte02', {
		fontFamily: 'Univers',hover:true
	});
	Cufon.replace('.fonte03', {
		fontFamily: 'Satisfaction', hover: true
	});
	$(".developed-project").hover(function() {
			$(".img-project img", this).stop().animate({marginLeft: "300px"}, {queue:false,duration:300});
		}, function() {
			$(".img-project img", this).stop().animate({marginLeft: "0px"}, {queue:false,duration:300});
		}
	);
	$("a[rel^='prettyPhoto']").prettyPhoto({ deeplinking: false });
	
	/*$('#opacity-language').css({
		'width': $('#language li').width() + 6
	});*/
	
	
	
	//identifica o navegador e seta os parametros corretos
	var nav = navigator.userAgent;
	/*if(nav.indexOf('MSIE 9.0') >= 0){
		$("#ul2 li:eq(0), #ul2 li:eq(1)").css("padding", "13px 1px 0px 21px");
	}
	if(nav.indexOf('MSIE 8.0') >= 0){
		$("#ul2 li").css("opacity", "0.0");
		$("#ul2 li").css("padding", "5px 5px 0 20px");
	}
	if(nav.indexOf('MSIE 7.0') >= 0){
		$("#ul2 li").css("opacity", "0.0");
		$("#ul2 li").css("padding", "0px 0px 5px 0px").css("margin", "0px 0px 0p 15px");
	}
	if(nav.indexOf('AppleWebKit') >= 0){
		$("#ul2 li").css("padding", "5px 5px 0 20px");
	}
	if(nav.indexOf('Opera') >= 0){
		$("#ul2 li").css("padding", "5px 5px 0 20px");
	}*/
	/*if(nav.indexOf('MSIE 8.0') >= 0){
		$("#ul2-pt li").css("opacity", "0.0")
	}
	
	if(nav.indexOf('MSIE 7.0') >= 0){
		$("#ul2-pt li").css("opacity", "0.0");
	}*/
	
	if(nav.indexOf('MSIE 8.0') >= 0){
		$('#language li span img').css('opacity','0.5');
		$('#language li span img').live({
			mouseover:function() {
				$(this).css('opacity','1');
			},
			mouseout:function() {
				$(this).css('opacity','0.5');
			}
		});
	} else {
		$('#language li span').live({
			mouseover:function() {
				$(this).css('opacity','1');
			},
			mouseout:function() {
				$(this).css('opacity','0.5');
			}
		});
	}

	//seta a largura correta dinâmicamente de li
	var cont = 0;
	/*$(".mainMenu ul:eq(0) li").each(function(){
		var width = $(this).width() + 10;
		$(".mainMenu ul:eq(1) li:eq("+ cont +")").css("width", width);
		cont++;
	});*/
	//troca a opacidade da li
	/*$("#ul2-en li, #ul2-pt li").mouseover(function(){
		$(this).css('opacity', '0.2');
	}).mouseout(function(){
		$(this).css('opacity', '0');
	});*/
	if(nav.indexOf('Opera') >= 0){
		$(".team").css("margin-top",'-162px');
		$(".portifolio").css("margin-top",'-159px');
		$(".content #clients-container").css("margin-bottom",'30px');
		$(".the-w8s").css("margin-top",'-157px');
		$(".contact").css("margin-top",'-156px');
		$("#footer-clip").css("margin-top",'-122px');
		$(".title-container-clip").css("background-position",'22px 33px');
		$("#contact .title-container-clip").css("background-position",'15px 30px !important');
	}
	if(nav.indexOf('MSIE 7.0') >= 0){
		$('.mg-top-less60').css({'margin-top': '-86px !important;'});
	}
	/* slider */
	if($(".top-carousel").html() != undefined && $(".top-carousel").html() != null){
		$(".top-carousel").jCarouselLite({
			btnPrev: ".carousel-prev",
	        btnNext: ".carousel-next",
	        auto: 5000,
	        speed: 1000,
	        circular: true,
	        visible: 1
		});
	}
	if($(".clients-carousel").html() != undefined && $(".clients-carousel").html() != null){
		$("#clients-flags").jCarouselLite({
			auto: 800,
			speed: 1000,
			visible: 5
		});
	}
	var menu = new Menu({'id' : 'navigation',
		'opacity' : '0.3',
		'backgroundColor':'#fff',
		'borderRadius':20,
		'padding':'5px 10px 8px 10px',
		'marginLeft':-10
	});
	$(".location").live({
		mouseover: function() {
			if ($(this).hasClass("brasil")) {
				$(".tooltip-brasil img").stop().animate({marginTop: '0px'}, {queue:false,duration:300});
				
			} else {
				$(".tooltip-portugal img").stop().animate({marginTop: '0px'}, {queue:false,duration:300});
			}
		},
		mouseout: function() {
			$(".tooltip-brasil img").stop().animate({marginTop: '100px'}, {queue:false,duration:300});
			$(".tooltip-portugal img").stop().animate({marginTop: '100px'}, {queue:false,duration:300});
		}
	});
	var input = "";
	$("#nome").focusin(function(){
		if($(this).val() == "seu nome" || $(this).val() == "your name"){ input = $(this).val(); $(this).val(""); }
	}).focusout(function(){
		if($(this).val() == ""){ $(this).val(input); }
	});
	$("#email").focusin(function(){
		if($(this).val() == "seu e-mail" || $(this).val() == "your e-mail"){ input = $(this).val(); $(this).val(""); }
	}).focusout(function(){
		if($(this).val() == ""){ $(this).val(input); }
	});
	$("#telefone").focusin(function(){
		if($(this).val() == "seu telefone" || $(this).val() == "your phone"){ input = $(this).val(); $(this).val(""); }
	}).focusout(function(){
		if($(this).val() == ""){ $(this).val(input); }
	});
	$("#msg").focusin(function(){
		if($(this).val() == "sua mensagem" || $(this).val() == "your message"){
			input = $(this).val(); $(this).val("");
		}
	}).focusout(function(){
		if($(this).val() == ""){ $(this).val(input); }
	});
	
	
	/*largura das bandeiras de linguagem
	$('#opacity-language').css({
		'width': $('#language li').width() + 6 + 'px'
	});*/
});

function telefoneM(a, e) {
	var tecla=(window.event)?event.keyCode:e.which;
	var navegador = navigator.appVersion;	
	var navegador = navegador.split(" ");
	var tipo   = navegador[2];	
	if((tecla > 47 && tecla < 58) || (tecla == 8) || (tecla == 46) || (tecla == 0)) {
		var telefone = $("#"+a).val();
		if(telefone.length == 0){
			$("#"+a).bind("keypress", function(e){
				if ( tipo == "MSIE" ) var resultado = e.keyCode;
				else var resultado = e.which;

				if(resultado!=8 && resultado!=46){
					var telefone = $("#"+a).val();
					if(telefone.length == 1 && !isNaN(telefone)){
						$("#"+a).val("(" + telefone);								  
					}
					if(telefone.length == 3){
						$("#"+a).val(telefone + ") ");
					}
					if(telefone.length == 9){
						$("#"+a).val(telefone + "-");
					}			    
				}
			});															  		
		}
	}
	else{
		if ( tipo == "MSIE" ) event.returnValue = false;
		else e.preventDefault();
	}
}
function mailvalido(v){
	var mailok = true;
    //var climail = document.getElementById("email");
    var n = v.length;
    var pa = v.indexOf("@");
    var ua = v.lastIndexOf("@");
    if(pa!=ua){
        mailok = false;
    }
    else if(pa==0 || ua==n-1){    	
        mailok = false;
    }
    else{
        var charv = new Array("q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "-", "_", ".", "@");
        var dok = true;
        var uok = true;
        var domi = v.substring(pa+1, n);
        var user = v.substring(0, pa);
        //
        var din = domi.indexOf(".");
        var dinl = domi.lastIndexOf(".");
        if(din == - 1 || din == 0 || dinl == (domi.length-1)){ dok = false; }
        //
        var uip = user.indexOf(".");
        var uipl = user.lastIndexOf(".");
        if(uip == 0 || uipl == (user.length-1)){ uok = false; }
        if(!dok || !uok){        	
            mailok = false;
        }
        //
        for (var i=0;i<n;i++){
            var l = v.charAt(i);
            var charok = false;
            for(var c=0;c<=9;c++){
               if(l == c.toString()){ charok = true; }
            }
            for(var cc=0;cc<charv.length;cc++){
                if(l == charv[cc]){ charok = true; }
            }
            if(!charok){               
               mailok = false;
            }
        }
    }
	return mailok;
}

function changeLang(id){
	if(id && id != ""){
		$("#loader").show();
		$.ajax({
			url: "../../inc/lang.php",
			type: "post",
			dataType: "html",
			data: "id="+id,
			cache: false,
			success: function(dataServer){
				if(dataServer == 1){
					document.location.reload();
				}
			},
			complete: function(){
				$("#loader").hide();
			}
		});
	}
}

