$(document).ready(function() {

	function checkKey(e){
		if(e.keyCode == 27) {
			abreFechaModalImagem(false, 0);
			abreFechaEquipe(false, 0);
		}
	}
	if ($.browser.mozilla) {
		$(document).keypress (checkKey);
	} else {
		$(document).keydown (checkKey);
	}						   
						   
						   
						   
	$('.perfil-div').each(function(){
		$(this).hover(function(){
			$('.perfil-over', this).stop().animate({right: '-17px'}, 500);
		}, function(){
			$('.perfil-over', this).stop().animate({right: '-190px'}, 500);
		});
	});

    $('.portfolio-div').each(function(){
		$(this).hover(function(){
			$('.portfolio-over', this).stop().animate({right: '-17px'}, 500);
		}, function(){
			$('.portfolio-over', this).stop().animate({right: '-190px'}, 500);
		});
	});
	
	
	$('.home-div').each(function(){
		$(this).hover(function(){
			$('.home-over', this).stop().animate({right: '0px'}, 500);
		}, function(){
			$('.home-over', this).stop().animate({right: '-220px'}, 500);
		});
	});	
	
	
	$('.proximo').each(function(){
		$(this).hover(function(){
			$(this).stop().animate({width: '60px'}, 200);
			$('.anterior').stop().animate({width:'40px'}, 200);
		}, function(){
			$(this).stop().animate({width: '50px'}, 200);
			$('.anterior').stop().animate({width:'50px'}, 200);
		});
	});		
	
	$('.anterior').each(function(){
		$(this).hover(function(){
			$(this).stop().animate({width: '60px'}, 200);
			$('.proximo').stop().animate({width:'40px'}, 200);
		}, function(){
			$(this).stop().animate({width: '50px'}, 200);
			$('.proximo').stop().animate({width:'50px'}, 200);
		});
	});
});


function trocaCategoriaPortfolio(data, btn){
	$('#menu-local-portfolio > ul > li > a').each(function(){
		$(this).removeClass('menu-local-on');
	});
	
	$(btn).addClass('menu-local-on');	
	
	if(data == 1){
		$('#conteudo-interna-deslocado > h1').html('Sinalização');
		$('#conteudo-interna-deslocado > h2').html('“O bom design é consistente até nos mínimos detalhes” – Dieter Rams');		
	}else if(data == 2){
		$('#conteudo-interna-deslocado > h1').html('Design Gráfico');
		$('#conteudo-interna-deslocado > h2').html('“O design torna o mundo mais legível” – Abraham Moles');		
	}else if(data == 3){
		$('#conteudo-interna-deslocado > h1').html('Arquitetura Comercial');
		$('#conteudo-interna-deslocado > h2').html('“Criatividade é a derrota do hábito pela originalidade” – Arthur Koestler');		
	}
	
	$('#conteudo-interna-deslocado').css('height', $('#conteudo-interna-deslocado').attr('offsetHeight')-30+'px');
	
	$('.portfolio-div').each(function(){
		$(this).fadeOut(500);
	});
	
	window.setTimeout(function() {
		var contagemDiv = 0;
		$('.portfolio-div').each(function(){
			if($(this).attr('data') == data){
				$(this).css({display:'block', opacity:0});
				contagemDiv++;
			}
		});	


		var novaAltura = Math.round(contagemDiv / 4);
		if(novaAltura < contagemDiv / 4){
			novaAltura++;		
		}
		
		novaAltura = (novaAltura*176) + 90;
		$('#conteudo-interna-deslocado').animate({height:novaAltura+'px'}, 500, function(){
			$('.portfolio-div').each(function(){
				if($(this).attr('data') == data){		
					$(this).animate({opacity:1}, 500);
				}
			});																				 
		});
		

		
	}, 520);
	

}


function enviarEmailContato(){
	erro = '';
	br   = '';
	
	if(document.formContato.nome.value.length < 5 || document.formContato.nome.value == 'Nome:' ){
		erro = erro + br + 'Insira seu nome';
		br = "<br />";
	}
	
	if(document.formContato.email.value.length < 5 || document.formContato.email.value == 'E-mail:' ){
		erro = erro + br + 'Insira seu e-mail';
		br = "<br />";
	}	
	
	if(erro.length > 0){
		$('#feedback-form').removeClass('erro');
		$('#feedback-form').removeClass('sucesso');
		$('#feedback-form').addClass('erro');		
		$('#feedback-form').html(erro).fadeIn(500);		
	}else{
		$.post("ajax_contato.php", $("#formContato").serialize(), function(data){
			if(data == 'true'){
				$('#feedback-form').removeClass('erro');
				$('#feedback-form').removeClass('sucesso');
				$('#feedback-form').addClass('sucesso');
				$('#feedback-form').html('E-mail enviado com sucesso!').fadeIn(500);
				document.formContato.nome.value = 'Nome:';
				document.formContato.email.value = 'E-mail:';
				document.formContato.telefone.value = 'Telefone:';
				document.formContato.mensagem.value = 'Mensagem:';								
			}else{
				$('#feedback-form').removeClass('erro');
				$('#feedback-form').removeClass('sucesso');
				$('#feedback-form').addClass('erro');
				$('#feedback-form').html('Erro ao enviar e-mail!').fadeIn(500);
			}
		});
	}
}


