window.addEvent('domready', function() {

	// Destaques no topo do site
	if ($defined($('highlights'))) {

		window.fxHighlights = function() {
			var items = $$('#highlights li');
			var size = items.length;
			var sel = 0;
			items.each(function(el, i) {
				if (el.hasClass('show')) sel = i;
			}, this);
			var next = sel + 1;
			var next = (next >= size) ? 0 : next;

			var fxFrom = new Fx.Style(items[sel], 'opacity', {
				duration: 2000,
				onComplete: function(el) {
					el.removeClass('show');
					var fxTo = new Fx.Style(items[next], 'opacity', {
						duration: 2000,
						onStart: function(el) {
							el.setStyle('opacity', 0);
							el.addClass('show');
						}
					});
					fxTo.start(0, 1);
				}.bind(this)
			});
			fxFrom.start(1, 0);
		}

		var items = $$('#highlights li');
		if (items.length > 1) {
			window.fxHighlights.periodical(5000);
		}

	}

	// Web 2
	var web2 = $$('div.logo ul')[0];
	if ($defined(web2)) {

		(function() {
			var items = $$('div.logo ul li');
			var size = items.length;
			if (size == 0) return;
			var sel = 0;
			items.each(function(el, i) {
				if (el.hasClass('show')) sel = i;
			}, this);
			var next = sel + 1;
			var next = (next >= size) ? 0 : next;

			items[next].setStyle('opacity', 0);
			items[sel].setStyle('opacity', 1);

			var fxFrom = new Fx.Style(items[sel], 'opacity', {
				duration: 2500,
				onComplete: function(el) {
					el.removeClass('show');
				}
			});
			fxFrom.start(1, 0);

			var fxTo = new Fx.Style(items[next], 'opacity', {
				duration: 2500,
				onStart: function(el) {
					el.addClass('show');
				}
			});
			fxTo.start(0, 1);

		}).periodical(4000);

	}

	// Rodape
	if ($defined($('footer'))) {
		$$('#footer div.rodape ul li a').each(function(el) {
			el.setStyle('opacity', 0.9);
			el.addEvent('mouseenter', function(e) {
				var fxFade = new Fx.Style(el, 'opacity', {duration:200});
				fxFade.start(0.9, 0.7);
			});
			el.addEvent('mouseleave', function(e) {
				var fxFade = new Fx.Style(el, 'opacity', {duration:200});
				fxFade.start(0.7, 0.9);
			});
		});

		window.scrollFooterTo = function(direction) {
			var ul = $E('#footer div.scroll ul');
			var pos = ul.getStyle('margin-left').toInt();
			if ((direction == 'left') && (pos <= -20)) {
				ul.setStyle('margin-left', pos + 20);
			} else if ((direction == 'right') && (pos >= -500)) {
				ul.setStyle('margin-left', pos - 20);
			}
		};

		var nav_left = $$('#footer div.nav_left')[0];
		var nav_right = $$('#footer div.nav_right')[0];

		if ($defined(nav_left)) {
			nav_left.addEvent('mouseenter', function(e) {
				window.scrollFooter = scrollFooterTo.periodical(50, window, 'left');
			});
			nav_left.addEvent('mouseleave', function(e) {
				$clear(window.scrollFooter);
			});
			nav_right.addEvent('mouseenter', function(e) {
				window.scrollFooter = scrollFooterTo.periodical(50, window, 'right');
			});
			nav_right.addEvent('mouseleave', function(e) {
				$clear(window.scrollFooter);
			});
		}

		// Tooltips rodape
		var tipImoveis = new Tips($$('#footer a.benin_class'), {
			showDelay: 400,
			hideDelay: 400
		});
	}

	// Lateral Accordion
	if ($defined($$('div.lateral')[0])) {
		var accordion = new Accordion('div.lateral h3', 'div.lateral div.tab');
		accordion.display(1);
	}

	// Tooltips - Imoveis recentes
	var tipImoveis = new Tips($$('ul.imoveis_recentes li a'), {
		showDelay: 400,
		hideDelay: 400
	});

	// Tooltips - Rodape
	var tipRodape = new Tips($$('#footer div.scroll ul li'), {
		showDelay: 400,
		hideDelay: 400
	});


	// Cabecalhos
	new MoosIFR(".conteudo h2", {
		flashsrc: "/swf/klavika.swf",
		textcolor: "#265B99",
		linkcolor: "#265B99",
		hovercolor: "#265B99",
		bgcolor: "#FFF",
		wmode: "transparent"
	});



});