 jQuery.noConflict();
     
     jQuery(document).ready(function(){
	     
    var options = { 
		target:     '#messages',
		success:    function(){
			myFollow();
		}
    };    
 
	
		
		jQuery('#logoutForm').live('submit', function(){

			jQuery.get('/smap/mapstart', function(){
				sMap.setUserId(0);						
			});			

			//jQuery('#logoutForm').submit();

			//return false;
		});  
		
		//jQuery('#wlpeLoginForm').bind('submit', prepareForm(jQuery('#wlpeLoginForm')));
	
	
	       jQuery('#fEmail').val('Enter your email');
       jQuery('#fEmail').click(function(){
            if(jQuery('#fEmail').val() == 'Enter your email'){
               jQuery('#fEmail').val('');
            }       
       });

jQuery('#wlpeLoginForm').addClass('hidden');
jQuery('#wlpeLoginForm').addClass('jsVersion');
jQuery('#wlpeLoginForm').addClass('jsVersion');

jQuery('<div id="userProfileDiv"></div><div id="login-reg-container"><p id="login-reg" class="showLogin"><a class="cleverlogin" href="#wlpeLoginForm">Login / Register</a></p><p class="descriptionlogin">Personalise, save and share your maps</p></div>').insertBefore('#wlpeLoginForm');
jQuery('<a class="closeLogin" href="#close" title="Close form"><img src="/assets/templates/sustrans/images/user_login_close.gif"/></a>').appendTo('#wlpeLoginForm');

jQuery('.showLogin a').click(function(){
	jQuery('#wlpeLoginForm').removeClass('hidden');
return false;
});
jQuery('.closeLogin').click(function(){
	jQuery('#wlpeLoginForm').addClass('hidden');
return false;
});

	var service = '';
	var errMsg = '';
		
		prepareForm(jQuery('#wlpeLoginForm'));

		jQuery('#wlpeLoginForm').live('submit', function(){
			//console.log('One');
			prepareForm(jQuery(this));
			//console.log('Two');
			/*jQuery.get('/smap/mapstart?'+userToken2+''+walkingSpeed2+''+cyclingSpeed2+'', function(){
					sMap.setUserId(userId2)				
			});*/

			return false;
		});
	
});


		function prepareForm(myForm){
			myForm.ajaxForm({
				
				// target identifies the element(s) to update with the server response 
				target: '#loginErrors', 
				
				//url: '/ajax-submit.php',
				url: '/user-details?user=true',
			 
				// success identifies the function to invoke when the server response 
				// has been received; here we apply a fade-in effect to the new content 
				success: taconiteFollowUp
			}); 
			
			
			//return false;
			
		}

function myFollow(responseText){
	alert(responseText);
}

var service = 'login';

function taconiteFollowUp(responseText){
	//alert('taconiteFollowUp Running');
	//console.log(responseText);
	
			//console.log('ten');
	
	if (service == 'login')
	{
		if (responseText == '')
		{
						
		}
		else
		{
			//jQuery('<div class="loadingOver" style="position:absolute;left:0;top:0;background:#000;opacity:0.4;filter:alpha(opacity=40);width:100%;height:100%;z-index:10000;"><img style="position:absolute;left:-110px;margin:200px 0 0 50%;" src="/assets/templates/sustrans/images/loading.gif"/></div>').insertBefore('.wrapper');
			var cyclingSpeed = jQuery("input[name='cyclingSpeed']").val();
			var walkingSpeed = jQuery("input[name='walkingSpeed']").val();
			var userToken = jQuery("input[name='userToken']").val();
			var userId = jQuery("input[name='userId']").val();
			
			if(cyclingSpeed != ''){
				var cyclingSpeed2 = '&cycling_mph='+cyclingSpeed;
			}
			if(walkingSpeed != ''){
				var walkingSpeed2 = '&walking_mph='+walkingSpeed;
			}
			
			var userToken2 = '&session_id='+userToken;
			var userId2 = userId; 
			
			if(userId2 != ''){
				jQuery('#loginErrors').addClass('loginBox');
				jQuery('#loginErrors').css('z-index', '9999');

				jQuery.post('/smap/mapstart?'+userToken2+''+walkingSpeed2+''+cyclingSpeed2+'', function(){
				
				sMap.setUserId(userId2)
					
				});

				jQuery('#wlpeLoginForm').addClass('hidden');
				//jQuery('#wlpeLogin').remove();
			}
			
		}
	}
	else if (service == 'registernew')
	{
		jQuery('#wlpeUserButtons').hide();
		jQuery('#wlpeResetButtons').hide();
		jQuery('#wlpeLoginButtons').hide();
		jQuery('#wlpeRegisterButtons').show();
		
		jQuery('#wlpeLoginFieldset').animate({opacity: 'hide', height: 'hide'}, 'normal', function(){
			jQuery('#messages').slideUp('fast');
		});
		jQuery.get('taconite/register.xml', function(){
			jQuery('#wlpeLoginFieldset').animate({opacity: 'show', height: 'show'}, 'normal');
		});
	}
	else if (service == 'register' || service == 'resetpassword')
	{
		jQuery('#wlpeUserButtons').hide();
		jQuery('#wlpeResetButtons').hide();
		jQuery('#wlpeRegisterButtons').hide();
		jQuery('#wlpeLoginButtons').show();

		jQuery('#wlpeLoginFieldset').animate({opacity: 'hide', height: 'hide'}, 'normal', function(){
			//jQuery('#messages').slideUp('fast');
		});
		jQuery.get('taconite/logout.xml', function(){
			jQuery('#wlpeLoginFieldset').animate({opacity: 'show', height: 'show'}, 'normal');
		});
		
		jQuery('#messages').slideDown('normal', function(){
			jQuery('#messages').animate({opacity: 1.0}, 6000, function(){
				jQuery('#messages').animate({opacity: 'hide', height: 'hide'}, 'slow');
			});
		});
	}
	else if (service == 'forgot')
	{
		jQuery('#wlpeUserButtons').hide();
		jQuery('#wlpeResetButtons').show();
		jQuery('#wlpeLoginButtons').hide();
		jQuery('#wlpeRegisterButtons').hide();
		
		jQuery('#wlpeLoginFieldset').animate({opacity: 'hide', height: 'hide'}, 'normal', function(){
			jQuery('#messages').slideUp('fast');
		});
		jQuery.get('taconite/forgot.xml', function(){
			jQuery('#wlpeLoginFieldset').animate({opacity: 'show', height: 'show'}, 'normal');
		});
	}
	else if (service == 'profile')
	{
		location.href = 'profile.html';
	}
	else
	{
		if (responseText == '')
		{
			jQuery('#wlpeUserButtons').hide();
			jQuery('#wlpeResetButtons').hide();
			jQuery('#wlpeRegisterButtons').hide();
			jQuery('#wlpeLoginButtons').show();

			jQuery('#wlpeLoginFieldset').animate({opacity: 'hide', height: 'hide'}, 'normal', function(){
				jQuery('#messages').slideUp('fast');
			});
			jQuery.get('taconite/logout.xml', function(){
				jQuery('#wlpeLoginFieldset').animate({opacity: 'show', height: 'show'}, 'normal');
			});
		}
		else
		{
			jQuery('#messages').slideDown('normal', function(){
				jQuery('#messages').animate({opacity: 1.0}, 4000, function(){
					jQuery('#messages').animate({opacity: 'hide', height: 'hide'}, 'slow');
				});
			});
		}
	}
	
}