$(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 == numberOfPortfolioItems;
			$('.portfolioSlider').animate({"left":"0px"});
		} else {
			newLocationTemp = currentItem * 330 - 660;
			newLocation = newLocationTemp - newLocationTemp - newLocationTemp;
			$('.portfolioSlider').animate({"left":newLocation});
			currentItem--;
		}
			return false;
	});
	
	// Added by MX, 21.11.2011
	$('.portfolioRightSide').click(function() {
		if(currentItem == numberOfPortfolioItems - 2) {
			currentItem = 0;
		}
		newLocationTemp = currentItem * 330;
		newLocation = newLocationTemp - newLocationTemp - newLocationTemp;
		$('.portfolioSlider').animate({"left":newLocation});
		currentItem++;
	
		return false;
	});
	// Added by MX, 21.11.2011
	$('.portfolioLeftSide').click(function() {
		if(currentItem == 1) {
			currentItem = numberOfPortfolioItems - 1;
		} 
		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 - 50;
	  			$('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;
	  		}
	 	}
	});

	// Name
	$('input#name').focus(function() {
		if($(this).attr("value") == "Name") { $(this).attr("value",""); }
	});
	$('input#name').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Name"); }
	});
	// Email
	$('input#email').focus(function() {
		if($(this).attr("value") == "Email") { $(this).attr("value",""); }
	});
	$('input#email').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Email"); }
	});
	// Phone
	$('input#phone').focus(function() {
		if($(this).attr("value") == "Phone") { $(this).attr("value",""); }
	});
	$('input#phone').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Phone"); }
	});
	// Message
	$('textarea').focus(function() {
		if($(this).attr("value") == "Message") { $(this).attr("value",""); }
	});
	$('textarea').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Message"); }
	});
	
	// 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="SEND MESSAGE" style="color:#ffffff; padding-bottom: 8px; font-size: 16px;" />');
	
	$('p.submit input#submit').click(function() {
		$('p.submit #submit').hide();
		$('p.submit').append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');
		
		var challengeField = $("input#recaptcha_challenge_field").val();
            	var responseField = $("input#recaptcha_response_field").val();
		var name = $('input#name').val();
		var email = $('input#email').val();
		var phone = $('input#phone').val();
		var message = $('textarea#message').val();
		
		$.ajax({
			type: 'post',
			url: './sendEmail-eng.php',
			data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&message=' + message + "&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
			
			success: function(results) {
				$('p.submit img.loaderIcon').fadeOut(100);
				$('p.submit #submit').fadeIn(1000);
				$('ul#response').fadeIn();
				$('ul#response').html(results);
			}
		}); // end ajax
		
		Recaptcha.reload();
	});


});

