if (!window.console || !console.firebug) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}

	l = function (t) {}
} else {
	l = function (t) {
		console.log(t);
	}
}
var base_path = '';
preloadImgs('img/step_1.gif','img/step_2.gif','img/step_3.gif','img/step_4.gif','img/aqua_0.gif','img/aqua_1.gif','img/aqua_2.gif','img/aqua_3.gif')
//l(TREE_NODES);
var nodes = TREE_NODES;

var Chooser = new cChooser();
Chooser.showStep(nodes);

function cChooser() {
	this.init = 0;
	this.parent = undefined;
	this.current = undefined;

	this.showStep = function(item) {
		if (item) {
			this.parent = this.current;
			this.current = item;
			this.setQuestion();
			this.setAnswers();
		}
	}

	this.setQuestion = function () {
		var div = $("#choose_question");
		if (div) {
			$(div).html(this.current.title);
		}
		var auqa = (parseInt(this.current.level) - 1) / 2;
		var step = auqa + 1;
		$('.auqa img').attr('src','img/aqua_' + auqa + '.jpg');
		$('.question img').attr('src','img/step_' + step + '.gif');
	}

	this.showNextStep = function (item) {
		this.showStep(item);
	}

	this.showDep = function (id) {
		$(".question, .answer, .auqa").fadeOut('fast',function(){
			$("#dep_"+id).fadeIn('fast');
		}); 
	}
	
	this.setAnswers = function () {
		var div = $("div.chooser");
		$(".answer", div).remove();
		if (div) {
			var _i = 1;
			for (var i in this.current.childs) {
				var item = this.current.childs[i];
					$('<div class="answer">' + _i + '.&nbsp;<a href="javascript:;">' +  item.title + '</a></div>')
						.appendTo(div)
						.fadeIn('fast');
				_i++ ;
			}
			$('.answer a').click(
				function(){
					var ind = $('.answer').index($(this).parent());
					if (ind == undefined) return false;
					var _item = Chooser.current.childs[ind];
					if (_item.childs) {
						Chooser.showNextStep(_item.childs[0]);
					} else {
						Chooser.showDep(_item.dep);
					}
				})
		}
	}

}


