function D(d) { return document.getElementById(d); }
var doing = 1;
var stop1 = false;
var stop2 = false;

function flipleft() {

	var lha = D("lha");
	var lhb = D("lhb");
	
	var cur = lha.style.backgroundPosition;
	
	var nexta;
	var nextb;
	
	if (cur && cur == "0px -183px")	{
		nexta = "0px 0px";
		nextb = "0px 0px";
	} else {
		nexta = "0px -183px";
		nextb = "0px -239px";
	}
	
	lha.style.backgroundPosition = nexta;
	lhb.style.backgroundPosition = nextb;
}

function flipright() {

	var rha = D("rha");
	var rhb = D("rhb");
	
	var cur = rha.style.backgroundPosition;
	
	var nexta;
	var nextb;
	var arr = ["0px 0px", "0px -183px", "0px -366px"];
	var arr2 = ["0px 0px", "0px -203px", "0px -406px"];
	
	do {
		var i = parseInt(Math.random() * 2.3);
		nexta = arr[i];
		nextb = arr2[i];
	} while (nexta == cur);
	
	rha.style.backgroundPosition = nexta;
	rhb.style.backgroundPosition = nextb;

}


window.onload = function() {
	setInterval( function() {
			if (doing == 1) {
				if (!stop2) 
					flipright();			
			} else {
				if (!stop1)
					flipleft();
			}
			doing *= -1;
		}, 5000);
};


function T(id) {
	var d = D("map_" + id);
	var l = D("l_" + id);
	if (!d) return;
	d.style.display = d.style.display == "block" ? "none" : "block";
	l.className = d.style.display == "block" ? "opened" : "closed";
}


function roll(id) {
	if (id == "contactmenu") {
		cancelunroll2();
	} else {
		cancelunroll();
	}
	try {
		D(id).style.display = "block";
		if (id == "contactmenu") {
			stop2 = true;
		} else {
			stop1 = true;
		}
	} catch(ex) {}
}
var hiderId;
function unroll(id) {
	hiderId = setTimeout(function() {
		try {
			D(id).style.display = "none";
			stop1 = false;
		} catch(ex) {}			  
	  }, 600);
}

function cancelunroll() {
	clearTimeout(hiderId);	
}

var hiderId2;
function unroll2(id) {
	hiderId2 = setTimeout(function() {
		try {
			D(id).style.display = "none";
			stop2 = false;

		} catch(ex) {}			  
	  }, 600);
}

function cancelunroll2() {
	clearTimeout(hiderId2);	
}