/* 1b test template
 * requires:
 * jquery.js
 * player_test_template.js
 * iliustraData.js
 */

console.log('> template1b.js is iniciated;');

function template1bscript() {
	console.log("function template1bscript(); sectionName=" +sectionName + "; slideName=" +slideName);
	
	tObj = getObject();
    
        var mainVars = initMainVars(tObj,sectionName,slideName);
	var tO = mainVars.tO;     
        
       tO = randomizeAnswers(tO);        
       var items = tO['items'];       
        
       var check_type = 0;          
        
	// count items
	var itemsCount = tO['items_count']; 	console.log('items count: ' +itemsCount);
	       
        if (tO['background']) {
		loadSlideBackground();
	}
        
	var p = {	// properties
		step : 160,		// it is a step for each text, radio, checkbox, check items
		check :{
			top  : 0,
			unchecked		: 'img/check.png',
			checked			: 'img/check_true.png',
			checked_false	: 'img/check_false.png',
			unchecked_false	: 'img/check_false_2.png',
			css  : {
				"position":"absolute",
				'width':'31px',
				'height':'31px',
				'left' : '595px',
				"cursor": "pointer",
				"z-index": "10",
				"background":"url(img/check.png) no-repeat 0px 0px"
			}
		},
		radio :{
			top  : 0,
			unchecked		: 'img/radio.png',
			checked			: 'img/radio_true.png',
			checked_false	: 'img/radio_false.png',
			unchecked_false	: 'img/radio_false_2.png',
			css :{
				"position":"absolute",
				'width':'35px',
				'height':'35px',
				'left' : '595px',
				"cursor": "pointer",
				"z-index": "10",
				"background":"url(img/radio.png) no-repeat 0px 0px"
			}
		},
		photo:{
			css	:{
				"position":"absolute",
				'width'	:'500px',
				//'height':'500px',
				'top'	: '187px',
				'left' 	: '60px',
				"z-index": "7"
			}
		},
		text:{
			top  : 0,
			css	:{
				"position":"absolute",
				'width':'476px',
				'left' : '655px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '21px',
				'text-align':'left',
				'line-height': '32px'
			}
		}
	}	
	
	p.step = 490/itemsCount;
	
	var zIndexChange=20;
	
	var text_top = 185;
	
	//  get true - correct ; or falls - incorrect
	this.checkAnswer = checkTestAnswer;
	// check buttton and function to check
	checkTestButton(this.checkAnswer,tO,p);

	appendQuestion(ssId, ss, tO);
	
	check_type = check_check_or_radio(tO,p,check_type);
	
	append_items(items,p,1,ss,ssId,check_type);
	
	append_photo_1b(tO.photo,p);
	
	$('#section0slide0_photo_div').css('top', ($(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 25) + 'px');
	
	cnt = 0
	for (item in items) {
		cnt++;
	}
		
	var bot = $(ssId+'item_'+(cnt-1)+'text').position().top + $(ssId+'item_'+(cnt-1)+'text').outerHeight() + 20;
	console.log(bot);
	
	normalize_height(Math.max(600, bot));
	
	$(ssId).append('<img id="'+ss+'_fake2" style="position: absolute; left: -1000px; top: -1000px">');
	$(ssId+'_fake2').on('load', function(){
			
			var ih = $(this).height()+ 21 + $('#section0slide0_photo_div').position().top;			
			normalize_height(Math.max(ih, bot));
		});
		
	$(ssId+'_fake2').attr('src', tO.photo);	
}

