function textReplacement(input){
	var originalvalue = input.val();
	input.focus(function() {
		if($.trim(input.val()) == originalvalue) {
			input.val('');
		}
	});
	
	input.blur( function() {
		if($.trim(input.val()) == '') {
			input.val(originalvalue);
		}
	});
}

function sendInter() {
	var
	name = $('#intName').val(),
	company = $('#incCompany').val(),
	email = $('#intEmail').val();
	date = $('#date').val();
	topic = $('#topic').val();
	time = $('#time').val();
	
	$.ajax({
		type: "post",
		url: "inter-form.php",
		data: "name=" + name + "&company=" + company + "&email=" + email + "&date=" + date + "&topic=" + topic + "&time=" + time,
		success: function () {
			$('#interForm').slideToggle(function() {
				$('#okInter').slideToggle();
			});
		}
	});
	return false;
}

function sendMail() {
	var
	name = $('#name').val(),
	telefon = $('#telefon').val(),
	email = $('#email').val(),
	comment = $('#message').val();
	
	$.ajax({
		type: "post",
		url: "contact-form.php",
		data: "name=" + name + "&telefon=" + telefon +"&email=" + email + "&comment=" + comment,
		success: function () {
			$('.contentContact .second').css('border', 'none');
			$('form#contactForm').hide(function() {
				$('.okContact').fadeIn();
			});
		}
	});
	return false;
}

$(document).ready(function() {
	$('li.contentContact .address a.stillsMail').attr('href', 'mailto:siv@stills.no').html('<strong>siv@stills.no</strong>');
	$('li.contentTrans a.sendFiles').attr('href', 'mailto:siv@stills.no');
	$('#contactForm').validate({
		errorElement: 'span',
		errorClass: 'validatorMessage',
		errorPlacement: function(error) {
			$('#contactErr').html(error);
		},
		success: function(label) {
			label.html('&nbsp;').addClass('success');
		},
		rules:
		{
			email: { email: true }
		},
		messages: {
			email: { email: 'Ugyldig e-post adresse' }
		},
		submitHandler: function() {
			$('#contactSubmit').attr('disabled', 'disabled');
			sendMail();
		}
	});
	
	$('#interLayer').css('left', $(window).width()/2-$('#interLayer').width()/2);
	$('#overlay').css('height', $(document).height());
	
	$('a.hireMe').click(function() {
		$('#overlay').fadeTo('300', 0.7);
		$('#interLayer').fadeIn();
		return false;
	});
	
	$('#overlay, .closeLayer').click(function() {
		$('#overlay').fadeOut('slow');
		$('#interLayer').fadeOut('slow', function() {
			$('#interForm').show();
			$('#okInter').hide();
			$('.layerSubmit .spinner').hide();
			$('#interSubmit').removeAttr('disabled');
		});
		return false;
	});
	
	$('#interSubmit').click(function() {
		$('#interSubmit').attr('disabled', 'disabled');
		$('.layerSubmit .spinner').fadeIn('fast');
		sendInter();
		return false;
	});
	
	$('#mainMenu a').hover(function() {
		var e = this;
		$(e).find('.slider').stop().animate({backgroundPosition:'0 -29px'}, 200, function() {
			$(e).find('.slider').animate({backgroundPosition:'0 -26px'}, 150);
		});
	}, function() {
		var e = this;
		$(e).find('.slider').stop().animate({backgroundPosition:'0 3px'}, 200, function() {
			$(e).find('.slider').animate({backgroundPosition:'0 0'}, 150);
		});
	});
	
	$('#slider').anythingSlider({
		easing: "easeInOutExpo",
		autoPlay: false,
		animationTime: 600,
		hashTags: false,
		buildNavigation: false,
		navigationFormatter: null
	});
	
	$('.contentContact.cloned #contactForm').remove();
	
	textReplacement($('#name'));
	textReplacement($('#email'));
	textReplacement($('#company'));
	textReplacement($('#message'));
	textReplacement($('#intName'));
	textReplacement($('#incCompany'));
	textReplacement($('#intEmail'));
	textReplacement($('#topic'));
	textReplacement($('#date'));
	textReplacement($('#time'));
	
	$('#mainMenu a').click(function() {
		$('#slider').anythingSlider(parseFloat($(this).attr('rel')));
		return false;
	});
	
	$('a[rel="external"]').attr('target','_blank');
	
});


