var last_cover=0;
var last_win=0;
var last_teg = null;
var last_teg2 = null;

function cover(id, teg){
//alert(id+"\n"+last_win+"\n"+last_cover);	if(typeof(photos[id]) != 'undefined'){
		if(typeof(photos[id][last_win]) != 'undefined'){
			mark(teg);
			door(photos[id][last_win]);
			last_cover = id;
		}else if(typeof(photos[id][0]) != 'undefined'){
			mark(teg);
			door(photos[id][0]);
			last_cover = id;
			if(last_teg2){
				last_teg2.firstChild.className = "";
			}
		 }else{			message();
		}
	}else{
		message();
	}
	return false;
}

function win(id, teg2){
	if(typeof(photos[last_cover][id]) != 'undefined'){
		if(last_teg2){
			last_teg2.firstChild.className = "";
		}
		teg2.firstChild.className="actimg";
		last_teg2 = teg2;

		door(photos[last_cover][id]);
		last_win = id;
	}else{
		message();
	}
	return false;
}

function mark(teg){
	if(last_teg){
		last_teg.firstChild.className = "";
	}
	teg.firstChild.className="actimg";
	last_teg = teg;
}

function door(text){
	//alert("cover "+last_cover+"\nwin "+last_win)
	document.getElementById('door').innerHTML=text;
}

function message(){
	alert("Данное изображение не загружено");
}
