	window.onload = init;
	document.getElementById('btnclr1').onclick = clear1;
	document.getElementById('btn1').onclick = check;
	document.getElementById('btn2').onclick = answer;

	var btnClr = document.getElementById('btnclr1');
	var btnValider = document.getElementById('btn1');
	var btnReponses = document.getElementById('btn2');
	var sc = 1;

function init() {
	counter=1
	btnReponses.disabled=true;
	btnReponses.setAttribute('style', "color:#D4D0C8");
	btnValider.disabled=true;
	btnValider.setAttribute('style', "color:#D4D0C8");
}




// add event handler
var addEvent = (function () {
	if (document.addEventListener) {
		return function (el, type, fn) {
			if (el && el.nodeName || el === window) {
				el.addEventListener(type, fn, false);
			} else if (el && el.length) {
				for (var i = 0; i < el.length; i++) {
					addEvent(el[i], type, fn);
				}
			}
		};
		} else {
			return function (el, type, fn) {
				if (el && el.nodeName || el === window) {
					el.attachEvent('on' + type, function () { return fn.call(el, window.event); });
				} else if (el && el.length) {
					for (var i = 0; i < el.length; i++) {
					addEvent(el[i], type, fn);
					}
				}
			};
		}
	})();

// inner variables

var dragItems;
updateDataTransfer();

var dropAreas = document.querySelectorAll('[droppable=true]');

// preventDefault (stops the browser from redirecting off to the text)

function cancel(e) {
	if (e.preventDefault) {
		e.preventDefault();
	}
	return false;
}



// update event handlers
function updateDataTransfer() {
	dragItems = document.querySelectorAll('[draggable=true]');
			for (var i = 0; i < dragItems.length; i++) {
		addEvent(dragItems[i], 'dragstart', function (event) {
			event.dataTransfer.setData('obj_id', this.id);
			return false;
		});
	}
}

// dragover event handler
addEvent(dropAreas, 'dragover', function (event) {
	updateDataTransfer()
		if (event.preventDefault) event.preventDefault();
		// little customization
		this.style.borderColor = "#000";
		return false;
	
});


// drop event handler
addEvent(dropAreas, 'drop', function (event) {
	updateDataTransfer();
	if (event.preventDefault) event.preventDefault();
		var iObj = event.dataTransfer.getData('obj_id');
		var oldObj = document.getElementById(iObj);
		var oldSrc = oldObj.innerHTML;
		var oldThis = this;
		var dID = oldThis.getAttribute('id'); 
			setTimeout(function() {
			oldThis.innerHTML = '<span class="ans" id="a_'+dID+'"><span id="'+iObj+'">'+oldSrc+'</span></span>';
			updateDataTransfer();
			oldThis.setAttribute("droppable", "false");
			btnValider.disabled=false;
			btnValider.setAttribute('style', "color:#000000");

		}, 300);
return false;
});



function clear1() {
	location.reload()
}

function check() {
	sc=1;
	var checkAlbum = document.getElementsByClassName("album");
	for(var i=1; i<=checkAlbum.length; i++) {
		var correctVal = document.getElementById("a_drop_"+i);
		var matchVal = document.getElementById("ans1_"+i);
		var dValue = document.getElementById("drop_"+i).getAttribute('droppable');
		if (dValue == 'false') {
			if (correctVal.innerText== matchVal.innerText) {
					correctVal.setAttribute("style","background-color:#008000; color:#FFFFFF;border:1px solid #008000;");
				} else {
					correctVal.setAttribute("style","background-color:#FF0000; color:#FFFFFF;border:1px solid #FF0000;");
				}
			}
		}
	btnReponses.disabled=false;
	btnReponses.setAttribute('style', "color:#000000");
}

function answer() {
	var answer = document.getElementsByClassName("album");
	if (sc=="1") {
		for(var i=1; i<=answer.length; i++) {
		var getVal = document.getElementById("drop_"+i);
		var corVal = document.getElementById("e_"+i);
			getVal.setAttribute('hidden', 'hidden');
			corVal.removeAttribute('hidden');
		}
		btnValider.disabled=true;
		btnValider.setAttribute('style', "color:#D4D0C8");
		sc += 1
	 } else {
		for(var i=1; i<=answer.length; i++) {
		var getVal = document.getElementById("drop_"+i);
		var corVal = document.getElementById("e_"+i);
			corVal.setAttribute('hidden', 'hidden');
			getVal.removeAttribute('hidden');
		}
		btnValider.disabled=false;
		btnValider.setAttribute('style', "color:#000000");
		sc -= 1
	}
}
