// JavaScript Document
$(document).ready(function(){
	var pAboutLoren1 = "clientImgs/aboutLoren1.png";
	var pAboutLoren2 = "clientImgs/aboutLoren2.png";
	var pAboutLoren3 = "clientImgs/aboutLoren3.png";
	var pSeanKempton1 = "clientImgs/seankempton2.png";
	var pSeanKempton2 = "clientImgs/seankempton3.png";
	var pSeanKempton3 = "clientImgs/seankempton4.png";
	var emailN = 0;
	var messageN = 0;
	
	/*var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {
 
       $("#topBarDiv").show();
 
	}*/
	
	
	$("#contactBttn").click(function(){
		$("#proj1").animate({left:1500}, "normal");
		$("#proj2").animate({left:-1500}, "normal");
		$("#proj3").animate({left:1500}, "normal");
		$("#proj4").animate({left:-1500}, "normal");
		$("#proj5").animate({left:1500}, "normal");
		$("#aboutDiv").fadeOut("fast");
		$("#contactDiv").slideDown();
		$("#proj1").fadeOut("4000");
		$("#proj2").fadeOut("4000");
		$("#proj3").fadeOut("4000");
		$("#proj4").fadeOut("4000");
		$("#proj5").fadeOut("4000");
	});
	$("#projectBttn").click(function(){
		$("#proj1").show();
		$("#proj2").show();
		$("#proj3").show();
		$("#proj4").show();
		$("#proj5").show();
		$("#proj1").animate({left:97}, "normal");
		$("#proj2").animate({left:97}, "normal");
		$("#proj3").animate({left:97}, "normal");
		$("#proj4").animate({left:97}, "normal");
		$("#proj5").animate({left:97}, "normal");
		$("#aboutDiv").slideUp("fast");
		$("#contactDiv").slideUp("fast");
	});
	$("#aboutBttn").click(function(){
		$("#contactDiv").fadeOut("fast");
		$("#aboutDiv").slideToggle("normal");
		$("#proj1").animate({left:1500}, "normal");
		$("#proj2").animate({left:-1500}, "normal");
		$("#proj3").animate({left:1500}, "normal");
		$("#proj4").animate({left:-1500}, "normal");
		$("#proj5").animate({left:1500}, "normal");
		$("#proj1").fadeOut("4000");
		$("#proj2").fadeOut("4000");
		$("#proj3").fadeOut("4000");
		$("#proj4").fadeOut("4000");
		$("#proj5").fadeOut("4000");
	});
	$("#blackOutDiv").click(function(){
		$("#blackOutDiv").hide();
		$("#projectImgViewDiv").hide();
		$("#lrgImg").attr("src", "");
		$("#pImg1Div").hide();
		$("#pImg2Div").hide();
		$("#pImg3Div").hide();
		$("#pImg1").attr("src", "");
		$("#pImg2").attr("src", "");
		$("#pImg3").attr("src", "");
		$("#yuvalFrame").hide();
		$("#videoDiv").hide();
		$("#animationFrame").hide();
		$("#yuvalFrame").attr("src", "");
	});
	/*$("#lrgImg").click(function(){
		$("#blackOutDiv").hide();
		$("#projectImgViewDiv").hide();
		$("#lrgImg").attr("src", "");
		$("#pImg1Div").hide();
		$("#pImg2Div").hide();
		$("#pImg3Div").hide();
		$("#pImg1").attr("src", "");
		$("#pImg2").attr("src", "");
		$("#pImg3").attr("src", "");
	});*/
	$("#topHitPoint").mouseover(function(){
		$("#topBarDiv").slideDown("normal");
		$(document).mousemove(function(e){
			if(e.pageX <= 105 || e.pageX >= 899 || e.pageY >= 64){
				$("#topBarDiv").slideUp("normal");
			};
		});
	$("#emailTI").focusin(function(){
		if(emailN < 1){
			$("#emailTI").attr('value', '');
			emailN++;
		}
	});
	$("#emailTI").focusout(function(){
		var eLength = $("#emailTI").val().length;
		if(eLength == 0){
			document.getElementById("emailTI").value = "Your Email Address...";
			emailN = 0;
		}
	});
	$("#messageTI").focusin(function(){
		if(messageN < 1){
			$("#messageTI").attr('value', '');
			messageN++;	
		} 
	});
	$("#messageTI").focusout(function(){
		var mLength = $("#messageTI").val().length;
		if(mLength == 0){
			document.getElementById("messageTI").value = "Your Message...";
			messageN = 0;
		}
	});
	
	});
	
	//Project 1 More Text
	$("#moreProj1").click(function(){
		$("#moreProj1").hide();
		$("#proj1").animate({height:250}, "slow");
		$("#proj1Desc").animate({height:200},"slow");
		$("#moreP").html("Most of the websites that I build usually incorporate an online backend that the client can use to add, update, and delete information, but for AboutLoren.com I designed and created an AIR application that the user can update his site from the desktop.");
		$("#proj2").animate({top:275},"slow");
		$("#proj3").animate({top:475}, "slow");
		$("#proj4").animate({top:674}, "slow");
		$("#proj3").animate({height:175});
		$("#proj3Desc").animate({height:140});
		$("#moreProj3").show();
		$("#moreP3").hide();
	});
	//Project 3 More Text
	$("#moreProj3").click(function(){
		$("#proj4").animate({top:744}, "slow");
		$("#proj3").animate({height:325}, "slow");
		$("#proj3").animate({top:396}, "slow");
		$("#moreProj3").hide();
		$("#proj3Desc").animate({height:275},"slow");
		$("#proj1").animate({height:175}, "slow");
		$("#proj1Desc").animate({height:140},"slow");
		$("#moreP").html("");
		$("#moreProj1").show();
		$("#proj2").animate({top:196}, "slow");
		$("#moreP3").show();
		
	});
	
	// Project 1 Image functions
	$("#proj1Img").click(function(){
		$("#blackOutDiv").fadeIn("fast");
		$("#pImg1Div").show();
		$("#pImg2Div").show();
		$("#pImg3Div").show();
		$("#pImg1").attr("src", pAboutLoren1);
		$("#pImg2").attr("src", pAboutLoren2);
		$("#pImg3").attr("src", pAboutLoren3);
		$("#pImg1").click(function(){
			$("#lrgImg").attr("src", pAboutLoren1);
		});
		$("#pImg2").click(function(){
			$("#lrgImg").attr("src", pAboutLoren2);
		});
		$("#pImg3").click(function(){
			$("#lrgImg").attr("src", pAboutLoren3);
		});
		$("#projectImgViewDiv").show();
		$("#lrgImg").attr("src", "clientImgs/aboutLoren1.png");
	});
	
	$("#proj2Img").click(function(){
		$("#blackOutDiv").fadeIn("fast");
		$("#pImg1Div").show();
		$("#pImg2Div").show();
		$("#pImg3Div").show();
		$("#pImg1").attr("src", pSeanKempton1);
		$("#pImg2").attr("src", pSeanKempton2);
		$("#pImg3").attr("src", pSeanKempton3);
		$("#pImg1").click(function(){
			$("#lrgImg").attr("src", pSeanKempton1);
		});
		$("#pImg2").click(function(){
			$("#lrgImg").attr("src", pSeanKempton2);
		});
		$("#pImg3").click(function(){
			$("#lrgImg").attr("src", pSeanKempton3);
		});
		$("#projectImgViewDiv").show();
		$("#lrgImg").attr("src", "clientImgs/seankempton2.png");
	});
	$("#watchYuval").click(function(){
		$("#videoDiv").show();
		$("#yuvalFrame").show();
		$("#blackOutDiv").show();
		$("#yuvalFrame").attr("src", "http://www.youtube.com/embed/6SyFuHnb4qw?hd=1");
	});
	$("#watchYuval2").click(function(){
		$("#videoDiv").show();
		$("#yuvalFrame").show();
		$("#blackOutDiv").show();
		$("#yuvalFrame").attr("src", "http://www.youtube.com/embed/6SyFuHnb4qw?hd=1");
	});
	// Animations
	$("#twigPlay").click(function(){
		
		$("#blackOutDiv").show();
		$("#animationFrame").show();
		$("#playFrame").attr("src", "animation.php");
		$("#playFrame").css("width", "600");
		$("#playFrame").css("height", "450");
		$("#animationFrame").css("width", "600");
		$("#animationFrame").css("height", "450");
		$("#animationFrame").css("left", "275px"); 
	});
});

function launchImg(imgSrc){
	$("#blackOutDiv").show();
	$("#projectImgViewDiv").show();
	$("#lrgImg").attr("src", imgSrc);
}
function sendIt(){
	$("#mSentDiv").fadeIn('fast');	
	var mTimer = setTimeout("sendDone()", 2000);
	}
function sendDone() {
	$('#mSentDiv').fadeOut('fast')
	document.getElementById("messageTI").value = "Your Message..."; 
	document.getElementById("emailTI").value = "Your Email Address...";
}

function validateEmail() {
	var x=document.forms["conForm"]["emailTI"].value;
	var atpos=x.indexOf("@");
	var dotpos=x.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
 		 alert("Not a valid e-mail address");
  	return false;
 	 }
  	var m=document.forms["conForm"]["messageTI"].value;
	if (m==null || m=="") {
  	alert("You need to fill out the message.");
 	 return false;
  }
  	sendIt();
}