function alteraImagem(direcao, divContainer, largura, altura){
	if(direcao == 'p'){
		imagemAtual++;
		if(imagemAtual > imagemArray.length - 1){
			imagemAtual = 0;
		}
	}else{
		imagemAtual--;
		if(imagemAtual < 0){
			imagemAtual = imagemArray.length - 1;
		}		
	}
	
	var _url = imagemArray[imagemAtual][0];
	
	_im =$("<img>");
	_im.hide();
	_im.bind("load",function(){ $(this).fadeIn(); });

	$('#'+divContainer).empty().append(_im);

	_im.attr('src',_url);
	_im.attr('width', largura);
	_im.attr('height', altura);	
}


function abreFechaEquipe(flag, id){
	if(flag){
		$('#modal-equipe-ajax').empty().html('<div style="width:620px; height:300px; background:url(img/ajax-loader.gif) center no-repeat;"></div>').load('ajax_equipe.php?id='+id);
		$('#modal-cancelar').stop().css({display:'block', opacity:0}).animate({opacity:0.8}, 500, function(){
			if(whichBrs() == 'Internet Explorer'){
				$('#modal-equipe-shadow-ie').css({display:'block'}).fadeIn(500);
			}
			
			$('#modal-equipe').fadeIn(500, function(){
				
			});											  
		});
	}else{
		if(whichBrs() == 'Internet Explorer'){
			$('#modal-equipe-shadow-ie').css({display:'block'}).fadeOut(500);
		}		
		$('#modal-equipe').fadeOut(500, function(){
			$('#modal-cancelar').fadeOut(500, function(){
			});
		});			
	}
}


function abreFechaModalImagem(flag, id, position, identificador){
	if(flag){
		$('#modal-cancelar').stop().css({display:'block', opacity:0}).animate({opacity:0.8}, 500, function(){
			$('#modal-imagem-ajax').empty().load('ajax_imagem.php?id='+id+'&pos='+position+'&ident='+identificador);
			
			if(whichBrs() == 'Internet Explorer'){
				//$('#modal-imagem-shadow-ie').css({display:'block'}).fadeIn(500);
			}
			
			$('#modal-imagem').fadeIn(500, function(){

			});
		});
	}else{
		if(whichBrs() == 'Internet Explorer'){
			$('#modal-imagem-shadow-ie').css({display:'block'}).fadeOut(500);
		}		
		$('#modal-imagem').fadeOut(500, function(){
			$('#modal-cancelar').fadeOut(500, function(){
			});
		});			
	}
}



function abreFechaSanfona(id, btn){
	if($('#sanfona-'+id).css('display') == 'block'){
		$('#sanfona-'+id).animate({height:'0px'}, 500, function(){  
			$(this).css({display:'none'});
		});
		$(btn).removeClass('sanfona-clipping-on');
		$(btn).addClass('sanfona-clipping-off');
	}else{
		$('#sanfona-'+id).css({display:'block', height:'0px'})
		var novaAltura = $('#sanfona-'+id+' > .sanfona-padding').css('height');
		novaAltura = parseInt(novaAltura.split('px')[0]) + 60;
		
		$('#sanfona-'+id).animate({height:novaAltura}, 500);
		$(btn).removeClass('sanfona-clipping-off');
		$(btn).addClass('sanfona-clipping-on');
	}
	
}


function pdfMostrar(div, btn){
	if($('#'+div).css('display') == 'block'){
		$('#'+div).slideUp(500);
		$(btn).removeClass('portfolio-on');
		$(btn).addClass('portfolio-off');		
	}else{
		$('#'+div).slideDown(500);
		$(btn).removeClass('portfolio-off');
		$(btn).addClass('portfolio-on');
	}
}

function informacaoMostrar(div, btn){
	if($('#'+div).css('display') == 'block'){
		$('#'+div).fadeOut(500);
		$(btn).removeClass('informacoes-on');
		$(btn).addClass('informacoes-off');		
	}else{
		$('#'+div).fadeIn(500);
		$(btn).removeClass('informacoes-off');
		$(btn).addClass('informacoes-on');
	}
}

var map;


var portoAlegre = new google.maps.LatLng(-30.037864,-51.176197);
var MY_MAPTYPE_ID = 'studio_mda';

