
var loaded_one=false;	
check=false;
var old_menu_pos;
var new_menu_pos;
var menu_array = [
	'/home',
	'/lab/introductie',
	'/lab/biomechanische-screening',
	'/lab/labotesten',
	'/lab/voedingsanalyse',
	'/lab/voedingssuppletie',
	'/lab/inspanningstesten',
	'/lab/coaching',
	'/team',
	'/media/lab',
	'/media/sporters',
	'/media/videos',
	'/partners',
	'/contact'
];					
function showNewsletter(){
	$('#newsletter').animate({
    	bottom: '-1'  
    }, 500, function() {
    	$('#nl-email').focus();
    });
}
function hideNewsletter(){
	$('#newsletter').animate({
    	bottom: '-192'  
    }, 500, function() {
   		$('#nl-email').focus();
    });
}
function replaceAll(txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
}

function getContent(src) {
	if(src.substring(0,5)=="/news"){
		ttl="/news";
	}else{
		ttl=src;
	}
	if(src=="/contactform"){
		ttl="/contact"
	}
	title=replaceAll(replaceAll(ttl,"-"," "),"/"," | ");	
	document.title= "Preventielab"+title;
	if($.browser.msie){
		$('#content_1').css({width:'450px', position:'relative', 'overflow-y':'auto',paddingBottom:50});
		$('#box_content').css({'overflow-y':'hidden'})
		$("#content_1").load('getData.php?hash='+src+' #content-info', function(){
			if($("#slider > img").size()>=2){
		    	$('#slider img:first').fadeIn(300, function() {
       				$('#slider').cycle({
       				 	after:  function(){
        					$('#slider').addClass("slider_new");
        		    	}
        			});
        		});
			}else{
				$('#slider > img').fadeIn();		
			}
			$("form#contactform").validate({
				submitHandler: function(form) {
					var naam     = $('#naam').attr('value');  
     				var email    = $('#email').attr('value');  
    				var telefoon = $('#telefoon').attr('value');  
     				var vraag    = $('#vraag').attr('value');  
     				var boodschap= $('#boodschap').attr('value');  
        			$.ajax({  
             			type: "POST",  
             			url: "http://www.preventielab.be/sendform.php",  
             			data: "naam="+ naam +"&email="+ email+"&telefoon="+ telefoon+"&vraag="+ vraag+"&boodschap="+ boodschap,  
        			   	success: function(html){  
       					   	//alert(html);
       			    	 	$('#contactform').html("<div id='message'></div>");  
     						$('#message').html("<div class='content-subtitle'>Contact formulier verzonden!</div>")  
   								.append("<p>We contacteren u zo snel mogelijk.</p>")  
								.hide()  
     							.fadeIn(1500);
     			
						}  
  	      			});  
        		}
			});
			$('#naam').focus();
			var centerTopEnd = (($(window).height()-$("#content_1").height()) / 2);
			if(centerTopEnd<=50){centerTopEnd=50;}
			var winHeight=$(window).height()-50-centerTopEnd;
			$("#content_1").css({top:0, height:winHeight,paddingTop:centerTopEnd,paddingBottom:50});
			//$('#content_1').css({'overflow-y':'scroll',paddingBottom:50});
		});
	}else{
		if(!check){
			var file = src.split(' ');
			new_menu_pos = $.inArray(file[0], menu_array);
			
  			check=true;
			if(loaded_one==true){
				var divCenter = "#content_1";
				var divBottom = "#content_2";
				loaded_one=false;
			}else{
				var divCenter = "#content_2";
				var divBottom = "#content_1";
				loaded_one=true;
			}	
			$(divCenter).css({position:'fixed'});
			$(divBottom).css({position:'fixed'});
			$(divCenter).load('getData.php?hash='+src+' #content-info', function() {
							$('#naam').focus();
				if(typeof(old_menu_pos)=='undefined'){
					old_menu_pos=123;
				}
				//alert(src+' '+old_menu_pos);
				if(new_menu_pos<old_menu_pos){
					var centerTopIni = 0 - $(divCenter).height()-250;
					var bottomTopEnd = $(window).height() + 250;
				}else{
					
					var centerTopIni = $(window).height() + 250;
					var bottomTopEnd = 0 - $(divBottom).height()-250;
				}
				
			//	var centerTopIni = 0 - $(divCenter).height()-250;
				var centerTopEnd = (($(window).height()-$(divCenter).height()) / 2);
				if(centerTopEnd<=50){centerTopEnd=50;}
				var bottomTopIni = $(divBottom).position().top;
				//var bottomTopEnd = $(window).height() + 250;
				$(divCenter).css({top:centerTopIni});
				$(divCenter).animate({top:centerTopEnd}, 1000, function(){
					$(divCenter).css({top:centerTopEnd});
					$(divCenter).css({position:'relative'});
					check=false;
				});
				$(divBottom).animate({top:bottomTopEnd}, 1000, function(){
					$(divBottom).empty();
					$(divBottom).css({top:centerTopIni});
					if($("#slider > img").size()>=2){
						$('#slider img:first').fadeIn(300, function() {
        					$('#slider').cycle({
					        	after:  function(){
        							$('#slider').addClass("slider_new");

					        	}
       	 					});
    					});
					}else{
						$('#slider > img').fadeIn();
						
					}
					$("form#contactform").validate({
						submitHandler: function(form) {
							var naam     = $('#naam').attr('value');  
     						var email    = $('#email').attr('value');  
    				 		var telefoon = $('#telefoon').attr('value');  
     						var vraag    = $('#vraag').attr('value');  
     						var boodschap= $('#boodschap').attr('value');  
        					$.ajax({  
             					type: "POST",  
             					url: "http://www.preventielab.be/sendform.php",  
             					data: "naam="+ naam +"&email="+ email+"&telefoon="+ telefoon+"&vraag="+ vraag+"&boodschap="+ boodschap,  
        					   	success: function(html){  
        					   	//alert(html);
        				    	 	$('#contactform').html("<div id='message'></div>");  
     								$('#message').html("<div class='content-subtitle'>Contact formulier verzonden!</div>")  
     									.append("<p>We contacteren u zo snel mogelijk.</p>")  
     									.hide()  
     									.fadeIn(1500);
     								var centerTopEnd = (($(window).height()-$(divCenter).height()) / 2);
									if(centerTopEnd<=50){centerTopEnd=50;}
									$(divCenter).animate({top:centerTopEnd}, 1000, function(){
										$(divCenter).css({top:centerTopEnd});
										$(divCenter).css({position:'relative'});
									});
								}  
  	    	  				});  
        				}
					});				
				});
				old_menu_pos=new_menu_pos;
				
			});
		}
	}
	
}

$(document).ready(function() {
	$('#image_holder').hide().fadeIn('slow', function() {
        resizeImage();
      });
});

