
var urlSignin = '/index.php/default/authorization/signin/format/html';
var urlRemind = '/index.php/default/authorization/remind/format/html';
var urlRegister = '/index.php/default/registration/index/format/html';


$(document).ready(function() {
	$('#signin-link').click(function(){
		$('#top-bar-box-wrapper').show();
		signin(urlSignin, 'GET');
		return false;
	});
	
	$('#register-link').click(function(){
		$('#top-bar-box-wrapper').show();
		register(urlRegister, 'GET');
		return false;
	});
	
	$('#close-link').click(function(){
		$('#top-bar-box-wrapper').hide();
		return false;
	});
});

function signin(url, type, data) {
	$.ajax({
		url: url, 
		global: false,
		type: type,
		data: data,
		beforeSend: function(){ $('#top-bar-box-content').prepend('<img style="width:50px; height:50px; margin:-25px 0 0 -25px; top:50%; left:50%; position:absolute;" src="/img/loading51.gif" alt="Ładuję..." />');},
		success: function(data) { 
			$('#top-bar-box-content').html(data);
			$('#signin-form').submit(function(){
				signin(url, 'POST', $('#signin-form').serialize());
				return false;
			});
			
			$('#remind-link').click(function(){
				remind(urlRemind, 'GET');
				return false;
			});
		},
		error: function(jqXHR, textStatus, errorThrown) {
			$('#top-bar-box-content').html(textStatus);
		}
	});
}

function remind(url, type, data) {
	$.ajax({
		global: false,
		type: type,
		url: url, 
		data: data,
		beforeSend: function(){ $('#top-bar-box-content').prepend('<img style="width:50px; height:50px; margin:-25px 0 0 -25px; top:50%; left:50%; position:absolute;" src="/img/loading51.gif" alt="Ładuję..." />');},
		success: function(data) { 
			$('#top-bar-box-content').html(data);
			$('#remind-form').submit(function(){
				remind(url, 'POST', $('#remind-form').serialize());
				return false;
			});
		},
		error: function(jqXHR, textStatus, errorThrown) {
			$('#top-bar-box-content').html(textStatus);
		}
	});
}

function register(url, type, data) {
	$.ajax({
		global: false,
		type: type,
		url: url, 
		data: data,
		beforeSend: function(){ $('#top-bar-box-content').prepend('<img style="width:50px; height:50px; margin:-25px 0 0 -25px; top:50%; left:50%; position:absolute;" src="/img/loading51.gif" alt="Ładuję..." />');},
		success: function(data) { 
			$('#top-bar-box-content').html(data);
			$('#register-form').submit(function(){
				register(url, 'POST', $('#register-form').serialize());
				return false;
			});
		},
		error: function(jqXHR, textStatus, errorThrown) {
			$('#top-bar-box-content').html(textStatus);
		}
	});
}