function initialize() {
    var stylez = [{featureType: "all",elementType: "all",stylers: [{ visibility: "on" },{ hue: "#00ffb3" },{ lightness: 0 },{ gamma: 0.68 },{ saturation: -58 }]}];

    var mapOptions = {
        zoom: 16,
		maxZoom: 20,
		minZoom:14,
        center: portoAlegre,
		keyboardShortcuts:false,

		disableDefaultUI:true,
		
        mapTypeControl: false,
        mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
        },

		navigationControl: false,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.ZOOM_PAN,
			position: google.maps.ControlPosition.LEFT_TOP
		},

        mapTypeId: MY_MAPTYPE_ID
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    var styledMapOptions = {
        name: "Studio MDA"
    };

    var jayzMapType = new google.maps.StyledMapType(stylez, styledMapOptions);

    map.mapTypes.set(MY_MAPTYPE_ID, jayzMapType);
	
	
	
	var image = 'img/pointer.png';
	var myLatLng = new google.maps.LatLng(-30.037864,-51.176197);
	var beachMarker = new google.maps.Marker({
	  position: myLatLng,
	  map: map,
	  icon: image
	});
	

}









/*
	var resolucao = '';
	function resizeFunction(){
		var tamanhos = alertSize();
		
		if(document.body.offsetWidth < 1160){
			$("#troca-css").attr("href",'estilos-1024.css');
			resolucao = 1024;
		}else{
			$("#troca-css").attr("href",'estilos-1280.css');
			resolucao = 1280;
		}
		
		$('#conteudo').css('min-height', $('#contato').attr('offsetHeight') + $('#contato').attr('offsetTop') - 80);
		//document.getElementById('campo-usuario').value  = document.body.offsetWidth;
		

		if($('#container-home').attr('offsetHeight') < tamanhos[1]){
			var novaAltura = Math.round((tamanhos[1] - $('#container-home').attr('offsetHeight')) / 2) - 20;
			$('#container-home').css('marginTop', novaAltura);
		}				
	}

	
	function scrollFunction(){
		var top  = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
		var left = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
		var tamanhos = alertSize();
		var i = 0;
		$('.lote').each(function () {
			if($(this).attr('offsetTop') < Number(top+tamanhos[1] - 100)){
				if(arrayLoteApareceu.indexOf(i) == -1){
					$(this).stop().animate({opacity:1}, 500, function(){ $(this).css({display:'block'}).css('filter', 'none') });
					arrayLoteApareceu.push(i);
				}
			}
			i++;
		});
	}



	
    $(window).resize(function() {
        resizeFunction()
    });

    $(window).scroll(function() {
        scrollFunction()
    });
	
	resizeFunction();
	scrollFunction();	
	
	window.setTimeout(function() {
		resizeFunction();
		scrollFunction();	
	}, 500);
	
	
	*/
	











/*
function validarLancePrevio(loteId){
	$.post("ajax_lance_previo_v.php", $("#formLancePrevio").serialize(), function(data){
		if(data == 'true'){
			$('#modal-lance-previo-ajax').empty().html('<div id="modal-lance-previo-loading"><p><img src="img/ajax-loader.gif" width="16" height="16" /></p></div>').load('ajax_lance_previo.php?id='+loteId+'&status=1');
		}else if(data == 'preco'){
			$('#modal-lance-previo-erro').html('Seu lance deve ser maior que o valor inicial do lote.').css({display:'block', opacity:0}).animate({opacity:1}, 500);
		}else{
			$('#modal-lance-previo-erro').html('Ocorreu um erro, tente fazer o lance prévio mais tarde.').css({display:'block', opacity:0}).animate({opacity:1}, 500);			
		}
	});	
}

function formEsqueciValidar(){
	erro = '';
	br   = '';
	if(document.formEsqueci.esqueci_email.value.length < 5 || !checkMail(document.formEsqueci.esqueci_email.value)){
		erro = erro + br + '- E-mail inválido';
		br = "<br />";
		$('#esqueci_email').addClass('input-erro');
	}else{
		$('#esqueci_email').removeClass('input-erro');
	}
	
	if(erro.length == 0){
		$.post("ajax_esqueci_senha.php", $("#formEsqueci").serialize(), function(data){
			if(data == 'true'){
				$('#esqueci-fase1').css({display:'none'});
				$('#esqueci-fase2').css({display:'block'});
				$('#modal-erro-esqueci').animate({opacity:0}, 250, function(){ $(this).css({display:'none'}) });
			}else if(data=='naoexiste'){
				$('#modal-erro-esqueci').html('E-mail não encontrado.').css({display:'block', opacity:0}).animate({opacity:1}, 500);
			}else{
				$('#modal-erro-esqueci').html('Tente novamente mais tarde.').css({display:'block', opacity:0}).animate({opacity:1}, 500);				
			}
		});	
		
	}else{
		$('#modal-erro-esqueci').html(erro).css({display:'block', opacity:0}).animate({opacity:1}, 500);
	}	
}
*/



function ieVersion() {
	var agt=navigator.userAgent.toLowerCase();	
	if (agt.indexOf("msie 8") != -1) return 'IE8';	
	if (agt.indexOf("msie 7") != -1) return 'IE7';		
}

function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();
	
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){ 
			return true; 
		}
	}else{
		return false;
	}
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  return new Array(myWidth, myHeight);
}


if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function validaEnter(e, form){
   if(e && e.keyCode == 13){
      form.submit();
   }
}
