	$(function() {
			   setupZoom();

		$("#box").toggle(
			function() {
				$("#box").animate({ top: -0}, 300);
				$("#footer").animate({ top: -0}, 300);
					
			},
			function() {
				
			   document.getElementById("content").innerHTML = "";
                $("#background").animate({  top:-470}, 0);
			
				$("#box").animate({ top:-160}, 300);
				$("#footer").animate({ top: -160}, 300);

		
                $("#innerBackground").animate({ height: 20}, 300);
				$("#background").animate({ height: 20}, 300);
				$("#button1").animate({ top: 0}, 300);
				$("#button2").animate({ top: 0}, 300);
				$("#button3").animate({ top: 0}, 300);
				$("#button4").animate({ top: 0}, 300);
				$("#button5").animate({ top: 0}, 300);
			}
			
		);
	
		$("#button1").click(function() {
			
			$("#button1").animate({ top: -15}, 300);
			$("#button2").animate({ top: 0}, 300);
			$("#button3").animate({ top: 0}, 300);
			$("#button4").animate({ top: 0}, 300);
			$("#button5").animate({ top: 0}, 300);

document.getElementById("innerBackground").style.visibility="visible";
		
			total = 1;
			$("#content").load("about.html", "", cleanState);
			
			
			return false;
		});
		
		$("#button2").click(function() {
			
			$("#button1").animate({ top: 0}, 300);
			$("#button2").animate({ top: -15}, 300);
			$("#button3").animate({ top: 0}, 300);
			$("#button4").animate({ top: 0}, 300);
			$("#button5").animate({ top: 0}, 300);
		
document.getElementById("innerBackground").style.visibility="visible";
			
			 $("#content").load("resume/resumemain.html", "", resumeBodyLoad);
			
			return false;
		});
		
		$("#button3").click(function() {
			
			$("#button1").animate({ top: 0}, 300);
			$("#button2").animate({ top: 0}, 300);
			$("#button3").animate({ top: -15}, 300);
			$("#button4").animate({ top: 0}, 300);
			$("#button5").animate({ top: 0}, 300);
		document.getElementById("innerBackground").style.visibility="hidden";
			
			 $("#content").load("slider.html", "", slider);
			
			return false;
		});
			
		$("#button4").click(function() {
			
			$("#button1").animate({ top: 0}, 300);
			$("#button2").animate({ top: 0}, 300);
			$("#button3").animate({ top: 0}, 300);
			$("#button4").animate({ top: -15}, 300);
			$("#button5").animate({ top: 0}, 300);

		document.getElementById("innerBackground").style.visibility="hidden";
			
			$("#content").load("contact.html", "", contactPage);
			
			return false;
		});
				
		$("#button5").click(function() {
			
			$("#button1").animate({ top: 0}, 300);
			$("#button2").animate({ top: 0}, 300);
			$("#button3").animate({ top: 0}, 300);
			$("#button4").animate({ top: 0}, 300);
			$("#button5").animate({ top: -15}, 300);

document.getElementById("innerBackground").style.visibility="hidden";
			
			total =6;
			$("#content").load("links.html", "", cleanState);
			
			
			
			return false;
		});
	});
	

	var slidercount = 0;
	function slider(){
if(slidercount==0){
total =0;	
		cleanState();
}
		
		
 slidercount++;
	if(slidercount>21){
			slidercount=0;
	
		   var container = $('div.sliderGallery');
            var ul = $('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
                        
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.ui-slider-handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
	       $(".btn-left").click(function(){
		       var elValue = $('.slider', container).slider('option', 'value');
			       if(elValue > 0) {
			          elValue = elValue - 100;
			          if(elValue < 0) {
		             elValue = 0;
		          }
			     $(".sliderGallery .slider").slider('value', elValue);
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			       }
			});
			$(".btn-right").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
			       if(elValue < itemsWidth) {
			          elValue = elValue + 100; 
			          if(elValue > itemsWidth) {
		             elValue = itemsWidth;
		          }
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			       }
			});
			$("span.end").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		             elValue = itemsWidth;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			});
			$("span.start").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		             elValue = 0;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			});
			
			//Item Code (Copy to make new item)
            
			$("img#itemA").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =1;
				$("div#portfolio").load("projects/project1.html", "", cleanState);
										   
			});
			$("img#itemA").tooltip('#tooltip');
			
            
			$("img#itemB").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =8;
				$("div#portfolio").load("projects/project2.html", "", cleanState);
										   
			});
            $("img#itemB").tooltip('#tooltip');
            
            
			$("img#itemC").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =1;	
				$("div#portfolio").load("projects/project3.html", "", cleanState);
										   
			});
            $("img#itemC").tooltip('#tooltip');
            
            
			$("img#itemD").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =5;
				$("div#portfolio").load("projects/project4.html", "", cleanState);
										   
			});
            $("img#itemD").tooltip('#tooltip');
            
            
			$("img#itemE").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =3;
				$("div#portfolio").load("projects/project5.html", "", cleanState);
										   
			});
            $("img#itemE").tooltip('#tooltip');
            
            
			$("img#itemF").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =7;
				$("div#portfolio").load("projects/project6.html", "", cleanState);
										   
			});
            $("img#itemF").tooltip('#tooltip');
            
            
			$("img#itemG").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =7;	
				$("div#portfolio").load("projects/project7.html", "", cleanState);
										   
			});
            $("img#itemG").tooltip('#tooltip');
            
            
			$("img#itemH").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =6;
				$("div#portfolio").load("projects/project8.html", "", cleanState);
										   
			});
            $("img#itemH").tooltip('#tooltip');
            
            
			$("img#itemI").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =2;	
				$("div#portfolio").load("projects/project9.html", "", cleanState);
										   
			});
            $("img#itemI").tooltip('#tooltip');
            
            
			$("img#itemJ").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =2;	
				$("div#portfolio").load("projects/project10.html", "", cleanState);
										   
			});
            $("img#itemJ").tooltip('#tooltip');
            
            
			$("img#itemK").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =4;
				$("div#portfolio").load("projects/project11.html", "", cleanState);
										   
			});
            $("img#itemK").tooltip('#tooltip');
            
            
			$("img#itemL").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =1;
				$("div#portfolio").load("projects/project12.html", "", cleanState);
										   
			});
            $("img#itemL").tooltip('#tooltip');
            
            
			$("img#itemM").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =4;	
				$("div#portfolio").load("projects/project13.html", "", cleanState);
										   
			});
            $("img#itemM").tooltip('#tooltip');
            
            
			$("img#itemN").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =4;
				$("div#portfolio").load("projects/project14.html", "", cleanState);
										   
			});
            $("img#itemN").tooltip('#tooltip');
            
            
			$("img#itemO").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =6;
				$("div#portfolio").load("projects/project15.html", "", cleanState);
										   
			});
            $("img#itemO").tooltip('#tooltip');
            
            
			$("img#itemP").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =6;
				$("div#portfolio").load("projects/project16.html", "", cleanState);
										   
			});
            $("img#itemP").tooltip('#tooltip');
            
            
			$("img#itemQ").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =3;
				$("div#portfolio").load("projects/project17.html", "", cleanState);
										   
			});
            $("img#itemQ").tooltip('#tooltip');
            
            
			$("img#itemR").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =14;
				$("div#portfolio").load("projects/project18.html", "", cleanState);
										   
			});
            $("img#itemR").tooltip('#tooltip');
            
            
			$("img#itemS").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =5;
				$("div#portfolio").load("projects/project19.html", "", cleanState);
										   
			});
            $("img#itemS").tooltip('#tooltip');
            
            
			$("img#itemT").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =1;	
				$("div#portfolio").load("projects/project20.html", "", cleanState);
										   
			});
            $("img#itemT").tooltip('#tooltip');
            
            
			$("img#itemU").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
					total =8;	
				$("div#portfolio").load("projects/project21.html", "", cleanState);
										   
			});
            $("img#itemU").tooltip('#tooltip');
            
            
			$("img#itemV").click(function(){
            document.getElementById("innerBackground").style.visibility="visible";
						total =8;
				$("div#portfolio").load("projects/project22.html", "", cleanState);
										   
			});
            $("img#itemV").tooltip('#tooltip');
            }

	return false;
	}
	function resumeBodyLoad(){
		
		total =0;
			cleanState();
		
		
		$("span#resume1").click(function(){
				document.getElementById("resume1").className = "resumeSelected";
				document.getElementById("resume2").className = "resumeUnselected";
				document.getElementById("resume3").className = "resumeUnselected";
				
				$("div#resume").load("resume/resume1.html", "", cleanState);
										   
			});
		$("span#resume2").click(function(){
				document.getElementById("resume1").className = "resumeUnselected";
				document.getElementById("resume2").className = "resumeSelected";
				document.getElementById("resume3").className = "resumeUnselected";
				
				$("div#resume").load("resume/resume2.html", "", cleanState);
										   
			});
		$("span#resume3").click(function(){
				document.getElementById("resume1").className = "resumeUnselected";
				document.getElementById("resume2").className = "resumeUnselected";
				document.getElementById("resume3").className = "resumeSelected";
				
			$("div#resume").load("resume/resume3.html", "", cleanState);
										   
			});

		
	return false;

	}

