		$(document).ready(function(){
			
				$('a.blank').click(function(){
			        window.open(this.href);
			        return false;
			    });
		    
				
				$(window).resize(function(){ resize_window(); });
				
				set_up();
				
				
				$('a#details_show').click(function(){
						
						$('#how-to-find, #get-in-touch').hide("fast", function(){ $('#your_details').fadeIn(); });
						return false;
				});
				
				$('a#details_return').click(function(){
						
						$('#your_details').hide("fast", function(){ $('#how-to-find, #get-in-touch').fadeIn(); });
						return false;
				});				
				
				$('a.close').click(function(){
				
						close_panel();
						return false;
				});
				
				$('#from_here').focus(function(){
				
					if($(this).val()==$(this)[0].defaultValue){
						$(this).val('');
					}
					 
				})
				.blur(function() { 
					if( $(this).val().length < 1 ) {$(this).val($(this)[0].defaultValue);}
				});
				
				
				
				$('.loadPerma').click(function(){
						
						var link=$(this).attr('href').replace('http://mnatwork.com/', '');
						document.getElementById("app").loadPermalink(link);
						close_panel();
						return false;
				});

	

			});
			

			
			function contact_form(){
					$('#cForm').submit(function(){ 
										$(this).preventDefault();
								});
						
					$("#cForm input#cSubmit").click(function(){send_mail();return false;});
					
					$('.inputText').focus(function(){
				
					if($(this).val()==$(this)[0].defaultValue){
						$(this).val('');
					}
					 
				})
				.blur(function() { 
					if( $(this).val().length < 1 ) {$(this).val($(this)[0].defaultValue);}
				});		
			}
			
			function set_up(){
								$('#secret_garden, #about_us, #contact, #your_details').hide();
								resize_window();
				}
				
				function send_mail(){
		
		
				//// Check the values
				
				var hasError = false;
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				
				$("p.error").remove();
				
				var emailToVal = $("#Contact_email_address").val();
				
					if(emailToVal == '' || emailToVal == 'Email') {

						$("#Contact_email_address").after('<p class="error">Hmmm - you might want to check that email field.</p');
						hasError = true;
					} else if(!emailReg.test(emailToVal)) {
						$("#Contact_email_address").after('<p class="error">Hmmm - you might want to check that email field.</p>');
						hasError = true;
					}
				
				var nameVal = $("#Contact_name").val();
					if(nameVal == '' || nameVal == 'Name') {
						$("#Contact_name").after('<p class="error">That\'s not your name...</p>');
						hasError = true;
					} 
				
				var typeVal = $("#Contact_enquiry_type").val();
				
				var messageVal = $("#Contact_enquiry").val();
				
				if($('#cOptIn:checked').length) {
 					
 					var OptInVal="yes";
 					
				}else{
					var OptInVal="no";
				}
				
				if(hasError == false) {
					$('#cSubmit').attr('disabled', 'disabled'); 
					$.post( 
					"/contact.new.php",
					{ Contact_name : nameVal, Contact_email_address: emailToVal, Contact_enquiry_type: typeVal, addtomail: OptInVal, Contact_enquiry: messageVal} ,
			  		function(message){ 
				        		
				        		$("#cForm").hide();
				        		if (message.length > 0){  $('#contact_form').append(message);} 
				    		
				    		},
				    "html"		    		
					);}
				}

				
				function close_panel(callback){
						$('.shut_the_doors').hide();
						$('#app').animate({ top: 0 }, "fast", "swing", callback);				
				}
				
				function open_panel(panel){
					reset_contact();
					var closed="";
					switch(panel){
						case 'contact':
							var height= 540;
						break;
						case 'about_us':
							var height= 460;
						break;
					}
					
					
					if($('#secret_garden').is(":hidden")){
						
						$('#app').animate({ "top": '-'+ height } , "fast", "swing", function(){
										$('#secret_garden').show();
										$('#secret_garden').css('height',height);
										$('#'+ panel).show();
										if(panel == "contact"){ show_map(); }
							});
					} else if($('#' + panel).is(":visible")) {
						close_panel();
					}else{
						close_panel(function(){
						$('#app').animate({ "top": '-'+ height } , "fast", "swing", function(){
											$('#secret_garden').show();
											$('#secret_garden').css('height', height);
											$('#'+ panel).show();
											if(panel == "contact"){ show_map();}
											
								});
						});
							
					
					}
				}
				
				
				function reset_contact(){
						$('#how-to-find, #get-in-touch').show();
						$('#your_details').hide();
						$('#contact_form').load("/contact.new.php",'', function(){contact_form();});
						
				}
			
				function resize_window(){
						if($.browser.msie){
							var width=$(window).width();
							var height=$(window).height();
							
							$('#app').css({'width': width, 'height':height});
						}
				}
				
				function load_default_directions(){
						$('#find-directions').load("/directions.php",'', function(){
							
							$('#st_peters').click(function()
							{ 
								
								static_directions('St Peter\'s Square, Manchester');
								$('#find-directions').append('<p><a href="#" class="directions_back">&laquo; Back</a></p>');
								back_to_map();
								return false;
								 
								
								
							});
							
							$('#manc_picc').click(function()
							{ 
								
								static_directions('Manchester Piccadilly, Manchester, UK');
								$('#find-directions').append('<p><a href="#" class="directions_back">&laquo; Back</a></p>');
								back_to_map();
								return false;
								
								
							});
							
							$('#car_park_1').click(function()
							{ 
								
								static_directions('6 Minshull Street, Manchester, UK');
								add_back_to_map();
								back_to_map();
								return false;
								
								
							});
							
							$('#car_park_2').click(function()
							{ 
								
								static_directions('Chorlton Street, Manchester, M1, UK');
								add_back_to_map();
								back_to_map();
								return false;
								
								
							});
							
							
						});
						
						
				}
				
				function add_back_to_map(){
					$('#find-directions').append('<p><a href="#" class="directions_back">&laquo; Back</a></p>');
				}
				
				function back_to_map(){
						
						$('.directions_back').click(function()
							{ 
								show_map();
								return false;
							});
				}
