
var loginurl
var stat


function setuser(){
		return
			$("#erroruser").html("");
		
				$.post("_files/script/action.php", {adduser: "/reset"  }, function(data){
			

				$("#booklayout").html(data) 
				$("#newuser").val("");
				$("#newuser").focus();
			
			} );
		
	};
	
	

	function flashdiv() {

		var flashhtml = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " +
					"codebase='http://download.macromedia.com/pub/shockwave/" +
					"cabs/flash/swflash.cab#version=6,0,40,0' name='mymoviename'" +
					" width='683' height='85' " +
					"id='mymoviename'> " +
					"<param name='movie'  value='_files/flash/flash.swf' /> " +
					"<param name='quality' value='high' /> " +
					"<param name='wmode' value='transparent' /> " +
					"<embed  src='_files/flash/flash.swf' quality='high' wmode='transparent' width='683' height='85' name='mymoviename' align='' type='application/x-shockwave-flash'  pluginspage='http://www.macromedia.com/go/getflashplayer'> " +
					"</embed> </object> ";
		$("#flashdiv").html(flashhtml);
}

$(document).ready(function(){
					
					
				$(".divsubs").show();

						   
						   
						   
						   
						   
						   
			$('.menu1').ptMenu();	
			
	 $("#namearr").attr("src" , loginurl );
	$("ul.menu_body li:even").addClass("alt");
  
	$(".btn-slide").click(function(){
								  
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); 
	
			if ( stat == '0'){
				stat = '1';
				$("#namearr").css("display", "none");
				$("#namearr").css("top", "19px");
				
				
									$("#namearr").attr("src" , loginurl );
				 $("#lgbtn").animate({ 
					height: "46px"
 					 }, 500 , function() {
						$("#namearr").css("display", "block");
		  });
		}else{
			stat = '0';
				
			
			$("#namearr").css("display", "none");
				$("#namearr").css("top", "5px");
				
				
			$("#namearr").attr("src" , "_files/images/default/sluiten.png" );
	
				 $("#lgbtn").animate({ 
				height: "20px"
 			 }, 500 , function() {
				 
				 
				$("#namearr").css("display", "block");
		  });
	
		
			
		}
	});
	
	 	
			
});

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);



