// JavaScript Document

$(document).ready(function() {
						   
	$('a[href*=#]').click(function(evt) {

		// duration in ms
		var duration=1000;

		// velocity in px/s
		var velocity=2;	// 20px/0.1s
		
		// easing values: swing | linear
		var easing='swing';
		
		// get / set parameters
		var newHash=this.hash;
		var target=$(this.hash).offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;
		
		// recalculating duration
		if (Math.abs(evt.pageY-target)<400) {duration=400;}
		else {duration=Math.round(Math.abs(evt.pageY-target)/velocity);}
		
		// make sure it's the same location      
		if (oldLocation+newHash==newLocation) {
			
			// set selector
			if($.browser.safari) var animationSelector='body:not(:animated)';
			else var animationSelector='html:not(:animated)';
			
			// animate to target and set the hash to the window.location after the animation
			$(animationSelector).animate({ scrollTop: target }, duration, easing, function() {
			
				// add new hash to the browser location
				window.location.href=newLocation;
			
			});
		
			// cancel default click action
			return false;
			
		}
		
	});
	
	inputFocusBlur("#contact_name","name");
	inputFocusBlur("#contact_email","e-mail");
	inputFocusBlur("#contact_phone","phone");
	inputFocusBlur("#contact_message","info");
	
	$("#contact_form").submit(function() {
		var serials=$(this).serialize()+"&ajax=1";
		$("#contact_cnt").html('<div class="contact_inputs"><div style="padding:112px 129px;"><img src="imgs/loader_contact.gif"></div></div>');
		$("#contact_cnt").load("?"+serials, function(response, status, xhr) {
			if (status == "error") {
				//var msg = "Sorry but there was an error: ";
				//alert(msg + xhr.status + " " + xhr.statusText);
			}
		});
		return false;
	});

});

function inputFocusBlur(obj,t) {
	$(obj).focus(function () {
		if($(this).attr('value')==t) {
			$(this).attr('value','')
		}
	});
	$(obj).blur(function () {
		if($(this).attr('value')=='') {
			$(this).attr('value',t)
		}
	});     
}
