// ---------- start of jQuery document.ready() ----------
  
$(document).ready(function() {   
  

	//add javascript only elements
		$('<div id="rule"></div>').insertBefore('div#services');
		$('<div id="showcase"></div>').insertAfter('div#projectlist');
		$('div#showcase').append('<img id="largeImg" src="">')
		.append('<div id="projectdescription"></div>').hide();
		$('<div id="closebutton"><img src="images/close.png"></div>').insertAfter('div#showcase');
		$('.work').html("Past Work");
	
	
	//hide elements
		$('div#delay').hide();
		$('div#portfolio').hide();
		$('div#rule').hide();
		$('div#sectionnavigation').hide();
		$('div.return').hide()
		
	
	//animate line & scroll
		function rule() {
			welcomeOffset = $('div#welcome').offset().top;
			$('html, body').animate({scrollTop: welcomeOffset}, 1200);
			$('div#rule').slideDown(2400);
		}
		setTimeout(rule, 300);
	  
	  
	// show hidden content
		function reveal() {
			$('div#delay').show();	
		}
		setTimeout(reveal, 900);
		
		function lateReveal() {
			$('div.return').fadeIn(600);	
		}
		setTimeout(lateReveal, 6500);
		
  
	//click scroll 		  
		$('a[href*=#]').each(function() {
			var targetId = $(this.hash);
			var targetOffset = targetId.offset().top;
			$(this).click(function() {
				$('html, body').animate({scrollTop: targetOffset}, 600);
				$('div.return').animate({opacity: 1}, 1200).fadeIn(600);
				return false;
				});		 
		});
		  

	// expand & contract the portfolio space
		$('span.work').click(function(){
			$('html, body').animate({scrollTop: welcomeOffset}, 600);
			$('div#portfolio').fadeIn(600);
			$('div#projectlist').fadeIn(600);
		});
		
		$('.thumbs a').click(function(){
			var closed = $('div#portfolio').width();
			if (closed < 300 ) {
				$('div#portfolio').animate({width: 840}, 1200);
				}
			$('div#showcase').show();
			var largePath = $(this).attr('href');
			var description = $(this).attr('name');
			$('#projectdescription').load('portfolio.php #'+description+'');
			$('#largeImg').attr({ src: largePath });
        	return false;
		});
		
		$('div#closebutton').click(function(){
			var opened = $('div#portfolio').width();
			if (opened > 300 ) {
				$('div#portfolio').animate({width: 270}, 600);
				}
			$('div#showcase').fadeOut(600);
			$('div#projectlist').animate({opacity: 1}, 600)
			.fadeOut(600);
			$('div#portfolio').fadeOut(600);
		});


		
	// form processor
		$('#contactform').ajaxForm(function(data) {
			if (data==1) {
				$('#formcontainer').html("<div id='successmessage'></div>");
        		$('#successmessage').html("<div id='successtext'><h2>Message sent successfully!</h2><p>Thank you for taking the time to contact me.</p></div>");
        		$('#successtext').hide().fadeIn(1200);
        		$('#successmessage').animate({opacity: 1}, 6000)
        		.fadeOut('slow'); 
			}
			
			else if (data==2) {
				$('<div id="error"></div>').insertAfter('div#formcontainer');
				$('#error').html("<p class='blocktext'>Message not sent; server error. Please try again later.</p>")
				.hide()
				.fadeIn(900)
				.animate({opacity: 1}, 3600)
				.fadeOut(900);
			}
			
			else if (data==3) {
				$('<div id="error"></div>').insertAfter('div#formcontainer');
				$('#error').html("<p class='blocktext'>Please make sure there are entries in all fields and that the email address is valid.</p>")
				.hide()
				.fadeIn(900)
				.animate({opacity: 1}, 3600)
				.fadeOut(900);
			}
		});

    
});


// ---------- end of jQuery document.ready() ----------