    function getObject(){
        //alert(tObj);
      //  console.log("MYOBJECT:",tObj);
            if (typeof tObj == 'undefined'){
                    tObj = doObj;
            }

            return tObj;
    }      
    
    function shuffle(arrayItems, arrayAnswers) {
      //console.log("ARRAY:",arrayItems); 
      var finalArray = []; 
      var currentIndex = arrayItems.length,temporaryValue,temporaryValue2,randomIndex;

      // While there remain elements to shuffle...
      while (0 !== currentIndex) {
        // Pick a remaining element...
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;

        // And swap it with the current element.
        temporaryValue = arrayItems[currentIndex];
        temporaryValue2 = arrayAnswers[currentIndex];
        arrayItems[currentIndex] = arrayItems[randomIndex];
        arrayItems[randomIndex] = temporaryValue;

        arrayAnswers[currentIndex] = arrayAnswers[randomIndex];
        arrayAnswers[randomIndex] = temporaryValue2;    
      }

      finalArray[0] = changeItemsKey(arrayItems);
      finalArray[1] = arrayAnswers;  

      return finalArray;
    }   
    
    function changeItemsKey(itemsArray){
        var nArray = [];
        for (var i=0;i<itemsArray.length;i++){
            nArray["item_"+ i] = itemsArray[i];
        }
        
        return nArray;
    }    
    
    function randomizeAnswers(tO){
        
        var items = tO['items'];        
        
        var arr_items =  $.map(items, function(value, index) { //convert items to array
            return [value];
        });      
              
        var originalAnswers = tO['answer'];
        var randomArrays = shuffle(arr_items, originalAnswers);
        items = randomArrays[0]; 
        
        tO['items'] = items;       
        
        var ans =  randomArrays[1];
        
        console.log("Random items:",items,"Random answers:",ans); 
        
        return tO;
    }    
        
    function initMainVars(tObj,sectionName,slideName){                  
		tO = tObj[sectionName][slideName];
		return {
			tO:tO,
			items:tO['items'],
			check_type:0
		};
		//var tO = tObj[sectionName][slideName]; 	console.log("tObj:"); 		console.log(tObj);
		//var items = tO['items'];				console.log("items:");	console.log(items);
		//var check_type = 0;	// which type: 0- checkbox; 1 - radio?              
	}

	function container_droppable(classId){
		$( classId).droppable({
			drop: function( event, ui ) {},
			out: function( event, ui ) {}
		});
	}
	
	function append_caption_text_4b(tO,p,answered) {						// level 1 function
		var text = tO['caption'];
		var css = p.text.css; // css of item
		
		text_coords = text.split('/*');
		text = text_coords[0];
		
		text = text.split('|');
		
		var l = text.length;
		var new_text = '';
		for (var i =0;i<l;i++) {
			if (i==(l-1)) {
				new_text += '<div style="display: inline-block; white-space: pre">' + text[i] + '</div>';	
			}
			else{
				new_text += '<div style="display: inline-block; white-space: pre">' + text[i] + '</div>' + '<div class="drp" id ="'+ss+'_text_place_'+i+'"><div class="drp2"> </div></div>';
			}
		}
		
		$(ssId)
			.append('<div class="" id="' +ss+'caption">'+new_text+'</div>');
	
		$(ssId+'caption .drp')
			.css({
				'width':'249px',
				'height':'45px',
				'background':"white",
				'display': 'inline-block',
				'border': '1px dotted white',
				'white-space': 'pre'
			});
			
		$(ssId+'caption .drp2')
			.css({
				'width':'248px',
				'height':'40px',
				'background':"white",
				'display': 'inline-block',
				'border': '1px dotted black',
				'white-space': 'pre'
			});	
		
		for (var i =0;i<l;i++) {
			container_droppable(ssId+'_text_place_'+i);
			
			$(ssId+'_text_place_'+i)
				.on('drop', function( event, ui ) {	// droppable jquery ui
					
					
					var container_no = $(this).attr('id');
					var item_no = $(ui.draggable).attr('id');
					//container_no = parseInt(container_no.replace('section0slide0_text_place_',''));
					//item_no = parseInt(item_no.replace('section0slide0item_',''));
                                        
                                        var sec = ssId.replace("#",'');                                       
                                        container_no = parseInt(container_no.replace(sec+'_text_place_',''));
					item_no = parseInt(item_no.replace(sec+'item_',''));
					
					answered[item_no] = container_no;
				console.log("answered_test:", answered, container_no);
				console.log(answered);
							
				console.log("droped in:"+$(this).attr('id'));
				console.log("droped item:"+$(ui.draggable).attr('id'));
				
				tp = $(ssId + 'caption').position().top;
				lf = $(ssId + 'caption').position().left;
				
				var field_top = $(this).position().top + tp + 2;
				var field_left = $(this).position().left + lf + 2;
				
				$(ui.draggable)
					.attr('drp_in', container_no)
					.animate({ 'top': field_top + 'px', 'left': field_left + 'px'}, 400, function(){})
					.css({
						"background":"rgb(255,255,255)",
						"border":'1px solid white'
						});
				}
			);
		}
		
		$(ssId+'caption')
			.css({
				"position":"absolute",
				'width':'1043px',
				//'height':'70px',
				//'top':'180px',
				'left':'60px',
				"z-index": "6",
					'text-indent':'0px',
					'font-family':'Arial',
					'font-size': '24px',
					'line-height': '40px'
			});
			
		tp = $(ssId+'question').position().top + $(ssId+'question').outerHeight() + 54;
		console.log('tp:', tp);
		$(ssId+'caption').css('top', tp+'px');	
			
		if (text_coords.length > 1)	{
			text_coords = text_coords[1].replace('/*', '');
			text_coords = text_coords.split('--');
						
			tp = $(ssId+'_photo_div').position().top;
			lf = $(ssId+'_photo_div').position().left;
			
			ofs_l = $(ssId+'caption').position().left - lf;
			ofs_t = $(ssId+'caption').position().top - tp;
			
			console.log('offset:',ofs_l);
			
			$(ssId).append('<canvas id="'+ss+'_linecanvas" width="630" height="500" style="position:absolute; top:'+tp+'px; left:'+lf+'px; z-index:6"></canvas>');
			
			for (i=0;i<text_coords.length;i++) {
								
				coords = text_coords[i].split(',');
				
				if (coords.length > 6) {
					$(ssId+'_text_place_'+i).addClass('for_img');
				}
				
				itm = $(ssId+'_text_place_'+i);
				itm.css('display', 'block');
				itm.css('position', 'absolute');
				itm.css('left', coords[0]+'px');
				itm.css('top', coords[1]+'px');
				
			}
		}
                        //console.log("final_answered:", answered)
                        //return answered;
	}
	
	function append_caption_text(caption,captions,p,drop_in) {
		var left = p.left[caption]; // animation end point
		var css = p.caption; // css of caption
			
		console.log(caption + ' position: left='+left );
		$(ssId)
			.append('<div id="' + ss + caption + '">' + captions[caption] + '</div>')
			.append('<div class="container" id="' + ss + caption + 'container' + '"></div>');
	
		$(ssId + caption)
			.css(p.caption)
			.css('left',left);
			
		if (caption == 'caption_2') {
			$(ssId + caption)
				.css('background-image', 'url("img/fonas_2.jpg")');
		}	
		
		var cap_top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 25;
		$(ssId + caption)
			.css('top', cap_top + 'px');
		
		
		$(ssId + caption + 'container')
			.css(p.container)
			.css('left',left);
			
		if (caption == 'caption_2') {
			$(ssId + caption + 'container')
				.css('background-image', 'url("img/fonas_2.jpg")');
		}	
		
		$(ssId + caption + 'container')
			.css('top', (cap_top + 59) + 'px')
		
		
		//container_droppable(ssId + caption + 'container');
		$(ssId + caption + 'container').droppable();
		
		$(ssId + caption + 'container').on('drop', function( event, ui ) {	// droppable jquery ui
					var top = $(this).position().top + 1;
					var left = $(this).position().left + 4;
					var container_id = $(this).attr('id');
					var item_id = $(ui.draggable).attr('id');			
					console.log("droped item id:"+item_id);
					console.log("caption:"+caption);
					console.log("droped in container id:"+container_id);
	
					// add items to object to track in which caption they are dropped
					drop_in[caption][item_id] = drop_in.items[item_id];
					drop_in.caption[item_id] = caption;
	
					drop_in.order[caption].push(item_id);
					
					$('#'+item_id).css({"-webkit-box-shadow": "none",
										"-moz-box-shadow": "none",
										"box-shadow": "none",
										'background': "#fff"});
					
					
					if ($(ui.draggable).children().children('img').length > 0) {
						order_caption_items1();
					} else {
						order_caption_items();
					}
	
					console.log('drop_in:');
					console.log(drop_in);
					
	
					function order_caption_items1() {
						var l = drop_in.order[caption].length
						var cnt = $('#'+container_id).width() / 185;
						
						for (var i = 0; i <l; i++) {
							
							var left_i = (184 * Math.floor(i % cnt)) + $('#'+container_id).position().left;
							var top_i = (Math.floor(i / cnt)*149) + $('#'+container_id).position().top;
							
							var item = drop_in.order[caption][i];
							$('#'+item).css({top: (top_i+2), left: (left_i+1)});
						}
							//return top;
					}
					
					function order_caption_items() {
						var l = drop_in.order[caption].length
						for (var i = 0; i <l; i++) {
								var item = drop_in.order[caption][i];
								$('#'+item).css({top: top, left: left});
								top += drop_in.height[item]+3;
								console.log('item:' + item+ "; Item height: " + drop_in.height[item] + '; Item text: '+drop_in.text[item]);
						}
						return top;
					}				
			});
	
	}      
        
    function append_photo(url,p) {
		var width =505;
		var height = 500;
		
                
		if (url) {
				
			console.log('Photo: ' + url);
			$(ssId)
				.append('<div class="photo" id="' + ss + '_photo_div"></div>');
			$(ssId + '_photo_div')
				.css(p.photo.css)
				.append('<img id="' + ss + '_photo_img" src="'+url+'">');
			
			//$("img")
			//	.one('load', function() {setW_H();})
			//	.each(function() {if(this.complete) $(this).load();});
		}
		
		function setW_H() {
			width = $(ssId + '_photo_img').width();
			height = $(ssId + '_photo_img').height();
			var left_margin = (505-width)/2;
			var top_margin = (500-height)/2;
			console.log('Image width = ' + width + '; height = ' + height);
		
			$(ssId + '_photo_img')
				.css({
					'position': 'absolute',
					'margin-left': left_margin,
					'margin-top':top_margin
				});	
		}
	}  
	
	function append_photo_3e(url,p) {
		var width =505;
		var height = 500;
		
                
		if (url) {
				
			console.log('Photo: ' + url);
			
			txt = $(ssId+'question').html();
			$(ssId+'question').html('<div id="'+ss+'txt_frame" style="width: 580px; float: left">'+txt+'</div>');
			
			$(ssId+'question')
				.append('<div class="photo" id="' + ss + '_photo_div"></div>');
			$(ssId + '_photo_div')
				.css(p.photo.css)
				.append('<img id="' + ss + '_photo_img" src="'+url+'">');
			
			//$("img")
			//	.one('load', function() {setW_H();})
			//	.each(function() {if(this.complete) $(this).load();});
		}
		
		function setW_H() {
			width = $(ssId + '_photo_img').width();
			height = $(ssId + '_photo_img').height();
			var left_margin = (505-width)/2;
			var top_margin = (500-height)/2;
			console.log('Image width = ' + width + '; height = ' + height);
		
			$(ssId + '_photo_img')
				.css({
					'position': 'absolute',
					'margin-left': left_margin,
					'margin-top':top_margin
				});	
		}
	}
	
	function append_photo_1b(url,p) {
		var width =505;
		var height = 500;
		
                
		if (url) {
				
			console.log('Photo: ' + url);
			$(ssId)
				.append('<div class="photo" id="' + ss + '_photo_div"></div>');
			$(ssId + '_photo_div')
				.css(p.photo.css)
				.append('<img id="' + ss + '_photo_img">');
			
			$("img").load( function() {
					$('.unchecked').css('left', ($(this).width() + 60 + 35) + 'px');
					$('.text_t').css('left', ($(this).width() + 60 + 95) + 'px');
				});
				
			$(ssId + '_photo_img').attr('src', url);	
			
			//$("img")
			//	.one('load', function() {setW_H();})
			//	.each(function() {if(this.complete) $(this).load();});
		}
		
		function setW_H() {
			width = $(ssId + '_photo_img').width();
			height = $(ssId + '_photo_img').height();
			var left_margin = (505-width)/2;
			var top_margin = (500-height)/2;
			console.log('Image width = ' + width + '; height = ' + height);
		
			$(ssId + '_photo_img')
				.css({
					'position': 'absolute',
					'margin-left': left_margin,
					'margin-top':top_margin
				});	
		}
	}
	
	function checkTestAnswer_6a(tO) {
		
		var correct = true;	
		if (tO.answer[0].indexOf('--') == 0) {
			
			correct = false
			
			var ans = tO.answer[0].replace('--', '');
			ans_a = ans.split('$-$');
			answered = $(ssId+'answer_input').val().trim();
			
			for (i=0;i<ans_a.length;i++) {
				if ((answered == ans_a[i].trim()) && (ans_a[i].trim() != '')) {
					correct = true
				}
			}
		}
		
		console.log('JSF checkTestAnswer()');
		
		console.log(tO);
			
		testAnswer(correct);
		return correct;
	}    

    function checkTestAnswer_11a(tO,ssId,randPlaces) {
		var i=0;
		var right = randPlaces;
		var xPrev=0;
		var correct = true;
		var count = 0; // count right answers
	
		var items_tops = get_items_top_positions();
		
		var items_places = get_items_places(items_tops);
		
		var correct = compareAnswers_11a(right,items_places,ssId);
			
		function get_items_top_positions() {		// get top positions of each answer in array
			var itemsTops = [];
			var item;
			for (item in tO['items']) {
				var x = parseInt($(ssId+item ).css('top'), 10);
				console.log(item + ' x = '+x );
				itemsTops.push(x);
			}
			console.log('itemsTops:');
			console.log(itemsTops);
			return itemsTops;
		}	

		console.log('Answered: '+ items_places);
		console.log('Right answer: '+ randPlaces);
				
		testAnswer(correct);
		return correct;
	}      

	function checkTestAnswer_2a(tO,ssId,randPlaces,backWidth,itemsCount) {					// level 1 function		// check test is it right answered
		var leftX = [30,254,478,702,926];
		var i=0,j=0;
		var xPrev=0;
		var correct = false;
		var answered = [];
		var y;
		
		
		var count = 0; // count right answers
		randPlaces.forEach(function(i){
			var x = parseInt($(ssId+'m_item_' + j ).css('left'), 10); // get integer
			var answer = 30+i*(20+backWidth);
			y = ((x-30)/(20+backWidth)).toFixed(0);
			answered.push(y);
			
			//alert("randPlace:"+randPlaces[j]+ "answered:"+ answered[j]);
                        if ((randPlaces[j] == answered[j]) && ($(ssId+'m_item_' + j).hasClass("dropped"))) {
				console.log('Correct'+'m_item_' + j + ' check x = '+x + '; leftX = '+answer);
				$(ssId+'m_item_' + j + '_wrong_mark')
					.css({'border':'1px solid #48c3eb',});
					
				$(ssId+'m_item_' + j + 'background').css('border-color', '#48c3eb');
				
				count ++;	// count right answers
			}
			else{
				console.log('Incorect '+'m_item_' + j + ' check x = '+x + '; leftX = '+answer);
				
				$(ssId+'m_item_' + j + '_wrong_mark')
					.css({'border':'1px solid rgb(255,72,0)',});
					
				$(ssId+'m_item_' + j + 'background').css('border-color', 'rgb(255,72,0)');	
			}
			j++;
		});
		console.log('Answered: '+ answered);
		console.log('Right answer: '+ randPlaces);
		
		if (count == itemsCount) {
			correct = true;
		}
		else {
			correct = false;
		}
		
		
		testAnswer(correct);
		return correct;
	}  

    function checkTestAnswer_4b(tO,ssId,randPlaces,backWidth,itemsCount,answered) {
		var i=0;
		var right = randPlaces;
		var xPrev=0;
		var correct = true;
		var count = 0; // count right answers
		
		console.log('Initial object 4b');
		console.log(answered);
		var answer = prepare_answer(answered,right);
		console.log('converted object answ');
		console.log(answer);
		
		var correct = compareAnswers_4b(right,answer,ssId, tO);
		
		function prepare_answer(answered,randPlaces) {
			var array = [];
			var l = randPlaces.length;
                       // alert(l);
			for (var i=0;i<l;i++) {
				array.push(answered[i]);
			}
	
			return array;
		}

		console.log('Answered: '+ answer);
		console.log('Right answer: '+ randPlaces);
				
		testAnswer(correct);
		return correct;
	}       

    function checkTestAnswer(tO,p) {
		console.log('JSF checkTestAnswer()');		
		var right_answer = tO.answer;
		var count = 0; // count right answers
		
		var answered = get_answers(tO,ssId);
		
		var correct = compareAnswers(right_answer,answered,p,ssId);
		
		function get_answers(tO,ssId) {
			var i=0;
			var answers = [];
                        
            var item;            //console.log("RandomCheck:",tO['items'])
			for (item in tO['items']) {
				var id = ssId + item + 'check_or_radio';                               
				var className = $(id).attr('class');
				console.log('Item id = ' + id +'; className = ' + className );
				var item_answer = 0;
				if (className == 'checked') {
					item_answer = 1;
				}
				answers.push(item_answer);
				i++;
			}
			return answers;
		}	
		
		console.log('Answered: '+ answered);
		console.log('Right answer: '+ right_answer);
				
		testAnswer(correct);
		return correct;
	}      

    function randomise_items_end_XY(itemsCount,p) {			// make random x and y coordinates of items between min and max coordinates
		// make x and y with diviation for 6 images
		var i = itemsCount;
		var e = p.end; // end properties
		var minx = e.min.x,
			miny = e.min.y,
			maxx = e.max.x,
			maxy = e.max.y;
		console.log('minx='+minx+'; maxx='+maxx+'; miny='+miny+'; maxy='+maxy);
		
		// delta x, delta y
		var dx = ((maxx-minx)/i).toFixed(0);
		var dy = ((maxy-miny)).toFixed(0);
		
		console.log('delta dx='+dx+'; delta dy='+dy);
		
		for (var j = 0; j<i;j++) {
			var xy =[];
			
			var x;
			var y;	
			
			x = +( (j * dx)+ (dx *0.5* Math.random())).toFixed(0);
			y = +( (dy * Math.random())).toFixed(0);
			
			x += +minx
			y += +miny
			console.log('item_'+j+': x='+x+'; y='+y);
			
			e['item_'+j] = {};
			e['item_'+j]['top'] = y;
			e['item_'+j]['left'] = x;
		}
		console.log('randomise_items_end_XY :');
		console.log(e);
	}
	
	function randomArray(count) {				// make a random array of count numbers; count - 5; result example = [3,2,0,4,1]
		var max = count -1;
		console.log('JSF random(count)');
		var result = [];
		var depth = 0 ;
		var sum = 0;
		
		// get first random element and put in result
		var x = (Math.random() * max).toFixed(0);
		console.log('First element: ' + x);
		result.push(+x);
		console.log('result:');
		console.log(result);
		sum += +x;
		// get second and until the last elements
		for (var i =1;i<count-1;i++) {
			x = randomUnique(max);
			result.push(+x);	
			sum += +x;
			console.log('sum: ' +sum);
			console.log('result:');
			console.log(result);
		}
		
		// get last element : total sum of all numbers minus counted sum
		x = (count-1)/2 * count - sum;
		result.push(x);
		console.log('Last element: ' + x);
		console.log('result:');
		console.log(result);
		
		function randomUnique(max){
			depth++;
			console.log('depth+='+depth);
			
			var r = (Math.random() * max).toFixed(0);
			console.log('random=' + r);
			
			for ( var j=0;j<count-1;j++) {
				console.log('result['+j+']='+result[j] +'; random=' +r);
				if (result[j] === +r) {
					console.log('equal');
					r = randomUnique(max);
				}
			}
			depth--;
			console.log('depth-='+depth);
			return r;
		}
		return result;
	}
	
	function change_items_to_random(items, randPlaces) {
		var newOrder = {};
		var i=0;
		randPlaces.forEach(function(e){
			newOrder['item_'+i] = items['item_'+e]; // get images in new places by randPlaces set
			i++;
		});
		console.log(newOrder);
		// change real items with random
		items = newOrder;
                
                return items;
	}
        
    function check_check_or_radio(tO,p,check_type) {
		if (tO.answersCount == 1) {		// check if there is one right answer counted 
			p.check = p.radio;			// change to radio
			check_type = 1;                       
		}
                
                return check_type
	}
        
    function checkTextOrImage(str) {				// level 3 function
		var line_begin = ['../assets','assets/','content/','images','img/'];
		
		var l = line_begin.length;
		
		for (var i=0;i<l;i++) {
			var s_result = str.search(line_begin[i]);
			if (s_result == 0) {
				var found = 'image';
				return found;
			}
			else{
				var found = 'text';
			}
		}
		/*
		var result = str.search('../assets');
		var result = str.search('content/');
		//console.log ('Search in: '+str+'; result: ' + result)
		if (result == 0) {
			var found = 'image';
		}
		else{
			var found = 'text';
		}
		*/
		return found;		// type: 'text' - text; 'image'- image;
	}
		
	function append_one_item(f_or_m,item,items,f_p,m_p,backWidth) {// level 2 function		// append f or m one item
		var found = checkTextOrImage(items[item]); // type: 'text' - text; 'image'- image;
		console.log('JSF checkTextOrImage(item,items); item: '+ item + 'items[item]: ' + items[item] +'; found: ' + found);
		
		// f items
			if (found == 'image' && f_or_m == 'f') {
				append_item_image(f_p,item,items,backWidth);
			}
			
            //alert(found + '' + f_or_m);
            if (found == 'text' && f_or_m == 'f') {
				append_item_text_2a(f_p,item,items,backWidth);
			}
			
			// m items
			if (found == 'image' && f_or_m == 'm') {
				append_item_image(m_p,item,items,backWidth);
			}
			if (found == 'text' && f_or_m == 'm') {
				append_item_text_2a(m_p,item,items,backWidth);
			}
		
		function append_item_image(p,item,items,backWidth) {	// level 3 function
			var n = p.name; // f or m name
			var e = p.end; // animation end point
			var css = p.image.css; // css of item
			var css_wrong = p.text.css; // css of item

			var clname = sectionName+slideName + n + "_items_2a";
                        $(ssId).append('<div class="' + clname + '" id="' + ss + item + '"></div>');
				
				
			$(ssId + item)
				.css(css)
				//.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 1000, function(){})
				.css({'top' : e.top+'px', 'left' : e.left+'px'})
				.append('<div id="' + ss + item + '_wrong_mark"></div>');
			
			$(ssId + item)	
				.append('<div class="bkg" id="' + ss + item + 'background"></div>');	
				
			if (css_wrong.wrong != undefined){
				$(ssId + item+ '_wrong_mark').css(css_wrong.wrong);
			}		
			
			e.left += 20 + backWidth;// distance between images left
		}
            
		function append_item_text_2a(p,item,items,backWidth) { 	// level 3 function 	// p stands for f,m params
			var n = p.name; // f or m name
			var e = p.end; // animation end point
			var css = p.text.css; // css of item
			
			var clname = sectionName+slideName + n+ "_items_2a";
                        $(ssId).append('<div class="'+ clname+'" id="' + ss + item + '"></div>');
                        
            var txt = items[item];            ;
            txt = txt.replace(/\|sub\|/g, '<sub>');
            txt = txt.replace(/\|\-sub\|/g, '</sub>');
	
			$(ssId + item)
				.append('<div class="text'+n+'b" id="' + ss + item + 'background"></div>')
				.append('<div class="text'+n+'t" id="' + ss + item + 'text">' + txt + '</div>')
				.css(css.main)
				//.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 1000, function(){})
				.css({'top' : e.top+'px', 'left' : e.left+'px'})
				.append('<div id="' + ss + item + '_wrong_mark"></div>');
		
			if (css.wrong != undefined){
				$(ssId + item+ '_wrong_mark').css(css.wrong);
			}
                        
			$(ssId+item + 'background').css(css.background);
			
			$(ssId+item + 'text').css(css.text);
                        
			e.left += 20 + backWidth;// distance between images left
		}           
	}  
		
    function append_captions(captions,p,drop_in) {
		for (caption in captions) {
			console.log("caption: " +caption +'; ' + captions[caption]);
			append_caption_text(caption,captions,p,drop_in);
		}
	}
        
	function append_items(items,p,contentType,check_type,ss,ssId,drop_in) {			// level 1 function		// append f or m all items
		
		var item;
		for (item in items) {
				console.log("item: " +item +'; ' + items[item]);
			if (contentType == 1){				
                append_item_text(item,items,p,check_type,ss,ssId);
			}else if (contentType == 2){
				append_item_img(item,items,p,check_type,ss,ssId);                        
			}else if(contentType == 3){//alert("11a")
				append_item_text_11a(item,items,p,ss,ssId);
			}else if (contentType == 4){//alert("3e");
				append_item_text_3e(item,items,p,drop_in);
			}else if (contentType == 5){
				append_item_text_4b(item,items,p);
			}
		}
	
		function append_item_img(item,items,p,check_type,ss,ssId) { 	// level 3 function 	// p stands for f,m params
			var i_position = p.position.image[item];
			var c_position = p.position.check[item];
			
			var qh = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight();
			
			$(ssId)
				.append('<div class="text_t" id="' + ss + item + 'img_div"><img id="' + ss + item + 'img" src="'+items[item]+'"></div>')
				.append('<div class="unchecked" id="' + ss + item + 'check_or_radio"></div>');
			
			$(ssId+item + 'img_div')
				.css(p.photo.css)
				.css({
					'top' : ((i_position.top + qh)+'px'),
					'left': (i_position.left+'px'),
					'cursor':'pointer'
				})
				.bind('click',function(){
					check_item();
				});
		
			$(ssId+item + 'check_or_radio')
				.css(p.check.css)
				.css({
					'top' : ((c_position.top + qh)+'px'),
					'left': (c_position.left+'px'),
				})
				.bind('click',function(){
					check_item();
				});
				function check_item() {
					var className = $(ssId+item +'check_or_radio').attr('class');
					
					if (check_type) { // if check_type == 1 - radio type
						$('.checked')
							.css('background',"url(" + p.check.unchecked + ") no-repeat 0px 0px")
							.attr('class','unchecked');
					}
					
					if (className == 'checked') {
						$(ssId+item +'check_or_radio')
							.css('background',"url(" + p.check.unchecked + ") no-repeat 0px 0px")
							.attr('class','unchecked');
					}
					if (className == 'unchecked') {
						$(ssId+item +'check_or_radio')
							.css('background',"url(" + p.check.checked + ") no-repeat 0px 0px")
							.attr('class','checked');
					}
					
				}
		}       
			
		function append_item_text(item,items,p,ss,ssId,check_type) { 	// level 3 function 	// p stands for f,m params
			
			if (p.text.top == 0) {
				p.text.top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 27;
				p.check.top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 25;
				p.radio.top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 25;
			}
			
			var itm = items[item];
			itm = itm.replace(/\|sub\|/g, '<sub>');
			itm = itm.replace(/\|-sub\|/g, '</sub>');
			
			itm = itm.replace(/\|sup\|/g, '<sup>');
			itm = itm.replace(/\|-sup\|/g, '</sup>');
			
			itm = itm.replace(/-->/g, '→');
			
			var css = p.text.css; // css of item
			//alert(ssId);
			$(ssId)
				.append('<div class="text_t" id="' + ss + item + 'text">' + itm + '</div>')
				.append('<div class="unchecked" id="' + ss + item + 'check_or_radio"></div>');
			
			$(ssId+item + 'text')
				.css(p.text.css)
				.css({
					'top' : (p.text.top+'px'),
					'cursor':'pointer'
					 })
				.bind('click',function(){
					check_item();					
				});
	
			$(ssId+item + 'check_or_radio')
				.css(p.check.css)
				.css('top' , (p.check.top+'px'))
				.bind('click',function(){
					check_item();					
				});
			p.text.top += $(ssId+item + 'text').outerHeight() + 15;
			p.check.top += $(ssId+item + 'text').outerHeight() + 15;
			
			function check_item() {
				var className = $(ssId+item +'check_or_radio').attr('class');
					
					if (check_type) { // if check_type == 1 - radio type
						$('.checked')
							.css('background',"url(" + p.check.unchecked + ") no-repeat 0px 0px")
							.attr('class','unchecked');
					}
					
					if (className == 'checked') {
						$(ssId+item +'check_or_radio')
							.css('background',"url(" + p.check.unchecked + ") no-repeat 0px 0px")
							.attr('class','unchecked');
					}
					if (className == 'unchecked') {
						$(ssId+item +'check_or_radio')
							.css('background',"url(" + p.check.checked + ") no-repeat 0px 0px")
							.attr('class','checked');
					}
			}
		}              

		function append_item_text_11a(item,items,p,ss,ssId) { 	// level 3 function 	// p stands for f,m params
			//alert(sectionName+slideName);
                    var e = p.end[item]; // animation end point
			var css = p.text.css; // css of item
			console.log(item + ' position: top='+e.top+' ; left='+e.left);
                        
                       // alert(ss + item);
			var clname = sectionName+slideName + "items_11a";
                    $(ssId)
				.append('<div class="'+clname+'" id="' + ss + item + '"></div>');
		
			new_text = items[item].replace(/\|\|/g, '<br/>');
		
			$(ssId + item)
				.append('<div class="text_t fixed_pos" id="' + ss + item + 'text">' + new_text + '</div>')
				.css(css.main)
				.on( "dragstop", function( event, ui ) {
					
					function fixed_pos_obj(aelement, atop) {
						this.element = aelement;
						this.top = atop;
					}
					
					var objs = new Array();
					
					$(".fixed_pos").each(function( index, element ) {
						//var topp = (index * 60) + 120;
						//$(element).parent().animate({ 'top': topp + 'px', 'left': '30px'}, 100, function(){});
						
						objs[index] = new fixed_pos_obj(element, $(element).parent().position().top);
					});
					
					question_top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 30;
					hh_i = $(ssId + 'question').outerHeight() + 30;
					
					var topp = question_top;
					hh = hh_i;
					
					objs.sort(function(a,b) { return parseFloat(a.top) - parseFloat(b.top) } );
					for (var i=0; i<objs.length;i++) {
						//var topp = (i * 60) + question_top;
						$(objs[i].element).parent().animate({ 'top': topp + 'px', 'left': '20px'}, 400, function(){});
						topp = topp + $(objs[i].element).parent().outerHeight() + 10;
						hh = hh + $(objs[i].element).parent().outerHeight() + 10;
					}
									
				});
		
			$(ssId+item + 'text').css(css.text);
		}       
			
		function append_item_text_3e(item,items,p,drop_in) { 	// level 3 function 	// p stands for f,m params
			var e = p.end[item]; // animation end point
			var css = p.text.css; // css of item
			console.log(item + ' position: top='+e.top+' ; left='+e.left);
                         //  alert( ss + item );
			
                   var clname = sectionName+slideName + "items_3e";
                    $(ssId)
				.append('<div class="'+clname+'" id="' + ss + item + '"></div>');
	
	
			var itm = items[item];
			if (itm.indexOf('assets') == -1) {
				console.log('tst: nepagavom');
				$(ssId + item)
					.append('<div class="text_t" id="' + ss + item + 'text">' + items[item] + '</div>')
					.css(css.main);	
				
			} else {
				console.log('tst: pagavom');
				$(ssId + item)
					.append('<div class="text_t" id="' + ss + item + 'text"><img class="img_3e" style="width:181px" src="' + items[item] + '"/></div>')
					.css(css.main);
					
				it = $(ssId + item);	
				it.css('width', '183px');
				it.css('height', '150px');
				it.css('border', 'none');
				it.css('background', 'none');
				
				itt = $(ssId + item + ' .text_t');
				itt.css('border', '1px solid #e0e0e0');
				itt.css('height', '146px');
			}	
				
			$(ssId + item)	
				//.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 800, function(){})
				.on( "dragstart", function( event, ui ) {
					var item_id = ss + item;
					console.log('item_id: ' + item_id);
					
					var caption = drop_in['caption'][item_id];
					console.log('caption: ' + caption);
					
					$('#'+item_id).css({"-webkit-box-shadow": "0px 2px 1px 0px rgba(0,0,0,0.3)",
										"-moz-box-shadow": "0px 2px 1px 0px rgba(0,0,0,0.3)",
										"box-shadow": "0px 2px 1px 0px rgba(0,0,0,0.3)",
										'background': "#e0f7fd"});
					
					if (drop_in.caption[item_id] == 0) {}
					else{
						var top = $(ssId+caption+'container').position().top + 1;
						var left = $(ssId+caption+'container').position().left + 4;
						
						console.log('dropactivate item:' + item_id);
						
						remove_item();
						drop_in.caption[item_id] = 0;
						
						if (itm.indexOf('assets') == -1) {
							order_caption_items();
						} else {
							order_caption_items1();
						}	
					}
					
					function remove_item() {
						var i = drop_in.order[caption].indexOf(item_id);	// get item position in array
						console.log('i: ' + i);
						drop_in.order[caption].splice(i,1);
						console.log('removed item: ' + item_id);
						console.log('drop_in.order[caption]: ');
						console.log(drop_in.order[caption]);
						
					}
					
					function order_caption_items1() {
						var l = drop_in.order[caption].length
						var cnt = $(ssId+caption+'container').width() / 185;
						
						for (var i = 0; i <l; i++) {

							var left_i = (184 * Math.floor(i % cnt)) + $(ssId+caption+'container').position().left;
							var top_i = (Math.floor(i / cnt)*149) + $(ssId+caption+'container').position().top;
							
							var item = drop_in.order[caption][i];
							$('#'+item).css({top: (top_i+2), left: (left_i+1)});
						}
					}
					
					function order_caption_items() {
							var l = drop_in.order[caption].length
							for (var i = 0; i <l; i++) {
									var item = drop_in.order[caption][i];
									$('#'+item).css({top: top, left: left});
									top += drop_in.height[item]+3;
									console.log('item:' + item+ "; Item height: " + drop_in.height[item] + '; Item text: '+drop_in.text[item]);
							}
							return top;
					}
					
				} );
			
			
			if (itm.indexOf('assets') == -1) {
				
				$(ssId+item + 'text')
					.css(css.text);
				
				var height = $(ssId+item + 'text').height();
		
				$(ssId + item)
					.css('height',(height+10));
					
			} else {
				$(ssId + item + 'text').css('margin', '0px');
			}
			
			drop_in.text[ss + item]= items[item];
			drop_in.items[ss + item]=height+10;
			drop_in.height[ss + item]=height+10;
			drop_in.caption[ss + item]=0;
		}
	
		function append_item_text_4b(item,items,p) { 	// level 3 function 	// p stands for f,m params
			
			if (items[item].indexOf('--') == -1 ) {
				var e = p.end[item]; // animation end point
				var css = p.text.css; // css of item
				console.log(item + ' position: top='+e.top+' ; left='+e.left);	
				
				var clname = sectionName+slideName + "items_4b";
				$(ssId).append('<div class="'+clname+'" id="' + ss + item + '"></div>');
		
				item_text = items[item].split('|')[0];
		
				if (item_text.indexOf('assets/') > -1) {
					item_text = item_text.replace('==', '');
					item_text = item_text.replace('--', '');
					$(ssId + item).append('<div class="text_t" id="' + ss + item + 'text"><img src="' + item_text + '"></div>')
						.css(css.main);
				} else {
					item_text = item_text.replace('==', '');
					$(ssId + item).append('<div class="text_t" id="' + ss + item + 'text">' + item_text + '</div>')
						.css(css.main);
				}
				
				if ($(ssId+'_photo_div').length) {
					
				} else {
					$(ssId + item)	
						.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 800, function(){})
				}
					/*
					.hover(
						function() {
							
							$( this ).css("background","rgb(255,255,255)");
						},
						function() {
							$( this ).css("background","rgb(254,255,188)");
						}
					)*/;
						
				$(ssId+item + 'text').css(css.text);
				
				$(ssId + item).on('dragstart', function(event) {
						$(this).css("border", "1px solid #1fc8ff");
						$(this).attr('drp_in', '');
					});
			}
		}        
			
		   /* function append_item_text_2a(p,item,items,backWidth) { 	// level 3 function 	// p stands for f,m params
			var n = p.name; // f or m name
			var e = p.end; // animation end point
			var css = p.text.css; // css of item
			
			$(ssId).append('<div class="'+ n +'_items" id="' + ss + item + '"></div>');
	
			$(ssId + item)
				.append('<div class="text'+n+'b" id="' + ss + item + 'background"></div>')
				.append('<div class="text'+n+'t" id="' + ss + item + 'text">' + items[item] + '</div>')
				.css(css.main)
				.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 1000, function(){});
			
			$(ssId+item + 'background').css(css.background);
			
			$(ssId+item + 'text').css(css.text);
			e.left += 20 + backWidth;// distance between images left
		}   */   
	}  
        
	function get_items_places(items_tops) {
		var items_places = [];

		var l = items_tops.length;
		var i;
		var j;
		var min;
		var iplace;

		for (i=0;i<l;i++) {
			iplace = 0;
			for (j=0;j<l;j++) {
					if (items_tops[i]>items_tops[j]) {
							iplace++;
					}
			}
			items_places.push(iplace);
		}
		console.log('items_places:');
		console.log(items_places);
		return items_places;
	}
	
	function image_mDraggable_4b(classId,ssId,zIndexChange) {			// level 1 function		// make class dragable and snapable to f_items
		// make all imagem draggable
                //alert(classId);	
		var dObject;
        var clname = "."+sectionName+slideName + "f_items_2a";
		
		
		dObject = {			
			containment:ssId,
			snapTolerance: 60,
			snapMode: "inner",
			start: function(){
				console.log("zIndexChange: "+zIndexChange);
				console.log($(this));
				$(this).css('zIndex',zIndexChange++);
			},
							
		};                 
                
		var clid = "#"+sectionName+slideName;
			
		var fclass = clid + " .ui-droppable, "+ clid + " " + clname;
		var cnodot = clname.replace(".","");
		
		$(fclass).droppable({   
			tolerance: 'intersect',               
			over: function(event, ui) {
				//var nHeight = ($(this).height()-4) + "px";
				//$("<div>").addClass("hoverClass").appendTo($(this)).css("height", nHeight);                  
				$(this).children('.drp2').css('border', '1px dotted red');
			},               
			out: function(event, ui) {
				 //$(this).find(".hoverClass").remove();
				 $(this).children('.drp2').css('border', '1px dotted black');
				 
				   if ($(this).hasClass(cnodot)){
					  ui.draggable.removeClass("dropped");
				  }
			},               
			drop: function(event, ui) {
				
				 //$(this).find(".hoverClass").remove(); 
				 $(this).children('.drp2').css('border', '1px dotted black');
				
				 var cnt = 0;
				 var con_id = $(this).attr('id');
				 
				 var z_max = 0;
				 $('.ui-draggable').each( function() {
					 z_max = Math.max($(this).css('z-index'), z_max);
				 });
				 
				 $('.ui-draggable').each( function() {
					 if ($(this).attr('drp_in') == con_id) {
						 var pos = $(this).position();
						 pos.top = pos.top + 30;
						 pos.left = pos.left + 30;
						 $(this).css('top', pos.top);
						 $(this).css('left', pos.left);
						 $(this).css('z-index', z_max+5);
						 $(this).css('border', '1px solid #1fc8ff');
						 $(this).attr('drp_in', '');
						
					 }
				 });
				
				 ui.draggable.attr('drp_in', $(this).attr('id'));
						  	  
				 ui.draggable.addClass("dropped");		 
				                     
			}
		});               
		
		$(classId).draggable(dObject);

		// make dragable after click on top
		$(classId).click(function(zIndexChange) {
			$(this).css('zIndex',zIndexChange++);
		});	
	}
	
	function image_mDraggable(classId,ssId,zIndexChange,dragObjectType) {			// level 1 function		// make class dragable and snapable to f_items
		// make all imagem draggable
                //alert(classId);	
		var dObject;
                var clname = "."+sectionName+slideName + "f_items_2a";
		if(dragObjectType == 1){
			dObject = {
				containment:ssId,
				snapMode: "inner",
				start: function(){
						console.log("zIndexChange: "+zIndexChange);
						console.log($(this));
						$(this).css('zIndex',zIndexChange++);
					}
			};
			
		}else if (dragObjectType == 2){			
                        
                      //  var clname = "."+sectionName+slideName + "f_items_2a";
                        dObject = {
				//snap: '.f_items',
                                snap: clname,
				containment:ssId,
				snapMode: "inner",
                                //snapMode: "outter",
				snapTolerance: 20,
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				}
			};               
		}else if (dragObjectType == 3){
			dObject = {			
				snap: '.container',
				containment:ssId,
				snapMode: "inner",
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					//console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				}
			};                
		}else if (dragObjectType == 4){
			dObject = {			
				containment:ssId,
				snapTolerance: 60,
				snapMode: "inner",
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				},
                                
			};                
		} 
                
            var clid = "#"+sectionName+slideName;
           		
            var fclass = clid + " .ui-droppable, "+ clid + " " + clname;
            var cnodot = clname.replace(".","");
            
            $(fclass).droppable({   
                tolerance: 'intersect',               
                over: function(event, ui) {
                    var nHeight = ($(this).height()-4) + "px";
                    $("<div>").addClass("hoverClass").appendTo($(this)).css("height", nHeight);                  
                },               
                out: function(event, ui) {
                     $(this).find(".hoverClass").remove();
                     
                       if ($(this).hasClass(cnodot)){
                          ui.draggable.removeClass("dropped");
                      }
                },               
                drop: function(event, ui) {
                     $(this).find(".hoverClass").remove(); 
                                        
                     if ($(this).hasClass(cnodot)){
                         
                          var containerTop = $(this).position().top;
                          var draggContHeight = ui.draggable.height() - 26;
                          
                          var topPadding = (draggContHeight + containerTop) + "px";               
                          
                          if (dragObjectType != 2) {
							  ui.draggable.css("top",topPadding);
							  ui.draggable.css("left",$(this).css("left"));
						  }
                          ui.draggable.addClass("dropped");
                          
                          //alert(ui.draggable.attr("id"));                               
                     }                    
                }
            });               
            
            $(classId).draggable(dObject);

            // make dragable after click on top
            $(classId).click(function(zIndexChange) {
                $(this).css('zIndex',zIndexChange++);
            });	
	}
	
	function image_mDraggable_2a(classId,ssId,zIndexChange,dragObjectType) {			// level 1 function		// make class dragable and snapable to f_items
		// make all imagem draggable
                //alert(classId);	
		var dObject;
                var clname = "."+sectionName+slideName + "f_items_2a";
		if(dragObjectType == 1){
			dObject = {
				containment:ssId,
				snapMode: "inner",
				start: function(){
						console.log("zIndexChange: "+zIndexChange);
						console.log($(this));
						$(this).css('zIndex',zIndexChange++);
					}
			};
			
		}else if (dragObjectType == 2){			
                        
                      //  var clname = "."+sectionName+slideName + "f_items_2a";
                        dObject = {
				//snap: '.f_items',
                                snap: clname,
				containment:ssId,
				snapMode: "inner",
                                //snapMode: "outter",
				snapTolerance: 20,
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				}
			};               
		}else if (dragObjectType == 3){
			dObject = {			
				snap: '.container',
				containment:ssId,
				snapMode: "inner",
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					//console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				}
			};                
		}else if (dragObjectType == 4){
			dObject = {			
				containment:ssId,
				snapTolerance: 60,
				snapMode: "inner",
				start: function(){
					console.log("zIndexChange: "+zIndexChange);
					console.log($(this));
					$(this).css('zIndex',zIndexChange++);
				},
                                
			};                
		} 
                
            var clid = "#"+sectionName+slideName;
           		
            var fclass = clid + " .ui-droppable, "+ clid + " " + clname;
            var cnodot = clname.replace(".","");
            
            $(fclass).droppable({   
                tolerance: 'intersect',               
                over: function(event, ui) {
                    var nHeight = ($(this).height()-4) + "px";
                    $("<div>").addClass("hoverClass").appendTo($(this)).css("height", nHeight);                  
                },               
                out: function(event, ui) {
                     $(this).find(".hoverClass").remove();
                     
                       if ($(this).hasClass(cnodot)){
                          ui.draggable.removeClass("dropped");
                      }
                },               
                drop: function(event, ui) {
                     $(this).find(".hoverClass").remove(); 
                                        
                     if ($(this).hasClass(cnodot)){
                         
                          var containerTop = $(this).position().top;
                          var draggContHeight = ui.draggable.height() - 26;
                          
                          var topPadding = (draggContHeight + containerTop) + "px";     
                          
                          var same_pos = false
                          $(ssId + ' .ui-draggable').each( function() {
							  var pos = $(this).position();
							  
							  if ($(this).attr('id') != ui.draggable.attr('id')) {
								  //console.log('current', pos, $(this).attr('id'));
								  //console.log('another', ui.draggable.position(), ui.draggable.attr('id'));
								  if ((pos.left == ui.draggable.position().left) && (pos.top == ui.draggable.position().top)) {
									  ui.draggable.css('top', (ui.draggable.position().top + 30) + 'px')
								  }
							  }
							  
						  })          
                          
                          if (dragObjectType != 2) {
							  ui.draggable.css("top",topPadding);
							  ui.draggable.css("left",$(this).css("left"));
						  }
                          ui.draggable.addClass("dropped");
                          
                          //alert(ui.draggable.attr("id"));                               
                     }                    
                }
            });               
            
            $(classId).draggable(dObject);

            // make dragable after click on top
            $(classId).click(function(zIndexChange) {
                $(this).css('zIndex',zIndexChange++);
            });	
	}
	
	function appendFreeAnswer(ssId, ss, tO) {						// level 1 function
		var styleObject;
		
		styleObject = {
			'position':'absolute',
			'width':'1160px',
			'height':'300px',
			'top':'245px',
			'left':'50px',
			"z-index": "1000",
			'text-indent':'0px',
			'font-family':'Arial',
			'font-size': '28px',
			'line-height': '35px'
		};
		
		styleObject_textarea = {
			'background-color': '#f1f5f9',
			'border-color': '#b5d4f9',
			'border-style': 'solid',
			'border-width': '1px',
			'font-size': '20px',
			'height': '100%',
			'width': '100%',
			'z-index': '1000'
		}; 
        
           
                
        $(ssId).append('<div class="" id="' +ss+'freeanswer"><textarea id="'+ss+'answer_input"></textarea></div>');
        $(ssId).append('<div class="" id="' +ss+'level"></div>');
        
	    $(ssId+'freeanswer').css(styleObject);
	    $(ssId+'answer_input').css(styleObject_textarea);
	    
	    var free_top = $(ssId + 'question').position().top + $(ssId + 'question').outerHeight() + 24;
	    $(ssId+'freeanswer').css('top', free_top + 'px');

	}

    function appendQuestion(ssId, ss, tO, styleType) {						// level 1 function
		var styleObject;
		if (styleType == 1){
			styleObject = {
				'position':'absolute',
				'width':'1110px',
				'top':'0px',
				'left':'50px',
				'z-index': '6',
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '26px',
				'line-height': '35px',
				'color': '#008fc5'
			};
        }
		else if (styleType == 2){
			styleObject = {
				'position':'absolute',
				'width':'1110px',
				'top':'0px',
				'left':'50px',
				'z-index': '6',
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '26px',
				'line-height': '35px',
				'color': '#008fc5'
			};
        }            
		else if (styleType == 3){
			styleObject = {
				'position':'absolute',
				'width':'1110px',
				'top':'0px',
				'left':'50px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '26px',
				'line-height': '35px',
				'color': '#008fc5'
			};
        }
		else if (styleType == 4){
			styleObject = {
				'position':'absolute',
				'width':'1110px',
				'top':'0px',
				'left':'50px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '26px',
				'line-height': '35px',
				'color': '#008fc5'
			};         
        }
		else{
			styleObject = {
				'position':'absolute',
				'width':'1110px',
				'top':'0px',
				'left':'50px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '26px',
				'line-height': '35px',
				'color': '#008fc5'
			};
        }       
        
        var qq = tO['question'];
        qq = qq.replace(/\|sub\|/g, '<sub>');
        qq = qq.replace(/\|-sub\|/g, '</sub>');
        
        qq = qq.replace(/\|sup\|/g, '<sup>');
        qq = qq.replace(/\|-sup\|/g, '</sup>');
        
        qq = qq.replace(/-->/g, '→');
                
        $(ssId).append('<div class="" id="' +ss+'question">'+qq+'</div>');
	    $(ssId+'question').css(styleObject);
	    
	    $(ssId+'question p').css({'margin-top':'1em', 'margin-bottom': '0'});
	    
	    $(ssId+'question p:first').css({'margin-top':'0', 'margin-bottom': '0'});
	}
	
	function compareAnswers_4b(right,answered,ssId, tO) {
		var result_array =[];
		var count=0;
		var l = right.length;

		console.log('obj', tO);
		cnt = 0;
		f_cnt = 0;
		for (var i = 0; i < l; i++) {
				
				itm = strip_html_tags(tO['items']['item_'+i]).split('|');
				console.log('checking item', itm);
				
				if ((itm[0].indexOf('--') == -1) && (itm[0].indexOf('==') == -1)) {
					cnt = cnt + 1;
				}
				
				if (itm[0].indexOf('assets/') > -1) {
					obj = $(ssId + ' [drp_in='+ss+'_text_place_'+i+']');
					obj_t = strip_html_tags(obj.children().children().attr('src'));
				} else {					
					obj = $(ssId + ' [drp_in='+ss+'_text_place_'+i+']');
					obj_t = strip_html_tags(obj.children().html());
				}				
				console.log('obj_t', obj_t);
				
				if (itm.indexOf(obj_t) > -1) {			
					result_array[i] = true;
					count++;	// count right answers
					obj.css("border", "1px solid rgb(190,190,190)");
				}
				else{
					result_array[i] = false;
					obj.css("border", "2px solid rgb(255,72,0)");
					if (obj.attr('id') != undefined) {
						f_cnt++;
					}
				}
		}
			
		console.log('result_array:');
		console.log(result_array);

		l = cnt;
		if ((count == l) && (f_cnt == 0)) {
				return true;
		}
		else{
				return false;
		}
		//return result;
	}

	function compareAnswers_11a(right,answered,ssId) {
		var result_array =[];
		var count=0;
		var l = right.length;

		for (var i = 0; i < l; i++) {
				if (right[i] == answered[i]) {
					result_array[i] = true;
					count++;	// count right answers
					$(ssId+'item_'+i).css("border", "1px solid rgb(190,190,190)");
				}
				else{
					result_array[i] = false;
					$(ssId+'item_'+i).css("border", "2px solid rgb(255,72,0)");
				}
		}
		console.log('result_array:');
		console.log(result_array);

		if (count == l) {
				return true;
		}
		else{
				return false;
		}
		//return result;
	}

    function checkTestAnswer_3e(tO,p,randPlaces,drop_in) {
		var i=0;
		var right = randPlaces;
		var xPrev=0;
		var correct = true;
		var count = 0; // count right answers
	
		var answered = items_caption_no();
		
		var new_right = prepare_right_answer();
		
		var correct = compareAnswers_3e(new_right,answered);
		
		
		function prepare_right_answer() {
			var new_right = [];
			var l = right.length;
			for (var i=0;i<l;i++) {
				new_right.push(tO['answer'][right[i]]);
			}
			return new_right;
		}
		
		function items_caption_no() {
			var answered = [];
			var item;
			for (item in drop_in.caption) {
				console.log('JSF items_caption_no; drop_in.caption: ');
				console.log(drop_in.caption);
				console.log(drop_in.caption[item]);
				if (drop_in.caption[item] != 0) {
					var caption_no = drop_in.caption[item];
					caption_no = parseInt(caption_no.replace('caption_',''));
				}
				else{
					var caption_no = 0;
				}
				answered.push(caption_no);
			}
			return answered;
		}	

		console.log('Answered: '+ answered);
		console.log('Right answers: '+ right);
		console.log('prepared answer: '+ new_right);
				
		testAnswer(correct);
		return correct;
	}      
        
	function compareAnswers_3e(right,answered) {
		var result_array =[];
		var count=0;
		var l = right.length;
		
		var got_img = false;
		if ($('.iu-ui-draggable img').length) {
			got_img = true;
		}

		for (var i = 0; i < l; i++) {
			if (right[i] == answered[i]) {
				result_array[i] = true;
				count++;	// count right answers
				
				if (got_img) {
					$(ssId+'item_'+i + ' .text_t').css("border", "1px solid #e0e0e0");
				} else {
					$(ssId+'item_'+i).css("border", "1px solid #fff");
				}
			}
			else{
				result_array[i] = false;
				
				if (got_img) {
					$(ssId+'item_'+i + ' .text_t').css("border", "1px solid rgb(255,72,0)");
				} else {
					$(ssId+'item_'+i).css("border", "1px solid rgb(255,72,0)");
				}
			}
		}
		console.log('result_array:');
		console.log(result_array);

		if (count == l) {
				return true;
		}
		else{
				return false;
		}
		//return result;
	 }
        
	function compareAnswers(right,answered,p,ssId) {
		var result_array =[];
		var count=0;
		var l = right.length;
		
		for (var i = 0; i < l; i++) {
			var id = ssId + 'item_'+ i + 'check_or_radio';
			var className = $(id).attr('class');
			
			if (right[i] == answered[i]) {
				result_array[i] = true;
				count++;	// count right answers
			}
			else{
				if (className == 'checked') {
					$(id)
						.css('background',"url(" + p.check.checked_false + ") no-repeat 0px 0px");
				}
				result_array[i] = false;
			}
		}
		console.log('result_array:');
		console.log(result_array);
		
		if (count == l) {
			return true;
		}
		else{
			return false;
		}
	}
        
    // apend texts
	function append_texts() {
		for (text in doO.texts) {
			append_text_2(text);
		}
	}
	
	// apend two texts in two columns
	function append_text_2(content) { // level 1 function
		console.log('Append: ' + content);
		var text = doO.texts[content].text;
		var css = doO.texts[content].css;

		console.log('Text: ' + text);

		$(ssId).append('<div class="" id="' +ss+content+'">'+text+'</div>');
		$(ssId+content).css(css);
	}

	function append_images() {
		for (image in doO.images) {
			append_images_2(image);
		}
	}
	
	function append_images_2(content){
		console.log('Append image');
		var image = doO.images[content].image;
		var css   = doO.images[content].css;

		console.log('Image: ' + image);
		
		$(ssId)
			.append('<div class="image" id="' + ss + content +'"><img src="' + image + '" alt="" ></img></div>');
			
		$(ssId +content)
			.css(css);
	}     
	
	function normalize_height(check_button_top) {
		$('#section0slide0check').css('top', check_button_top + 'px');
		//$('#section0slide0check').css('width', '195px');
		$('#section0slide0check').css('height', '66px');
		//$('#section0slide0check').css('left', '1016px');
		
		$('#section0').css('width', '1260px');
		$('#section0slide0').css('width', '1260px');
		
		if ((frm_id == '1t') || (frm_id == '3t') || (frm_id == '5t') || (frm_id == '7t') || (frm_id == '9t') || (frm_id == '11t') || (frm_id == '12t') || (frm_id == '14t') ) {
			$('#section0slide0').css('background-color', '#f7f7f7');
			$('#section0slide0 .ui-droppable .bkg').css('background-color', '#f7f7f7');
			$('#section0slide0 .ui-droppable').css('background-color', '#f7f7f7');
			$('#section0slide0 .ui-droppable .textfb').css('background-color', '#f7f7f7');
		}
		
		$('#slideshow').css('height', (check_button_top + 25+66) + 'px');
		$('#pageContainer').css('height', (check_button_top + 25+66) + 'px');
		$('#slidesContainer').css('height', (check_button_top + 25+66) + 'px');
		
		$('#section0').css('height', (check_button_top + 25+66+2) + 'px');
		$('#section0slide0').css('height', (check_button_top + 25+66+2) + 'px');
		
		if (parent.setIframeHeight) {
			parent.setIframeHeight(check_button_top + 25+66+2, frm_id);
		}
	}
	
	function strip_html_tags(html) {
		
	   var tmp = document.createElement("DIV");
	   tmp.innerHTML = html;
	   return tmp.textContent || tmp.innerText || "";
	   
	}
