	var console;	

	$(document).ready(function(){
		var answers = [];
		var points = 0;
		
		hideAllPanels();
		load_state(1);
		$('#next').removeAttr("disabled");
		$("#level").attr('value', 'A');
		$("#points").attr('value', '0');
		$("#answers").attr('value', '0');
		
		$(':submit').click(function(){
			
			
			
			var current_state = $('#online-tests-wizard').attr('class');
			current_state = parseInt(current_state.replace(/(step_)/, ""));
			if ($(this).attr('id') == 'next'){
				$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
				switch(current_state){
					case 1:
						if (points >= 40) {
							$("#level").attr('value', 'B');
							load_state(2);
						}else 
							load_state(4);
					break;
					
					case 2:
						if (points >= 70) {
							$("#level").attr('value', 'C');
							load_state(3);
						}else 
							load_state(4);
					break;
					
					default:
						load_state(4);
						
				}
			}else if ($(this).attr('id') == 'previous'){
				load_state(--current_state);
			}
		});
		
		$("input[name*='question']").click(function() {
			var mKey = $(this).attr("name");
			var mValue = eval($(this).val());
			var obj = {key:mKey, value: mValue};
			
			$.each(answers, function(key, value){
				try {
					if(mKey == value.key) 
						answers.splice(key, 1);
				}catch(err){}
			});
			answers.push(obj);
			
			points = 0;
			if (answers.length > 0) {
				$.each(answers, function(key, value){
					if (value.value == 1) 
						points++;
				});
			}
			
			/** update result values **/
			$("#answers").attr('value', answers.length);
			$("#points").attr('value', points);
			$("#viewpoints").text(points);
			
			
		});
	});
	
	
	jQuery.fn.identify = function(prefix) {
	    var i = 0;
	    return this.each(function() {
	        if($(this).attr('id')) return;
	        do { 
	            i++;
	            var id = prefix + '_' + i;
	        } while($('#' + id).length > 0);            
	        $(this).attr('id', id);            
	    });
	};
	
	function hideAllPanels(){
		var panels = $('.wizardcontent').identify('step').length;
		for(i=0;i<=panels;i++) 
			$('#step_'+i).hide();
	}
	
	function load_state(current_state){

		hideAllPanels();
		
		$('#step_'+current_state).css('display', 'block');
		$('#online-tests-wizard').attr('class','step_'+ current_state);
		
		var iterator = 1;
		$('#online-tests-wizard h3').text("Step " + current_state);
		$('#navigation li').each(function(){
			var step = $(this)
			if (iterator == current_state){
				step.attr('class','current');
			}else if (current_state - iterator == 1){
				step.attr('class','lastDone');
			}else if (current_state - iterator > 1){
				step.attr('class','done');
			}else{ 
				step.attr('class','');
			}
			if (iterator == 4) step.addClass('finish'); 
			iterator++;
		});
		
		switch(current_state){
			case 4:
				$('.buttons').remove();
			break;
		}
	}
