	$(function(){

		curAnswer = null;
		index = 0;
		active = true;

		var answers = new Array(
									new Array('Yes','images/question1.png'),
									new Array('Yes','images/question2.png'),
									new Array('Yes','images/question3.png'),
									new Array('No','images/question4.png'),
									new Array('Yes','images/question5.png'),
									new Array('Yes','images/question6.png'),
									new Array('No','images/question7.png'),
									new Array('last','images/question8.png'),
									new Array('error','images/question9.png')
								);

		lastIndex = answers.length;
		
		$('#decision-tv-nav span').click(function(){
		questionNo = (index+1);
		$('#decision-tree').attr('class', 'question-'+questionNo);	
		
			if (active) {			
				if ($(this).hasClass('yes')) {
					curAnswer = 'Yes';
					if (answers[index][0] == 'Yes') {	
						index++;				
						// display new question 
						renderTV(index, answers);		
						// display answer history
						renderRightPanel(index, curAnswer);
					} else {
						// display new question 
						renderTV(8, answers);		
						// display answer history
					//	renderRightPanel(index, curAnswer);
						active = false;
						$('#decision-tv-nav .yes, #decision-tv-nav .no').addClass('inactive');
					}			
				
				} else if ($(this).hasClass('no')) {
				
					curAnswer = 'No';				
					if (answers[index][0] == 'No') {						
						index++;
						// display new question 
						renderTV(index, answers);
						// display answer history
						renderRightPanel(index, curAnswer);
					} else {		
						// display new question 
						renderTV(8, answers);		
						// display answer history
					//	renderRightPanel(index, curAnswer);
						active = false;
						$('#decision-tv-nav .yes, #decision-tv-nav .no').addClass('inactive');
					}

				} 
			}
			
				
			if (index == 7) { // last slide inactive buttons
			$('#decision-tv-nav .yes, #decision-tv-nav .no').addClass('inactive');	
			active = false;
			}

			
			if ($(this).hasClass('start')) {
				active = true;				
				$('#decision-tv-question').find('div').hide();		
				$('#decision-tv-question').find('#q0').fadeIn(200);
				$('#decision-tree-right-middle').find('div').hide();
				$('#decision-tv-nav .yes, #decision-tv-nav .no').removeClass('inactive');
				index = 0;				
			}
		})
		
		$('.overlay-info').hover(		
			function(){
				$(this).parent().find('#q'+index).find('.overlay').fadeIn(200);
			}, 
			function() {
			$(this).parent().find('#q'+index).find('.overlay').hide();
			}
		)
		
	});

	function renderTV(index, answers) {	
		$('#decision-tv-question').find('div').hide();
		$('#decision-tv-question').find('#q'+index).fadeIn(200);		
	}


	function renderRightPanel(index, curAnswer) {	
		index = index -1;		
		$('#decision-tree-right-middle').find('.right-question').eq(index).find('span.answer').text(curAnswer);		
		$('#decision-tree-right-middle').find('.right-question').eq(index).show(500);
	
	}



