var HEADERS = ["kokous", "navetta", "snagari"];

var title, contact;
var idx = parseInt(Math.random() * 3);
var contactTimer;
var effectOn = false;

function getImagePath() {
	return HEADERS[idx] + ".jpg";
}

function getFlashPath() {
	return HEADERS[idx] + ".swf";
}

function init() {
	title = $('title');
	contact = $('contact');
	
	title.observe('mouseover', onTitleMouseOver);
	title.observe('mouseout', onMouseOut);
	contact.observe('mouseover', onContactMouseOver);
	contact.observe('mouseout', onMouseOut);
}

function onTitleMouseOver() {
	clearTimeout(contactTimer);
	if (effectOn) return;
	
	var titleH = title.getHeight();
	var contactH = contact.getHeight();
	var t = (0 - contactH + titleH) + "px";
	contact.setStyle({ left: "0px", top: t, display: "block", opacity: 0.0,  });
	contact.appear();
	new Effect.Move(contact, { x: 0, y: 21, mode: 'absolute', beforeStart: function() { effectOn = true; }, afterFinish: function() { effectOn = false; } });
}

function onMouseOut() {
	contactTimer = setTimeout(_hideContact, 1000);
}

function _hideContact() {
	contact.appear({ from: 1.0, to: 0.0, duration: 0.5, afterFinish: function() { contact.setStyle({display: "none"}); } });
}

function onContactMouseOver() {
	clearTimeout(contactTimer);
}

document.observe('dom:loaded', init);