function sendMessage() {

var data = {
userName: $('#userName').val(),
userEmail: $('#userEmail').val(),
userMessage: $('#userMessage').val()
};
/*  ajax message sending  */
$.ajax({
data: data,
url: '/',
dataType: 'json',
type: 'post',					
success: function(response) { 
if (response.success) {
$('#get_in_touch .messageSentBlock').fadeIn(500);
} else {
/* error processing */      
}
}
});
}

function remove404() {
$(window).scroll(function() {
if ((($('html').scrollTop() ? $('html').scrollTop() : $('body').scrollTop()) + $(window).height()) < $('#page_not_found')[0].offsetTop) {
$('#page_not_found').remove();
$('.footer .line').eq(0).remove();
$(window).unbind('scroll');
changeAnchor();
}
});
}

function getHref() {
var href = document.location.href.split('#')[1] ? document.location.href.split('#')[1] : '';
if (href != '') {
var realHref = (href == 'home') ? 'home_' : href.replace(/-/g,'_');
var target_top = $('#' + realHref)[0].offsetTop;
$(document).scrollTop(target_top);

if (href.indexOf("_") != -1) {
document.location.replace( (href == 'home_') ? '#home' : ('#'+href.replace(/_/g,'-') ));
}
}
}

$(document).ready(function() {  
var notChangeAnchor = false;
function changeAnchor() {
$(window).scroll(function() { 
if (!notChangeAnchor) {
var changeLine = ($('html').scrollTop() ? $('html').scrollTop() : $('body').scrollTop()) + $(window).height()/2;
for(var i in sections) {
if (changeLine >= i) {
var currentSection = sections[i];
}    
}
if (currentSection != sections.current) {
sections.current = currentSection;
document.location.replace('#'+ sections.current);
}
}
});
}
getHref();
var sections = {};
sections.current =  document.location.hash.split('#')[1] ? document.location.hash.split('#')[1] : 'home';
$('body > div').each(function() {
if ($(this).attr('id')) {
sections[$(this)[0].offsetTop] = ($(this).attr('id') == "home_") ? "home" : $(this).attr('id').replace(/_/g,'-');
}
});
changeAnchor();

$(".scroll").click(function(event){
notChangeAnchor = true;
var full_url = this.href;
var parts = full_url.split("#");
var trgt = parts[1] ? parts[1] : '';
var trgtVis = (trgt == 'home_') ? 'home' : trgt.replace(/_/g,'-');
document.location.replace('#'+ (trgtVis ? trgtVis : ""));
sections.current = trgt;
if (trgt && $("#"+trgt).is('div')) {
var target_top = $("#"+trgt)[0].offsetTop;
} else {
var target_top = 0;
}
if (navigator.userAgent.toLowerCase().indexOf("webkit")!=-1) {
if (navigator.userAgent.indexOf('iPad') != -1 || navigator.userAgent.indexOf('iPhone') != -1) {
$(window).scrollTop(target_top);
} else {
$('body').animate({scrollTop:target_top + "px"}, 3000,function() {
notChangeAnchor = false;
});
}
} else {
$('html').animate({scrollTop:target_top + "px"}, 3000, function() {
notChangeAnchor = false;
});
}
return false;
});
});

/*$(document).ready(function(){
$(".popup").colorbox({width:"642px", height:"384px", iframe:true});
});
*/
