$(document).ready(function() {
    var site= new Array();
    var link= new Array();
    var texto_port= new Array();

    menuNav();
    function menuNav() {
        jQuery.each(jQuery.browser, function(i) {
            if($.browser.msie){
            }

            else {
                //$("#menu_port li").removeClass("hover");
                $("#menu_port li a").css({
                    opacity:0.0
                }).mouseover(function(){
                    $(this).stop().animate(
                    {
                        opacity:1.0
                    },300)
                })
                .mouseout(function(){
                    $(this).stop().animate(
                    {
                        opacity:0.0
                    }
                    ,500);
                });
            }

        });
    }
    $("#menu_port li a").click(function(port){
        port.preventDefault();
        $("#menu_port, #dog").fadeOut("fast");
        $("<div id='port_web_sites'></div>").appendTo("#portfolio_meio");
        var conteudoAjax_port = $('#port_web_sites');
        function mostrarCarregando_port(){  
		conteudoAjax_port.css('display', 'none');
        }
				
        function aposCarregamento_port(){
                conteudoAjax_port.fadeIn("fast");
        }

            mostrarCarregando_port();
            switch(this.id){
                case 'm1':
                    conteudoAjax_port.load('portfolio.html #dv1', aposCarregamento_port);
                    break;
                case 'm2':
                    conteudoAjax_port.load('portfolio.html #dv2', aposCarregamento_port);
                    break;
                case 'm3':
                    conteudoAjax_port.load('portfolio.html #dv3', aposCarregamento_port);
                    break;
                default:
                    aposCarregamento_port();
                    break;
            }
    });
    $('.port_web_site_fechar').click(function(){
        $('#ovelay').fadeOut('fast');
        $('.port_seta_esquerda').fadeOut("fast");
        $('.port_seta_direita').fadeOut("fast");
        $('#palco_web_site').remove();
        $('#palco_web_site_rodape').remove();
        $('#palco_web_site_loading').remove();
        $(this).fadeOut('fast');
    });
    $("#port_web_sites img").live("click",function(){
        var id_web = $(this).attr("class");
         $.ajax({
		type: "GET",
		url: "xml/sites.xml",
		dataType: "xml",
		success: function(portfolio) {
			$(portfolio).find('site').each(function(i){
				site[i] =$(this).find('img').text();
				link[i] = $(this).find('link').text();
				texto_port[i] = $(this).find('texto').text();
			});
                        var qtos_sites = site.length;
        $('#ovelay').fadeIn("fast");
        if(id_web!=0){
        $('.port_seta_esquerda').fadeIn("fast");
    }
        if(id_web < qtos_sites-1){
        $('.port_seta_direita').fadeIn("fast");
        }
        $("<div id='palco_web_site'></div>").appendTo('#portfolio_meio');
        $("<div id='palco_web_site_loading'/></div>").appendTo('#portfolio_meio');
        $("<img class='amostra_site'/>").appendTo("#palco_web_site");

                    $("<div id='palco_web_site_rodape'></div>").css('display', 'none').appendTo('#palco_web_site');
                    $("<p class='texto_port_titulo'>"+texto_port[id_web]+"</p>").css('display', 'none').appendTo('#palco_web_site_rodape');
                    $("<p class='link_port_web'><a href='"+link[id_web]+"' target='_blank'>visite</a></p>").css('display', 'none').appendTo('#palco_web_site_rodape');
        $('.amostra_site').load(function() {
                    $("#palco_web_site_loading").fadeOut("fast");
                    $('.port_web_site_fechar').fadeIn("fast");
                    $('.amostra_site').fadeIn('fast');
                    $('#palco_web_site').fadeIn('fast');
                    $('.link_port_web').fadeIn('fast');
                    $('.texto_port_titulo').fadeIn('fast');
                    $('#palco_web_site_rodape').fadeIn('fast');
                }).attr('src', 'img/portfolio/'+site[id_web] );
                
        
        $('.port_seta_direita').live("click",function(){
           $("#palco_web_site_loading").fadeIn("fast");
           $('#palco_web_site').fadeOut('fast');
           $(".amostra_site").empty();
           $('#palco_web_site_rodape').empty();
            id_web++;
             if(qtos_sites == id_web +1){
                    $('.port_seta_direita').fadeOut("fast");
                        }
             if(id_web!=0){
                    $('.port_seta_esquerda').fadeIn("fast");
                }
             $('.amostra_site').load(function() {
                    $("#palco_web_site_loading").fadeOut("fast");
                    $('#palco_web_site').fadeIn('fast');
                    $("<p class='texto_port_titulo'>"+texto_port[id_web]+"</p>").appendTo('#palco_web_site_rodape');
                    $("<p class='link_port_web'><a href='"+link[id_web]+"' target='_blank'>visite</a></p>").appendTo('#palco_web_site_rodape');
                    $(this).fadeIn('fast');
                }).attr('src', 'img/portfolio/'+site[id_web] );
        });
        $('.port_seta_esquerda').live("click",function(){
            $("#palco_web_site_loading").fadeIn("fast");
            //$('#palco_web_site_rodape').empty();
            $('.texto_port_titulo').remove();
            $('.link_port_web').remove();
            $('#palco_web_site').fadeOut('fast');
            $(".amostra_site").empty();
            $('.port_seta_direita').fadeIn("fast");
            id_web--;
            if(id_web==0){
        $('.port_seta_esquerda').fadeOut("fast");
    }
    $('.amostra_site').load(function() {
                    $("#palco_web_site_loading").fadeOut("fast");
                    $('#palco_web_site').fadeIn('fast');
                    $("<p class='texto_port_titulo'>"+texto_port[id_web]+"</p>").appendTo('#palco_web_site_rodape');
                    $("<p class='link_port_web'><a href='"+link[id_web]+"' target='_blank'>visite</a></p>").appendTo('#palco_web_site_rodape');
                    $(this).fadeIn('fast');
                }).attr('src', 'img/portfolio/'+site[id_web] );
        });


		}

	});
	
    });
	var x=$(window).width();
	var y=(x-65);
	var z=([x-960]/2);
	var xyz=(890+z);
	var a=0;
	var staff_loader = 0;
	var carregando = $('#carregando');
	var conteudoAjax = $('#staff_profiles_dois');
		$('#ovelay').css('display', 'none').css('opacity', .94);
		$('input').css('opacity', .30);
		$('textarea').css('opacity', .30);
		$('#all').css('width',''+(x*5)+'px');
		$('#inicio').css('width',''+x+'px');
		$('#staff').css('width',''+x+'px');
		$('#portfolio').css('width',''+x+'px');
		$('#code_barras').css('margin-left',''+y+'px');
		$('#duvidas').css('width',''+x+'px');
		$('#contato').css('width',''+x+'px');
		$('#news_table').css('opacity', 0.85);
		$('.opaco').css('opacity', 0.25);
		$('#duvida_um').css('opacity', 0.22);
		$('#duvida_dois').css('opacity', 0.22);
		$('#duvida_tres').css('opacity', 0.22);
		jQuery.each(jQuery.browser, function(i) {
		  if($.browser.msie){
			 $('#code_barras').css('margin-left',''+xyz+'px');
			 $('#duvida_um').css('background','url(img/balao.png) no-repeat');
			 $('#duvida_dois').css('background','url(img/balao_2.png) no-repeat');
			 $('#duvida_tres').css('background','url(img/balao_3.png) no-repeat');
		  }
		});
									  $('#twitter_table').css('opacity', 0.85);
           var y = Math.floor(Math.random()*9);
			$('<img src="img/saudacao/'+y+'.jpg" width="430" height="102"/>').appendTo('#saudacao');
			$('#news').click(function() {
									  $('#news_table').fadeIn("slow");
									  $('#twitter_table').fadeOut("slow");
									  });
			$('#mais_dupers_um').click(function() {
									  $('#staff_profiles_um').fadeIn("slow");
									  $('#mais_dupers').fadeIn("slow");
									  $(this).fadeOut("slow");
									  $('#staff_profiles_dois').fadeOut("slow");
									  });
			$('#fechar').click(function() {
									  $('#news_table').fadeOut("slow");
									  $('#twitter_table').fadeOut("slow");
									  $('#twitter_table ul').empty();
									  $('#twitter_table').addClass('loading');
									 // $('#news_table').addClass('loading');
									  });
			$('#fechar_news').click(function() {
									  $('#news_table').fadeOut("slow");
									  $('#twitter_table').fadeOut("slow");
									  $('#twitter_table ul').empty();
									  $('#twitter_table').addClass('loading');
									 // $('#news_table').addClass('loading');
									  });
			$('#contato_enviar').click(function(nops) {
									nops.preventDefault();
									  $(this).fadeOut("slow");
									var serializeDados = $('#formulario').serialize();
									 $.ajax({
									type: "POST",
									url: "contato.php",
									dataType: "html",
									data: serializeDados,
									beforeSend: function() {
									  $('#formulario').fadeOut("slow");
									  $('#contato_texto').fadeOut("slow");
									  $('#ovelay').fadeIn(1000).css('display', 'inline');	
									},
									complete: function() {
										$('#ovelay').hide();
									  $('#contato_cheers').fadeIn(1000).css('display', 'inline');	
									}
								});	

									  });
					function mostrarCarregando(){  
					 	carregando.css('display', 'block').fadeIn(1000).css('top', '30px');
				 	 	$('#ovelay').fadeIn(1000).css('display', 'inline');
					};
					function aposCarregamento(){
				 		carregando.css('display', 'none');  
				 		$('#ovelay').fadeOut('fast');
					};  
					$(conteudoAjax).css('opacity', .94);
						$('#mais_dupers').click(function(event){  
							event.preventDefault();
								if (staff_loader==0) {
								 $('#ovelay').css('display', 'inline');
								mostrarCarregando();  
								conteudoAjax.fadeIn("slow");
									conteudoAjax.load('staff_dois.html', aposCarregamento);
								}
						$('#staff_profiles_um').fadeOut("slow");
						$(this).fadeOut("slow");
						$('#mais_dupers_um').fadeIn("slow");
							if (staff_loader>0) {
									$('#staff_profiles_dois').fadeIn("slow");
							}
						staff_loader++;
						});
			$('.duvida').click(function() {
										$('#duvida_respondida').empty(); 
										$('#duvida_respondida').fadeIn("fast"); 							 
										var duvida = $(this).attr("name");
										$('<p>'+duvida+'</p>').appendTo("#duvida_respondida");
										 });
				 		   $(".duvida").hover(function(e){
													 $(this).css('opacity', 1);
														//$('#duvida_dois').css('opacity',1);
														//$('#duvida_tres').css('opacity', 1);
    }, function(e){
		$(this).css('opacity', 0.22);
    });
			 $('#pergunte_klog').click(function() {
										  $('#duvida_respondida').fadeOut("fast");
										  $('#form_dk').slideDown("fast");
										  $('#ovelay').fadeIn(1000).css('display', 'inline');
									  	  $('#titulo_form_dk').fadeIn("slow");
									  	  $('#dk_form').fadeIn("slow");
									  	  $('.enviar_klog').fadeIn("slow");		
										 });
			 $('.close').click(function() {
										  $('#form_dk').slideUp("fast");
										  $('#ovelay').fadeOut(1000);
									  	  $('#titulo_form_dk').fadeOut("slow");	
										 });
			 $('.enviar_klog').click(function(klog) {
									klog.preventDefault();
									  $(this).fadeOut("slow");
									var serializeDados = $('#form_dk').serialize();
									 $.ajax({
									type: "POST",
									url: "pergunta_dk.php",
									dataType: "html",
									data: serializeDados,
									beforeSend: function() {
									  $('#dk_form').fadeOut("fast");
									  $('.msg_dk').fadeIn(1500);
									  
									},
									complete: function() {	
									 	  $('#form_dk').slideUp("fast");
										  $('#ovelay').fadeOut(1000);
									  	  $('#titulo_form_dk').fadeOut("slow");
									  	  $('.msg_dk').fadeOut("fast");
									}
								});	
											  });
			$('#twitter').click(function() {
									  $('#news_table').fadeOut("slow");
									  $('#twitter_table').fadeIn("slow");
									  $('#twitter_table').addClass('loading');
									  var url = "http://twitter.com/statuses/user_timeline/super_dupers.json?count=8&callback=?"; 
       $.getJSON(url, 
        function(data){ 
            $.each(data, function(i, item) {  
                $("#twitter_table ul").append("<li>"+item.text+"</li>"); 
            }); 
			$('#twitter_table').ajaxStop(function() {
				$('#twitter_table').removeClass('loading');
													  });
        })
									  

									  });
				$('.menuStart').click(function(start) {
					start.preventDefault();
					$('html,body').animate({
                    scrollLeft:'0px'
               		},2000);
									  });
			$('.menuStaff').click(function(start) {
					start.preventDefault();
					$('html,body').animate({
						scrollLeft:x
					},2000);
									  });
			$('.menuPort').click(function(start) {
					start.preventDefault();
					$('html,body').animate({
						scrollLeft:(2*x)
					},2000);
									  });
			$('.menuInterrogacao').click(function(start) {
					start.preventDefault();
					if (a<1) {
					imagem_lista = Array('form_elvio.png', 'fechar_dk.png', 'resposta_klogteste.png', 'enviar_dk.png');
					imagem_qtd = imagem_lista.length;
						for (a = 0; a <imagem_qtd; a++) {
							var preload = new Image();
							preload.src = imagem_lista[a];
						}
					}
					$('html,body').animate({
						scrollLeft:(3*x)
					},2000);
									  });
			$('.menuContato').click(function(start) {
					start.preventDefault();
					$('html,body').animate({
						scrollLeft:(4*x)
					},2000);
									  });
			$(".opaco").hover(function(e){
				$(this).animate({
					opacity: 100
				  }, 300 );
				}, function(e){
					$(this).animate({
					opacity: 0.25
				  }, 300 );
						});
		 
			
			
	  });
		