$(function(){

	$('#d a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:250})
			
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		


});


$(document).ready(function(){

			
	$('img.resize').click(function(){
		$("#resizeimg").css("background-image", "none");
		$("#showimg").show();
		var src = $(this).attr("src");
		$.post("_files/script/action.php", {getsize: src}, function(data){
				var height = data.height;
				var width = data.width;	
				var marginleft = (width/2);
				var margintop = (height/2);
				var css = {
						"width" : width + "px",
						"height" : height + "px",
						"margin-top": "-" + margintop + "px",
						"margin-left" : "-" + marginleft + "px",
						"background-image" :  "url(" + src + ")"
				}//(height/2)(width/2)
		$("#resizeimg").css(css);
		}, "json");
		
	
	});
	
	$("#showimg").click(function(){
		
		$("#showimg").hide();
	});
		

	
var mailc = 0;
var userc = 0;
var pass = 0;
var curselec = 0 
var act = 0;
$("#sendreg").live('click', function(){
		
		var form = $("#regform").serialize();
		x = 0;
		
	

		if (mailc == 0 && userc == 0 && pass == 0 ) {
		
		
		$('#regform :input[alt=*]').each(function(i) {
				var curval = $(this).val();
				var curname = $(this).attr("name");
				if (curval == "") {
			
		
			var pos =  $(this).position();  
			var width =  $(this).width();
			$(this).css("border", "1px solid red");
			$(this).parent().next().html("<-- Onjuiste invoer!");
			//$(this).closest("td").html("Fout!");
			
			// balloonshow(pos, width, "Onjuist ingevuld!", "error_"+curname);
			 x++;
				};
      		  
   		 });
		 
		 
		if (x == 0 && act == 0) {
			act = 1;
			alert("requested");
			$.get("_files/script/action.php?add_user=true&" + form ,  function(data){
				
				$("#blackmodal").css("display", "none");
				
  				 if (data == 0){
					 
					 	// reqoff(curselec)	  
							$("#frametrim").animate({ 
										top: '-2283'
									  }, 2000, function() {
									  });
								   $("#curstep").html("4");	
	  								 $(".btn_left").css("display", "none");
	 								 $(".btn_right").css("display", "none");
									 
				 } else {
					
					 $("#username").val($("#reg_pass").val());
					 $("#password").val($("#reg_user").val());
					 loginbtn()
					 //showal(data)
					 
				 }
 					});
			
		}
		
		
		}

		
		
	});
	
	
	
	
	$("#send_new_reg").live('click', function(){
		
		var form = $("#regform").serialize();
		x = 0;
		
	

		if (mailc == 0 && userc == 0 && pass == 0 ) {
		
		
		$('#regform :input[alt=*]').each(function(i) {
				var curval = $(this).val();
				var curname = $(this).attr("name");
				if (curval == "") {
					$(this).css("border", "1px solid red");
					//$(this).closest("td").html("Fout!");
					
					// balloonshow(pos, width, "Onjuist ingevuld!", "error_"+curname);
					 x++;
				};
      		  
   		 });
		 
		 
		if (x == 0 && act == 0) {
			act = 1;
			$.get("_files/script/action.php?add_user=true&" + form ,  function(data){
				if (data == "success"){
					$("#user_reg_form").html("U heeft met success geregistreerd. <br /> Voordat we de registratie kunnen voltooien dient u uw account te verifieren doormiddel van een link die wij <br /> naar u toe hebben gemailt!");
				} else{
					
					alert(data);
				}
 					});
			
		}
		
		
		}

		
		
	});
var mouse_is_inside = false;
var mouse_is_inside_book = false;

	
	$(document).click(function(){
	
			
			
			
		
		
		if ($("#namearr").attr("src") == "_files/images/default/sluiten.png" ){
			stat = '1';
			$("#namearr").css("display", "none");
			$("#namearr").attr("src" , loginurl );
				$("#panel").slideUp("slow");
					 $("#lgbtn").animate({ 
						height: "46px"
						 }, 500 , function() { $("#namearr").css("top", "19px");  $("#namearr").css("display", "block");});
		}
});
 $('#showfriend').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });


	$("#panel").click(function(e){
   		 e.stopPropagation();
	});

	$("#lgbtn").click(function(e){
   		 e.stopPropagation();
	});

    $(document).mouseup(function(){ 
        if(! mouse_is_inside) $('#showfriend').hide();
    });

	 
						   $(".date").mouseover(function () {
  					  $(this).css("color","red");
 			 });
							   
		 if($.browser.msie){
     
     	$("img.a").hover(
	 
		function() {
				
				    
				//$(this).hide();
		},
		function() {
		               
				  
				//$(this).show();
							 
		});
     
   }else{
   
							   
		$("img.a").hover(
	 
		function() {
				
				$(this).stop().animate({"opacity": "0"}, "medium");
				$(this).parents('div.fadehover').css("background-image", "url(/_files/images/park/btn_back_act.png)");
		},
		function() {
		
				$(this).stop().animate({"opacity": "1"}, "medium");
				$(this).parents('div.fadehover').css("background-image", "url(/_files/images/park/btn_backl.png)");
							 
		});
    
      
   }
					   
    
    
//						   $.ajax({
//  url: "_files/script/action.php",
//  data: "h_date=true",
//  dataType: "json",
//    success: function(calendarEvents){ 
//           $(".calendarwidget'").datepicker({
//
//           // [rows, columns] if you want to display multiple calendars.                         
//           numberOfMonths: [1, 1],
//           showCurrentAtPos: 0,
//           beforeShowDay: function (date){
//                          for (i = 0; i < calendarEvents.length; i++) {
//                              if (date.getMonth() == calendarEvents[i][0] - 1 
//                              && date.getDate() == calendarEvents[i][1]
//                              && date.getFullYear() == calendarEvents[i][2]) {
//                              //[disable/enable, class for styling appearance, tool tip]
//                              return [false,"ui-state-active","Event Name"]; 
//                              }
//                           }
//                           return [true, ""];//enable all other days
//                        }
//           });
//           }
//         });
//						   
		$(".trip").click(function(){
                                   //Get the id of this clicked item
                           $("#ajax_load").css('display', 'block');
                                  pos = this.id;
				$.post("_files/script/action.php", { tripid: pos },
  					 function(data){
						  $("#modal_bus").attr("innerHTML", data);
                           $("#ajax_load").css('display', 'none');
					 });
                                 
     });
	
////modal
//select all the a tag with name equal to modal
	$('.offid').click(function(e) {
		
		                 $("#ajax_load").css('display', 'block');
                                  pos = this.id;
				$.post("_files/script/action.php", { tripid: pos },
  					 function(data){
						  $("#modal_bus").attr("innerHTML", data);
                           $("#ajax_load").css('display', 'none');
					 });
                              
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('id');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', (winW/2-$(id).width()/2) - 140);
	
		//transition effect
		$(id).fadeIn(10); 
	
	});
			$("#logbtn").click(function(){
				alert("1");
				loginbtn()
			});		
			

			
			$("#outbtn").click(function(){
									
				
					changescroll();
			});
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	



/////endmodal
			$("#outbtn").click(function(){
					
					changescroll();
			});
							
							
					    //switchText()
  											$("#popballoon").css("display", "none");
											
											
											$('#panel').keypress(function(event) {
																		   
														  if (event.keyCode == '13') {
    														loginbtn()
														  
														
 											  }
				   
																		   

									
	
			
			

			
			
			
			
});
			
/////////function scroll


function changescroll(){
		$.post("_files/script/action.php", { logout : 'true' },  function(data){	
							var href = "http://www.aletotouringcars.nl/";
								
												$("#historybooking").html("U dient hiervoor ingelogd te zijn!");
										$("#agendalogerror").css("display", "block");	
										$("#tab_log").css("display", "none");		
										
											
												if  ($("#conttabel").length != 0 ) {
															$("#con_name").val("");
															$("#con_tel").val("");
															$("#con_firm").val("");
															$("#con_mail").val("");
												}
														  	if ($("#curtitle").length != 0){
					
								//alert("mijn ritten2!");
							$("#rittenid").html(" <div><div style='text-align:center'>U dient ingelogd te zijn om deze gegevens weer te geven! </div></div> ");
				
				};	
						
				
														$("#panel").slideToggle("slow");
					loginurl = "_files/images/default/inloggen.png";
										stat = '0';
				$("#namearr").css("display", "none");
				$("#namearr").css("top", "19px");
				
				
									$("#namearr").attr("src" , loginurl );
				 $("#lgbtn").animate({ 
					height: "46px"
 					 }, 500 , function() {
						$("#namearr").css("display", "block");
						$.post( "_files/include/login.php", { username: $("#username").val() },
  													 function(data){ 
														 $("#panel").attr("innerHTML", data);
														
														 	stat = '1';
													 });
		  });
	 })
	
}




function loginbtn(){
	$.post("_files/script/action.php", { username: $("#username").val(), password: $("#password").val() },
  					 function(data){
						 
						 
    							if (data.length >= 2){
									//alert(data);
									Set_Cookie( 'tourlog', data, 1, '', '', '' );
										setuser();
										stat = '0';
										$("#popballoon").css("display", "none");
											loginurl = "_files/images/default/account.png";
										$("#agendalogerror").css("display", "none");	
										$("#tab_log").css("display", "block");	
											$("#namearr").css("display", "none");
											$("#namearr").css("top", "19px");
											$("#panel").slideToggle("slow");
											$("#namearr").attr("src" , loginurl );
											 $("#lgbtn").animate({ 
												height: "20px"
												 }, 500 , function() {
													$.post( "_files/include/login.php", { username: $("#username").val() },
  													 function(data){
														 
														$("#panel").attr("innerHTML", data);
														$("#namearr").css("display", "block");
														
														$('#panel #outbtn').click( function(){changescroll();});
														//////Toggle down agani
														$("#panel").slideToggle("slow");
														stat = '0';
			
			$("#namearr").css("display", "none");
				$("#namearr").css("top", "5px");
				
			
			$("#namearr").attr("src" , "_files/images/default/sluiten.png" );
	
				 $("#lgbtn").animate({ 
				height: "20px"
 			 }, 500 , function() {
				 
				 
				$("#namearr").css("display", "block");
				
				
			
		  });
														
													
									  				});	
									  });
								if  ($("#conttabel").length != 0 ) {
					
					$.post("_files/script/action.php", { getinfo : 'true' },  function(data){
						$("#con_name").val(data.person);
						$("#con_tel").val(data.tel);
						$("#con_firm").val(data.firm);
						$("#con_mail").val(data.mail);
					}, "json");
					
				};
				
				if ($("#historybooking").length != 0){
					
					
						
					$.post("_files/script/action.php", {reg_history: 'true'}, function(data){
							
						$("#historybooking").html(data);
					
					});
				};
				
				
				if ($("#curtitle").length != 0){
					
					$.post("_files/script/action.php", {getrit: 'true'}, function(data){
						
								$("#rittenid").html(data);
							});
					
				};
								}else if (data == 1){
									balloon("#password", "Foute Wachtwoord!")
								}else if (data == 0){
									balloon("#username", "Foute Gebruikersnaam!")
								}else{
									alert("Global error");
								}
							
							
							
  						 });
}

function balloon(div, msg){
	var pos = $(div).offset();
									$("#popballoon").css("left", (pos.left-134));
									$("#popballoon").css("top", pos.top);
									$("#popballoon").css("display", "block");
									$("#popballoon").html(msg);
									$(div).focus();
									$(div).select();
									$(div).bind('blur', function() {
  											$("#popballoon").css("display", "none");
									});

}


function switchText()
{
	if ($(this).val() == $(this).attr('title'))
		$(this).val('').removeClass('inputtext');
	else if ($.trim($(this).val()) == '')
		$(this).addClass('exampleText').val($(this).attr('title'));
}

$('input[title!=""]').each(function() {
	if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
	if ($(this).val() == $(this).attr('title')) $(this).addClass('inputtext');
}).focus(switchText).blur(switchText);


});

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


