    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 = text.split('|');
		
		var l = text.length;
		var new_text = '';
		for (var i =0;i<l;i++) {
			if (i==(l-1)) {
				new_text += text[i];	
			}
			else{
				new_text += text[i] + '<div id ="'+ss+'_text_place_'+i+'"></div>';
			}
		}
		
		$(ssId)
			.append('<div class="" id="' +ss+'caption">'+new_text+'</div>');
	
		$(ssId+'caption div')
			.css({
				'width':'249px',
				'height':'36px',
				'background':"rgb(222,223,223)",
				'display': 'inline-block',
				'color':'#ffffff'
			});
		
		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'));
				var field_top = $(this).position().top / resizeAddValue + 180;
				var field_left = $(this).position().left / resizeAddValue + 60;
				
				$(ui.draggable)
					.animate({ 'top': field_top  + 'px', 'left': field_left + 'px'}, 400, function(){})
					.css({
						"background":"rgb(255,255,255)",
						"border":'1px solid rgb(223,225,226)'
						});
				}
			);
		}
		
		$(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'
			});
                        //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);
		
		$(ssId + caption + 'container')
			.css(p.container)
			.css('left',left);
		
		
		//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 / resizeAddValue;
					var left = $(this).position().left / resizeAddValue;
					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);
					order_caption_items();
	
					console.log('drop_in:');
					console.log(drop_in);
	
					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 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 = [];
			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':'0px',});
				
				count ++;	// count right answers
			}
			else{
				console.log('Incorect '+'m_item_' + j + ' check x = '+x + '; leftX = '+answer);
				
				$(ssId+'m_item_' + j + '_wrong_mark')
					.css({'border':'3px solid 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_11a(right,answer,ssId);
		
		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 = [];
                        
                        //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'] = x;
			e['item_'+j]['left'] = y;
		}
		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(){})
				.append('<div id="' + ss + item + '_wrong_mark"></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>');
	
			$(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(){})
				.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
		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];
			
			$(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+'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+'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
			var css = p.text.css; // css of item
			//alert(ssId);
			$(ssId)
				.append('<div class="text_t" id="' + ss + item + 'text">' + items[item] + '</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 += p.step;
			p.check.top += p.step;
			
			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>');
		
			var topp = Math.round(e.top / 50.0) * 50;
			
			$(ssId + item)
				.append('<div class="text_t fixed_pos" id="' + ss + item + 'text">' + items[item] + '</div>')
				.css(css.main)
				
				//.animate({ 'top': e.top + 'px', 'left': '30px'}, 400, function(){})
				.hover(
					function() {
						$( this ).css("background","rgb(254,255,188)");
					},
					function() {
						$( this ).css("background","rgb(255,255,239)");
					}
				)
				.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);
					});
					
					//console.log(objs);
					objs.sort(function(a,b) { return parseFloat(a.top) - parseFloat(b.top) } );
					for (var i=0; i<objs.length;i++) {
						var topp = (i * 60) + 120;
						$(objs[i].element).parent().animate({ 'top': topp + 'px', 'left': '30px'}, 400, function(){})
					}
									
				});
						
			$(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>');
	
			$(ssId + item)
				.append('<div class="text_t" id="' + ss + item + 'text">' + items[item] + '</div>')
				.css(css.main)
				.animate({ 'top': e.top + 'px', 'left': e.left + 'px'}, 800, function(){})
				.hover(
					function() {
						$( this ).css(css.hover_on);
					},
					function() {
						$( this ).css(css.hover_out);
					}
				)
				.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);
					
					if (drop_in.caption[item_id] == 0) {}
					else{
						var top = $(ssId+caption+'container').position().top / resizeAddValue;
						var left = $(ssId+caption+'container').position().left / resizeAddValue;
						
						console.log('dropactivate item:' + item_id);
						
						remove_item();
						drop_in.caption[item_id] = 0;
						order_caption_items();	
					}
					
					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_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 height = " + drop_in.height[item] + '; Item text = '+drop_in.text[item]);
						}
						return top;
					}
				} );
			
			$(ssId+item + 'text')
				.css(css.text);
			
			var height = $(ssId+item + 'text').height();
	
			$(ssId + item)
				.css('height',(height+10));
			
			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
			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>');
	
			$(ssId + item).append('<div class="text_t" id="' + ss + item + 'text">' + items[item] + '</div>')
				.css(css.main)
				.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);
		}        
			
		   /* 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(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++);
				},
                                revertDuration: 300
                                ,
                                revert: function (droppableObj) {                          
                                       
                                    if (droppableObj != false){
                                        
                                        if (droppableObj.hasClass('filled')) {
                                             //$(this).data("parent", "");
                                           //alert("has");
                                            //alert($(this).data("parent"));
                                            $("#" + $(this).data("parent")).addClass("filled");
                                           
                                            return true;
                                       }else{                                     
                                           
                                            droppableObj.addClass('filled');                                           
                                           // alert("added");
                                       }                                        
                                        
                                        //if (!droppableObj.hasClass('filled')){
                                         //     droppableObj.addClass('filled')
                                         // }                                
                                        
                                    }else{
                                        $(this).data("parent", "");                                        
                                    }
                                    //console.log("ui",droppableObj);
                                    //if (droppable.hasClass('filled')) {
                                           //alert("has");
                                           // return true;
                                      // }
                                       console.log("lalala:",droppableObj);
                                    },
                                    stop:function(evt,ui){
                                        //alert($(this).data("parent"));
                                    //$("#" + $(this).data("parent")).addClass("filled");    
                                        
       
    }
			};               
		}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', 
                accept:function(d) { 
                    if(!d.hasClass("resizableShape")){ //disable drop for shape boxes
                        //$(this).addClass('filled');
                        return true;
                    }
                },
                over: function(event, ui) {
                    var nHeight = ($(this).height()-4) + "px";
                    $("<div>").addClass("hoverClass").appendTo($(this)).css("height", nHeight);                  
                },               
                out: function(event, ui) {                                    
                     
                    // alert($(this).length);
                    //if (ui.draggable.hasClass($(this).attr("id"))){
                    if (ui.draggable.data("parent") == $(this).attr("id")){
                        $(this).removeClass('filled');
                    }
                     
                     $(this).find(".hoverClass").remove();
                     
                       if ($(this).hasClass(cnodot)){
                          ui.draggable.removeClass("dropped");                          
                      }
                      
                      //alert($(this).attr("id"));
                      //ui.draggable.removeClass($(this).attr("id"));
                      //ui.draggable.data("parent", "");
                },               
                drop: function(event, ui) {
                    //alert("drop");
                    //$(this).append("<div class='itemcopy'>"+ui.draggable.html()+"</div>");
                    
                    //ui.draggable.addClass($(this).attr("id"));
                    //alert("s");
                    if (!$(this).hasClass("filled")){
                        ui.draggable.data("parent", $(this).attr("id"));
                        
                       // ui.draggable.data("has", 1);
                }
                    
                    
                    $(this).find(".hoverClass").remove(); 
                                       
                     if ($(this).hasClass(cnodot)){
                         
                          var containerTop = $(this).position().top / resizeAddValue;
                          var draggContHeight = ui.draggable.height() - 26;
                          
                          var topPadding = (draggContHeight + containerTop) + "px";               
                          
                          ui.draggable.css("top",topPadding);
                          ui.draggable.css("left",$(this).css("left"));
                          ui.draggable.addClass("dropped");
                          
                          //alert(ui.draggable.attr("id"));                               
                     }                    
                }
            });               
            
           
            //$(classId).draggable(dObject);
            $(classId).draggable(dObject);

            // make dragable after click on top
            $(classId).click(function(zIndexChange) {
                $(this).css('zIndex',zIndexChange++);
            });	
	}

    function appendQuestion(ssId, ss, tO, styleType) {						// level 1 function
		var styleObject;
		if (styleType == 1){
			styleObject = {
				'position':'absolute',
				'width':'1043px',
				'height':'70px',
				'top':'43px',
				'left':'72px',
				'z-index': '6',
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px'
			};
        }
		else if (styleType == 2){
			styleObject = {
				'position':'absolute',
				'width':'1043px',
				'height':'70px',
				'top':'43px',
				'left':'72px',
				'z-index': '6',
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px'
			};
        }            
		else if (styleType == 3){
			styleObject = {
				'position':'absolute',
				'width':'1043px',
				'height':'70px',
				'top':'43px',
				'left':'72px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px'
			};
        }
		else if (styleType == 4){
			styleObject = {
				'position':'absolute',
				'width':'1060px',
				'height':'70px',
				'top':'43px',
				'left':'60px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px'
			};         
        }
		else{
			styleObject = {
				'position':'absolute',
				'width':'1043px',
				'height':'70px',
				'top':'45px',
				'left':'60px',
				"z-index": "6",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px'
			};
        }  
        
        
        styleObject2 = {
				'position':'absolute',
				'height':'30px',
				'top':'15px',
				'right':'30px',
				"z-index": "8",
				'text-indent':'0px',
				'font-family':'Arial',
				'font-size': '28px',
				'line-height': '35px',
				'background-image': 'url("img/zvaigzdute.png")',
				'background-repeat': 'repeat-x',
				'background-position': 'right center'
			};             
                
        $(ssId).append('<div class="" id="' +ss+'question">'+tO['question']+'</div>');
        $(ssId).append('<div class="" id="' +ss+'level"></div>');
	    $(ssId+'question').css(styleObject);
	    $(ssId+'level').css(styleObject2);
	    $(ssId+'level').css('width', (35 * tO['level']) + 'px');
	}

	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 = [];
			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;

		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 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);
	}     
