jQuery(document).ready(function(){
	
	jQuery('input[type="text"]').focus(function() {  
	       if (this.value == this.defaultValue){  
	           this.value = '';  
	       }  
	      if(this.value != this.defaultValue){  
	          this.select();  
	      }  
	});
	
  	jQuery('input[type="text"]').blur(function() {  
	     if (this.value == ''){  
	         this.value = (this.defaultValue ? this.defaultValue : '');  
	      }  
	}); 
	
	jQuery("a.projetosProfissional").click(function(){
	   	jQuery('#projetos-profissional').slideToggle('fast');
	
		if(jQuery("#infoProjeto")[0]) {
			jQuery("#infoProjeto").attr("id", "infoProjetoFull");
		} else {
			jQuery("#infoProjetoFull").attr("id", "infoProjeto");
		}
		
		if(jQuery("#outros-projetos").css("display") == "block") {
			jQuery("#outros-projetos").hide();
		} else {
			jQuery("#outros-projetos").show();
		}
		
		if(jQuery(this).is(".projetosProfissional")) {
			jQuery(this).removeClass("projetosProfissional").addClass("btVoltar");
		} else {
			jQuery(this).removeClass("btVoltar").addClass("projetosProfissional");
		}
	});
	
	jQuery("#imgProjeto").hover(
		function(){
			jQuery("#navegacao").fadeIn(500);
			jQuery("#gostou-projeto").fadeIn(500);
		},
		function(){
			jQuery("#navegacao").fadeOut(200);
			jQuery("#gostou-projeto").fadeOut(200);
		});
		
	jQuery(".zoomFoto").click(function(){
		var page_height = $(document).height();
		
		var fundoTransp = document.createElement("div");
		fundoTransp.style.display = "none";
		fundoTransp.style.background = "url(images/black.png)";
		fundoTransp.style.width = "100%";
		fundoTransp.style.height = page_height+"px";
		fundoTransp.style.position = "absolute";
		fundoTransp.style.top = "0";
		fundoTransp.style.left = "0";
		fundoTransp.style.zIndex = "999";
		fundoTransp.id = "fundoTransp";

		var img = document.createElement("img");
		img.src = jQuery(this)[0].href;
		img.style.position = "absolute";
		
		var divImg = document.createElement("div");
		divImg.style.position = "absolute";
		divImg.style.top = '100px';
		divImg.style.left = '50%';
		//divImg.height = img.height + "px";
		divImg.width = img.width + "px";
		//divImg.style.marginTop = ((img.height / 2) * -1) + "px";
		divImg.style.marginLeft = ((img.width / 2) * -1) + "px";
		divImg.style.marginBottom = "50px";
		
		var divNavegacao = document.createElement("div");
		divNavegacao.className = "nav";
		divNavegacao.style.width = img.width + "px";
		divNavegacao.style.top = (img.height / 2) + "px";
		
		var linkEsq = document.createElement("a");
		linkEsq.className = 'anteFoto';
		linkEsq.innerHTML = "Anterior";
		
		var linkDir = document.createElement("a");
		linkDir.className = 'proxFoto';
		linkDir.innerHTML = "Proxima";
		
		var linkFechar = document.createElement("a");
		linkFechar.className = 'fechar';
		linkFechar.innerHTML = "Fechar";
		
		divNavegacao.appendChild(linkDir);		
		divNavegacao.appendChild(linkEsq);
		divNavegacao.appendChild(linkFechar);
		
		jQuery(divImg).hover(
			function(){
				jQuery(divNavegacao).fadeIn(500);
			},
			function(){
				jQuery(divNavegacao).fadeOut(200);
			});

		linkFechar.onclick = function() {
			jQuery(fundoTransp).fadeOut(200, function() { document.body.removeChild(fundoTransp); });
		}
		
		var $imagens = $("#slideshow div").length;
		var $count = -1;
		
		if($count == -1) { linkEsq.className = ''; linkEsq.innerHTML = ''; }
		if($imagens == 1) { linkDir.className = ''; linkDir.innerHTML = ''; }
		
		linkDir.onclick = function() {
			$count++;
			if(($count+1) == $imagens) { linkDir.className = ''; linkDir.innerHTML = ''; }
			if($count >= 1) { linkEsq.className = 'anteFoto'; linkEsq.innerHTML = 'Anterior'; }
			
			var $proximo = $("#slideshow div").get()[$count];
			//$("#slideshow div").fadeOut(200);
			//$($proximo).fadeIn(500);
			
			$(divImg).children('img').remove();
			img = document.createElement("img");
			img.src = $($proximo).children().attr('src');
			img.style.position = "absolute";
			divImg.appendChild(img);
			
			page_height = $(document).height();
			fundoTransp.style.height = page_height+"px";
			//if(page_height > 850)
			//{
			//	page_height = page_height+400;
			//	fundoTransp.style.height = page_height+"px";
			//}
		}
		
		linkEsq.onclick = function() {
			$count--;
			if(($count+1) == $imagens) { linkDir.className = 'proxFoto'; linkDir.innerHTML = 'Proxima'; }
			if($count < 1) { linkEsq.className = ''; linkEsq.innerHTML = ''; } else { linkEsq.className = 'anteFoto'; linkEsq.innerHTML = 'Anterior'; }
			
			var $proximo = $("#slideshow div").get()[$count];
			//$("#slideshow div").fadeOut(200);
			//$($proximo).fadeIn(500);
			
			$(divImg).children('img').remove();
			img = document.createElement("img");
			img.src = $($proximo).children().attr('src');
			img.style.position = "absolute";
			divImg.appendChild(img);
			
			page_height = $(document).height();
			fundoTransp.style.height = page_height+"px";
			//if(page_height > 850)
			//{
			//	page_height = page_height+400;
			//	fundoTransp.style.height = page_height+"px";
			//}
		}
		
		divImg.appendChild(divNavegacao);
		divImg.appendChild(img);
		fundoTransp.appendChild(divImg);
		document.body.appendChild(fundoTransp);
		
		jQuery(fundoTransp).fadeIn(200);
		
		return false;
	});
});


