$(document).ready(function(){
	$('input, textarea').each(function() {
	   var default_value = this.value;
	   $(this).focus(function(){
		  if(this.value == default_value && this.value != 'SEND') {
			 this.value = '';
		  }
	   });
	   $(this).blur(function(){
		  if(this.value == '') {
			 this.value = default_value;
		  }
	   }); 
	});
	
	
	var SPEED = 400;
	//var PAGES = [320, 1850, 3370, 4800];
	var PAGES = [0, 0, 0, 0];
	var CURRENTPAGE = 0;
	
	
	var window_width = $(window).width();					  
	if(window_width >= 1900) {
		var window_center = 0;
		PAGES[0] = 0;
	} else {
		var window_center = (1920 - window_width)/2;
		PAGES[0] = window_center/2 + 200;
		$('html, body').animate({'scrollLeft': window_center/2 + 200}, 0);
	}
		
	PAGES[1] = 1520 + 150 + window_center/2;
	PAGES[2] = 1520*2 + 150 + window_center/2;
	PAGES[3] = 1520*3 + 150 + window_center/2;
	
	//$('#size').text('Window: ' + window_width + ' Half: ' + window_center );
	
	var window_height = $(window).height();
	if(window_height < 800) {
		$('body').attr('style','margin-top: -130px');
		$('.homePage ul').attr('style','top: -50px');
	}
	
		
	$(window).resize(function() {
							  
		var window_width = $(window).width();					  
		if(window_width >= 1900) {
			var window_center = 0;
			PAGES[0] = 0;
		} else {
			var window_center = (1920 - window_width)/2;
			PAGES[0] = window_center/2 + 200;
			$('html, body').animate({'scrollLeft': window_center/2 + 200}, 0);
		}
		PAGES[1] = 1520 + 150 + window_center/2;
		PAGES[2] = 1520*2 + 150 + window_center/2;
		PAGES[3] = 1520*3 + 150 + window_center/2;
		
		//$('#size').text('Window: ' + window_width + ' Half: ' + window_center );
			
	});
	
	
	// function start
	
	var goToPage = function(which) {
			if (which < 0) {
				which = 0;
			}
			if (which > PAGES.length - 1) {
				which = PAGES.length - 1;
			}
			$('html, body').animate({'scrollLeft': PAGES[which]}, SPEED);
	}
	
	// navigation buttons
	$('.boxNav, .nav-btn').live('click', function(ev) {
			CURRENTPAGE = this.id.replace(/btn|section/, '');
			goToPage(CURRENTPAGE);
			ev.preventDefault();
	});
	$('.nextBtn').live('click', function() {
		$('html, body').animate({'scrollLeft': PAGES[1]}, SPEED);
	});
	$('.contactBtn').live('click', function() {
		$('html, body').animate({'scrollLeft': PAGES[3]}, SPEED);
	});
	
	
	// show navigation
	var navIsHidden = false;
	$("#fixedNav").css({'top': '-150px'});
	$(window).scroll(function(ev) {
		var $n = $("#fixedNav");
		var sl = $(this).scrollLeft();
		for (var i = 0; i < PAGES.length - 1; ++i) {
			if (sl > PAGES[i]) {
				CURRENTPAGE = i + 1;
			}
		}
		if ($(this).scrollLeft() > 1450) {
			if (!navIsHidden) {
				navIsHidden = true;
				$n.animate({'top': '0px'}, SPEED);
			}
		}
		else {
			if (navIsHidden) {
				navIsHidden = false;
				$n.animate({'top': '-150px'}, SPEED);
			}
		}
		ev.preventDefault();
		ev.stopPropagation();
	});
	
	// mouse scroll
	$(window).mousewheel(function(ev, d) {
		var s = $(this).scrollLeft();
		$(this).scrollLeft(s - (d * 200));
		ev.preventDefault();
	});
	
	


});


