$(function() {

	pic1= new Image(16, 16); 
	pic1.src="/images/ajax-loader.gif";
	pic2= new Image(71,39); 
	pic2.src="/images/portfolioButtonHover.jpg";

	$('a.lightbox').lightBox();

	var numberOfPortfolioItems = $('ul.portfolioSlider li').size();
	var currentItem = 1;
	var newLocationTemp;
	var newLocation;
	
	$('.portfolioButtons a.right').click(function() {
		if(currentItem == numberOfPortfolioItems - 2) {
			currentItem = 1;
			$('.portfolioSlider').animate({"left":"0px"});
		} else {
			newLocationTemp = currentItem * 330;
			newLocation = newLocationTemp - newLocationTemp - newLocationTemp;
			$('.portfolioSlider').animate({"left":newLocation});
			currentItem++;
		}
			return false;
	});
	
	$('.portfolioButtons a.left').click(function() {
		if(currentItem == 1) {
			currentItem = 1;
			$('.portfolioSlider').animate({"left":"0px"});
		} else {
			newLocationTemp = currentItem * 330 - 660;
			newLocation = newLocationTemp - newLocationTemp - newLocationTemp;
			$('.portfolioSlider').animate({"left":newLocation});
			currentItem--;
		}
			return false;
	});
		
	
  	$('ul.nav a[href*=#]').click(function() {
	  $('ul.nav li').removeClass('active');
	  $(this).parent('li').addClass('active');
	 	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	  		var $target = $(this.hash);
	   		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
	   		if ($target.length) {
	  			var targetOffset = $target.offset().top - 85;
	  			$('html,body').animate({scrollTop: targetOffset}, 1000);
	    		return false;
	  		}
	 	}
	});
	
	$('#banner a.bannerPortfolioLink').click(function() {
	  $('ul.nav li').removeClass('active');
	  $('ul.nav li a.myPortfolio').parent('li').addClass('active');
	 	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	  		var $target = $(this.hash);
	   		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
	   		if ($target.length) {
	  			var targetOffset = $target.offset().top - 50;
	  			$('html,body').animate({scrollTop: targetOffset}, 1000);
	    		return false;
	  		}
	 	}
	});




	// These first three lines of code compensate for Javascript being turned on and off. 
	// It simply changes the submit input field from a type of "submit" to a type of "button".
	
	var paraTag = $('input#submit').parent('p');
	$(paraTag).children('input').remove();
	$(paraTag).append('<input type="button" name="submit" id="submit" value="&nbsp;" />');
	
	$('p.submit input#submit').click(function() {
	   	$('p.submit #submit').hide();
	    $('p.submit').append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');
	
	    var name = $('input#name').val();
	    var email = $('input#email').val();
	    var message = $('textarea#message').val();
	
	    $.ajax({
	        type: 'post',
	        url: './sendEmail.php',
	        data: 'name=' + name + '&email=' + email + '&message=' + message,
	
	        success: function(results) {
	            $('p.submit img.loaderIcon').fadeOut(100);
	    		$('p.submit #submit').fadeIn(1000);
	            $('ul#response').fadeIn();
	            $('ul#response').html(results);
	        }
	    }); // end ajax
	});


});