jQuery(function($){
	$.datepicker.regional.nl = {
		closeText: 'Sluiten',
		prevText: '←',
		nextText: '→',
		currentText: 'Vandaag',
		monthNames: ['januari', 'februari', 'maart', 'april', 'mei', 'juni',
		'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
		monthNamesShort: ['jan', 'feb', 'maa', 'apr', 'mei', 'jun',
		'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
		dayNames: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
		dayNamesShort: ['zon', 'maa', 'din', 'woe', 'don', 'vri', 'zat'],
		dayNamesMin: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
		weekHeader: 'Wk',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional.nl);
});

function loginsep(user, pass) {
	 $.post("_files/script/action.php",  {username: user, password: pass}, function(data){
								if (data.length >= 2){
									checkdivs("login")
											loginurl = "_files/images/default/account.png";
																
											$("#namearr").attr("src" , loginurl );
											$("#blackmodal").css("display", "none");	
											$("#regmodal").css("display", "none");	
											$.post( "_files/include/login.php", { username: $("#user_reg_form").val() },
  													 function(data){
														 
														 $("#panel").attr("innerHTML", data);
														$("#namearr").css("display", "block");
												});	
												
												
								}else if (data == 1){
									alert("Foute Wachtwoord!")
								}else if (data == 0){
									alert("Foute Gebruikersnaam!")
								}else{
									alert("Global error");
								}
		
												 
			}
	);
}

function checkdivs(par){
	
	if (par  == "login") {
		$("#agenda_login").hide();
		$("#tab_log").show();
		setuser();
		$("#sendcmt").show();
	}
		
	
}
//////
// JavaScript Document
