
//sceneSelectLoad
function sceneSelectLoad(){
	
	
	
	//questionText
	text=dataScene[sceneCurrent]['text'];
	if(text){
		x=dataScene[sceneCurrent]['textX'];
		if(x==null){ x=100; }
		
		y=dataScene[sceneCurrent]['textY'];
		if(y==null){ y=100; }
		
		width=dataScene[sceneCurrent]['textWidth'];
		if(width==null){ width=defaultStageWidth-200; }
		
		align=dataScene[sceneCurrent]['textAlign'];
		if(align==null){ align='center'; }
		
		fill=dataScene[sceneCurrent]['textColor'];
		if(fill==null){ fill='#ffffff'; }
		
		fontSize=dataScene[sceneCurrent]['textSize'];
		if(fontSize==null){ fontSize=18; }
		
		var questionText = new Konva.Text({
			x: x,
			y: y,
			width: width,
			fontSize: fontSize,
			fill: fill,
			align: align,
			text: text,
			fontStyle: 'bold',
			fontFamily: 'Trebuchet MS, sans-serif',
			lineHeight: 1.5,
			
		});
		grpScene.add(questionText);
	}
	
	//questionImage
	src=dataScene[sceneCurrent]['image'];
	if(src){
		dataObject=dataScene[sceneCurrent];
		dataObject['height']=dataObject['imageHeight'];
		var object=qcImage({
			id:dataObject['name'],
			name:dataObject['name'],
			src:dataObject['image'],
			image_type:dataObject['image_type'],
			x:dataObject['imageX'],
			y:dataObject['imageY'],
			width:dataObject['imageWidth'],
			height:dataObject['imageHeight'],
			frameRate:dataObject['frameRate'],
			sprite_sheet:dataObject['sprite_sheet'],
		});
		grpScene.add(object);
		
	}
	
	//answers
	var dataObjects=dataScene[sceneCurrent]['objects'];
	for(key in dataObjects){
		
		var dataObject=dataObjects[key];
		
		//grpAnswer
		
		var grpAnswer = new Konva.Group({
			id: dataObject['answer'],
			x: dataObject['x'],
			y: dataObject['y'],
			answer: dataObject['answer'],
			correct:dataScene[sceneCurrent]['answer'],
			opacity:1,
		});
		grpScene.add(grpAnswer);
		initButton(grpAnswer,0);
		grpAnswer.on('pointerdown ', function () {
			sceneSelect_answerClick(this);
		});
		
		//answerBackground
		var answerBackground = new Konva.Rect({
			x: 0,
			y: 0,
			stroke: dataScene[sceneCurrent]['answerStroke'],
			strokeWidth: dataScene[sceneCurrent]['answerStrokeWidth'],
			visible:false,
		});
		grpAnswer.add(answerBackground);
		
		//answerText
		text=dataObject['text'];
		if(text){
			var answerText = new Konva.Text({
				x: dataObject['textX'],
				y: dataObject['textY'],
				width: dataObject['width'],
				fontSize: dataObject['fontSize'],
				fill: dataObject['fill'],
				align: dataObject['align'],
				text: text,
				fontStyle: 'bold',
				fontFamily: 'Trebuchet MS, sans-serif',
				lineHeight: 1.5,
				
			});
			grpAnswer.add(answerText);
			
			
		}
		
		//answerImage
		src=dataObject['image'];
		if(src){
			var object=qcImage({
				id:dataObject['name'],
				name:dataObject['name'],
				src:src,
				image_type:dataObject['image_type'],
				x:dataObject['imageX'],
				y:dataObject['imagey'],
				width:dataObject['imageWidth'],
				height:dataObject['imageHeight'],
				frameRate:dataObject['frameRate'],
				sprite_sheet:dataObject['sprite_sheet'],
			});
			grpAnswer.add(object);
		}
		
		
	}
	
	sceneResults[sceneCurrent]={
		'scene':sceneCurrent,
		'type':'select',
		'answer':'Yok',
		'correct':dataScene[sceneCurrent]['answer'],
	};
}

function sceneSelect_resetAnswer(){
	objects = grpScene.find('Group');
	
	
	for(key in objects){
		var obj = objects[key];
		
		//obj.width(0);
		//obj.height(0);
		obj.opacity(.4);
	}
}

function sceneSelect_answerClick(grpAnswer){
	btnCheckPopup.hide();
	sceneSelect_resetAnswer();
	
	checkLock=false;
	
	var answer=grpAnswer.getAttr('answer');
	var correct=grpAnswer.getAttr('correct');
	var rect=grpAnswer.getClientRect();
	
	grpAnswer.opacity(1);
	
	answerBackground = grpAnswer.find('Rect')[0];
	
	answerBackground.width(rect.width);
	answerBackground.height(rect.height);
	
	//*********************************************************
	//check if answer correct and save answer to answers array
	//*********************************************************
	sceneResults[sceneCurrent]={
		'scene':sceneCurrent,
		'type':'select',
		'answer':answer,
		'correct':correct,
	};
	if(answer==correct){
		sceneResults[sceneCurrent]['success']=true;
	}
	
}
function sceneSelectSolve(){
	
	var objects = grpScene.getChildren();
	
	for(key in objects){
		
		var obj = objects[key];
		
		obj.off('pointerdown');
		obj.off('pointerup');
		obj.off('pointerover');
		obj.off('pointerout');
		
		
	}
	sceneSelect_resetAnswer();
	var correct=dataScene[sceneCurrent]['answer'];
	var grpAnswer = grpScene.findOne('#' + correct);
	
	grpAnswer.opacity(1);
	
	var rect=grpAnswer.getClientRect();
	
	answerBackground = grpAnswer.find('Rect')[0];
	
	answerBackground.width(rect.width);
	answerBackground.height(rect.height);
	
}

