var timeout = {
	tid: 0,
	value: 500
};

var cycle = {
	tid: 0,
	counter: 2,
	value: 2500
}

window.addEvent('load', initHome);

function initHome() {
	/*var drop = $('nav');
	drop.addEvent('mouseenter', function() {
		clearTimeout(timeout.tid);
	});
	drop.addEvent('mouseleave', resetTimeout);
	$$('#header ul.nav').each(function(item) {
		item.addEvent('mouseenter', function() {
			clearTimeout(timeout.tid);
			if (drop.getStyle('height') == '0px') {
				new Fx.Style(drop, 'height', { onComplete: function() {
					$$('#nav ul li').each(function(li) {
						new Fx.Style(li, 'opacity').start(0, 1);
					});
				}, duration:200 }).start(0, 160);
				new Fx.Style(drop, 'padding-top', { duration:200 }).start(0, 20);
				new Fx.Style(drop, 'padding-bottom', { duration:200 }).start(0, 20);
			}
		});
		item.addEvent('mouseleave', resetTimeout);
	});
	$$('#header ul.nav li').each(function(item, i) {
		item.addEvent('mouseenter', function() {
			$$('#nav ul').each(function(e, j) {
				if (i == j+1) {
					e.setStyle('color', '#fff');
				}
			});
		});
		item.addEvent('mouseleave', function() {
			$$('#nav ul').each(function(e) {
				e.setStyle('color', '#333');
			});
		});
	});
	$$('#nav ul').each(function(item) {
		item.addEvent('mouseenter', function() {
			item.setStyle('color', '#fff');
		});
		item.addEvent('mouseleave', function() {
			item.setStyle('color', '#333');
		});
	});*/

	var images = $$('#clients img');
	images[cycle.counter].setStyle('display', 'block');
	new Fx.Style(images[cycle.counter], 'opacity').start(0, 1);
	cycle.tid = cycle_trigger.periodical(cycle.value);
}

var cycle_trigger = function() {
	var images = $$('#clients img');
	new Fx.Style(images[cycle.counter], 'opacity', { onComplete: function() {
		images[cycle.counter].setStyle('display', 'none');
		if (cycle.counter + 1 < 24) {
			images[cycle.counter+1].setStyle('display', 'block');
			new Fx.Style(images[cycle.counter+1], 'opacity').start(0, 1);
		} else {
			images[0].setStyle('display', 'block');
			new Fx.Style(images[0], 'opacity').start(0, 1);
		}
		if (cycle.counter == 23) {
			cycle.counter = 0;
		} else {
			cycle.counter++;
		}
	}}).start(1, 0);
}

function resetTimeout() {
	clearTimeout(timeout.tid);
	timeout.tid = setTimeout(hide_menu, timeout.value);
}

function hide_menu() {
	var drop = $('nav');
	if (drop.getStyle('height') == '160px') {
		new Fx.Style(drop, 'height', { onStart: function() {
			$$('#nav ul li').each(function(li) {
				new Fx.Style(li, 'opacity', { duration: 100 }).start(1, 0);
			});
		}, duration:200 }).start(160, 0);
		new Fx.Style(drop, 'padding-top', { duration:200 }).start(20, 0);
		new Fx.Style(drop, 'padding-bottom', { duration:200 }).start(20, 0);
	}
}

sfHover = function() {
	var sfEls = document.getElementById("header").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);