function arrowsIn(){//bring arrows in
	$("#prevBtn").animate({
		left: "0px"
		}, 800);
				
	$("#nextBtn").animate({
		left: "870px"
		}, 800);
}
function arrowsOut(){//send arrows back out
	$("#prevBtn").animate({
		left: "-20px"
		}, 800);
				
	$("#nextBtn").animate({
		left: "890px"
		}, 800);
}	
function activeState(margin, width){//animate active state
	$("#active_bar").animate({
		left: margin,
		width: width
	}, 400);
}		
//bring portfolio back up if its down
function backUp(){
	var top = document.getElementById('top');
		if(top.style.marginTop == "0px"){
			$("#top").animate({ 
				marginTop: "-132px"
				}, 200);
				
				arrowsOut();
				
			$("#content_wrap").animate({ 
				marginTop: "70px"
				}, 300);
		} 
}			
//ABOUT ME
		function loadAbout(){
			backUp();
			
			activeState("0px", "105px");
			
			$('#about_me').fadeIn(600);
			$('#info_wrap').css('display','none');
			$("#image").css('background', '');
			$("#image").animate({
				height: "450px"
				}, 400);
		}
//MY WORK
		function loadWork(){
			var top = document.getElementById('top');
				$("#top").animate({
				marginTop: "0px"
				}, 200);
				
				arrowsIn();
				
				activeState("105px", "103px");
		
			$("#content_wrap").animate({ //bring content down with nav
				marginTop: "200px"
				}, 300);
				imageSwap(0, document.getElementById('first_photo'))
		}		
//CONTACT ME 	
function contact(){
	
	$(".contact_btn").click(function(){
		if($("#footer_wrap").css('marginBottom')=='-300px'){
		$("#footer_wrap").animate({ 
				marginBottom: "0px"
				}, 100);
		$(".contact_btn").attr("src", "images/close_off.jpg");		
		}else{
			$("#footer_wrap").animate({ 
				marginBottom: "-300px"
				}, 100);
		$(".contact_btn").attr("src", "images/contact_me_off.jpg");
		}
	});
	
	
}	
//INFO TAB
	function infoTab(){
		var infoTab = document.getElementById("info_wrap");
		var button = infoTab.getElementsByTagName('a'); 
		
	$('a.info_tab').click(function(){	
		if(infoTab.style.marginLeft == "780px"){
			$("#info_wrap").animate({
				marginLeft: "580px"
				}, 100);
				button[1].innerHTML="&#187;"
		}
		else{
			$("#info_wrap").animate({
				marginLeft: "780px"
				}, 100);
				button[1].innerHTML="&#171;"
		}
		});
		
	}	


		
