$(document).ready(function(){
	var superContainer = $('#facebox .network-reg'),
		progress = superContainer.find('.progress'),
		progressKeeper = superContainer.find('.progress-keeper'),
		progressWidth = progressKeeper.width();

	$.fn.NextTab = function(){
		$(this).parents('.tab-network').fadeOut(500, function () {
			$(this).next().fadeIn(500)
		});
	}

	$.fn.ProgressBar = function(){
		progress.animate({
			width: progress.width() + Math.round(progressWidth / 3)
		}, 500);
	}

	superContainer.find('ul.list-network li').click(function() {
		superContainer.find('ul.list-network li').removeClass('selected');
		$(this).addClass('selected');
		$('.step-number').text('2/3');

		$(this).parent().next('div.userkey-div').children('p').children('a').attr('href', 'http://www.'+$('span', this).attr('class')+"/account.html");
		superContainer.find('table tr td.disclaimer span').text($('span', this).attr('class'));

   		$NetworkSelected = $('span', this).attr('class');

   		$('.userkey-div').fadeIn(300);

   		if(progress.width() != 368) {
			$(this).ProgressBar();
   		}

	});
	superContainer.find('.nav-start').click(function(){
		$(this).parent().parent().fadeOut(500, function () {
            $(this).next().fadeIn(500);
        });

        $(this).ProgressBar();

        return false
	});

	superContainer.find('.next').click(function(){
		$(this).NextTab();
        return false
	});
});