var cleanStateCounter =0;
var total =0;
	function cleanState(){

	cleanStateCounter =0;
        

if(cleanStateCounter >= total){

		 setupZoom();
		
		cleanStateAni();
		
}
		return false;
	}

	function cleanStateHelper(){
cleanStateCounter++;
if(cleanStateCounter >= total){

		 setupZoom();
		
		cleanStateAni();
		
}
return false;
}
	function cleanStateAni(){
                 var offset = document.getElementById("content").offsetHeight;
		var bgoffset = document.getElementById("content").offsetHeight +20;

		var topoffset = -1*(bgoffset + 470);
		
		$("#background").animate({ top: topoffset}, 0);
		
		
		$("#background").animate({ height: bgoffset}, 300);
	        $("#innerBackground").animate({ height: bgoffset}, 300);
		$("#box").animate({ top: offset}, 300);
		$("#footer").animate({ top: offset}, 300);
}

	function contactPage(){
	
	$("#imgname").hide();
	$("#imgsubject").hide();
	$("#imgemail").hide();
	$("#imgcomments").hide();
	total =0;
	cleanState();
	$("form").submit(function() {
				
				$("#imgname").hide();
	$("#imgsubject").hide();
	$("#imgemail").hide();
	$("#imgcomments").hide();
	 var error = true;
      if ($("input#formname").val() == "") {
        $("#imgname").show();
        error = false;
      } 
	  if ($("input#formsubject").val() == "") {
         $("#imgsubject").show();
         error = false;
      }  
	 if ( !echeck($("#formemail").val() )) {
          $("#imgemail").show();
        error = false;
      } 
	  if ($("#formcomments").val().length ==0) {
         $("#imgcomments").show();
         error = false;
      } 
	  
	  
	 return error;
    });
	
	}
	
	function postForm(){
		
		$.post("contact.php", $("form").serialize() , function(data){
  document.getElementById("content").innerHTML = data;
total =0;
  cleanState();
});	
	}
	
	function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		  
		   return false;
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		
		   return false;
		}

		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false;
		}

		 else if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false;
		 }

		 else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		  
		    return false;
		 }

		 else if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false;
		 }
		
		else  if (str.indexOf(" ")!=-1){
		    
		    return false;
		 }
else{
 		 return true	;		
}
	}