//IMAGE SWAP

	function imageSwap(image, thumb){
		$('#about_me').css('display', 'none');
	if($('#info_wrap').css('display')=='none'){
		$('#info_wrap').fadeIn(600);
		}	
		//MAKE REQUEST OBJECT 
			var xmlhttp;
				if (window.XMLHttpRequest){
 					xmlhttp=new XMLHttpRequest();
				}else if (window.ActiveXObject){
  					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}else{
  					alert("Your browser does not support XMLHTTP!");
  				}
				
		var url      = "portfolio.php";
		xmlhttp.open("GET",url,true);
		
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				//assign vars to IDs
				var xmlDoc = xmlhttp.responseXML.documentElement;
					//alert(xmlDoc);
				var slider = document.getElementById('slider');

				//grab array of image thumbs
				var thumbs = slider.getElementsByTagName('img');
				//set all image thumb borders to original color
				for (i = 0; i < thumbs.length; i++) {
					thumbs[i].style.borderColor = "#666";
				}
				//change active thumb to blue
				thumb.firstChild.style.borderColor = "#82b8cd";
				//get image to load
				var elem=xmlDoc.getElementsByTagName("image")[image].childNodes[0].nodeValue;
				//get title
				var title=xmlDoc.getElementsByTagName("title")[image].childNodes[0].nodeValue;
				//get info
				var info=xmlDoc.getElementsByTagName("info")[image].childNodes[0].nodeValue;
				//get skills
				var skills=xmlDoc.getElementsByTagName("skills")[image].childNodes[0].nodeValue;
				//get link
				var link=xmlDoc.getElementsByTagName("link")[image].childNodes[0].nodeValue;
				//make loading gif
				$('#image').css('background','url(images/loading.gif) 300px top no-repeat');
				$('#info').fadeOut(100);
					
					var newImg = new Image();
					newImg.src = xmlDoc.getElementsByTagName('image')[image].childNodes[0].nodeValue;
					//on image load, get width and height
						newImg.onload = function(){
							var imgHeight = newImg.height;
							var imgWidth = newImg.width;
							//change height of container
							//alert(imgHeight);
						$("#image").animate({
							height: imgHeight
						}, 400, function(){
							//load and fade in new image
							var elem=xmlDoc.getElementsByTagName("image")[image].childNodes[0].nodeValue;
							$('#image').css({'background':"url('" + elem + "') left top no-repeat", 'display':'none'});
							$('#image').fadeIn(400);
							
							//replace old info with new info
							var infoDiv = document.getElementById('info');
							var infoTitle = infoDiv.getElementsByTagName('h1');
							var infoText = infoDiv.getElementsByTagName('p');
							var infoLink = infoDiv.getElementsByTagName('a');
							var view = document.createTextNode('View Site');
							infoTitle[0].innerHTML = title;
							infoText[0].innerHTML = info;
							infoText[1].innerHTML = skills;
							infoLink[0].setAttribute("href", link);
							if(link!=="#"){
								infoLink[0].innerHTML="Launch Site";
							}else{
								infoLink[0].innerHTML="";
							}
							$('#info').fadeIn(600);
						});
	
					};

			}
		}	
		xmlhttp.send(null);
}

function contactForm(){
	$('.val').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
        }
    });
});

$("a img#submit").click(function(){
				var name     = $("input[name=name]").val();
				var email    = $("input[name=email]").val();
				var comments = $("textarea[name=comments]").val();
				//MAKE REQUEST OBJECT 
				var xmlhttp;
				if (window.XMLHttpRequest){
 					xmlhttp=new XMLHttpRequest();
				}else if (window.ActiveXObject){
  					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}else{
  					alert("Your browser does not support XMLHTTP!");
  				}
				
		var url      = "contact.php";
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Connection", "close");
		
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState < 4) {
			$("img#submit").attr("src", "images/loading.gif");
			$('input').css('backgroundColor', '#fff');
			$("#errors").css('display','none');
			}
			
			if (xmlhttp.readyState == 4) {
			$("img#submit").attr("src", "images/send_off.png");
			//alert(xmlhttp.responseText);
			$("#errors").html(xmlhttp.responseText);
				//change field colors
				if(xmlhttp.responseText=="Please enter your name<br/>Please enter your email address"){
					$("#errors").css('display','block');
					$('input[name=name]').css('backgroundColor', '#ffc0cb');
					$('input[name=email]').css('backgroundColor', '#ffc0cb');
				}else if(xmlhttp.responseText=="Please enter your name<br/>"){
					$("#errors").css('display','block');
					$('input[name=name]').css('backgroundColor', '#ffc0cb');
				}else if(xmlhttp.responseText=="Please enter your email address"){
					$("#errors").css('display','block');
					$('input[name=email]').css('backgroundColor', '#ffc0cb');
				}else{
					$("#success").css('display', 'block');
					$("#success").html(xmlhttp.responseText);
					$("img#submit").css('display', 'none');
					$("form").css('display', 'none');
					
				}
			}
		}
		var randomnumber=Math.floor(Math.random()*11);
		xmlhttp.send(
		"name="+encodeURI(name)+
		"&email="+encodeURI(email)+
		"&comments="+encodeURI(comments)+
		"&rand="+randomnumber
		);
				
				
				
				
				});
}
