﻿var prehome = {
	detachActionListener: null,
	
	adjHeight: function() {
		if ($(window).height() < '754') {
			$('.pre-home h1, .pre-home h1 embed, .pre-home h1 object').height($(window).height() - $('.select-bar').height());
		}
		else {
			$('.pre-home h1, .pre-home h1 embed, .pre-home h1 object').height(625);
		}
	},

	callTracking: function() {
		structure.trackingReady(function() {
			if ($('.pre-home .default-select select').val() == "") {
				tracking.google.call('mi3fCMmltQEQ0ZmG6wM');
			}
		});
	},

	init: function() {
		
		$.getScript('/static/js/lib/jquery-color.js', function(data, success) {
			prehome.detachActionListener = setInterval(prehome.detachSelect, 2000);
		});
		
		$.getScript('/static/js/lib/swfobject.js', function(data, success) {
			swfobject.embedSWF(structure.baseUrl + "static/swf/pre-home.swf", "banner-pre-home", "100%", "624", "10", "expressInstall.swf", {}, {}, {});
			setTimeout(prehome.adjHeight, 2000);
		});

		this.callTracking();
		this.adjHeight();
		$(window).bind('resize', this.adjHeight);
		$('.box-items-found .nav-see-all').neoHover();
		
		$.each($('.footer.clean-mode .highlights ul li.our-address dd'), function(i, item) {
			var itemClass = 'node-' + i + ' ' + $(item).attr('class');
			$(item).attr('class', itemClass);
		});
		
		$('.pre-home .box-state select').bind('change', function(e){
			clearInterval(prehome.detachActionListener);
			
			var _id = $(this).find('option:selected').val();
			
			if(_id == ""){
				$('.pre-home .box-items-found').animate({ left: '620px' },{ time: .5});
				return;
			}

			setTimeout(prehome.detachButton, 1000);
			
			$.ajax({
				url: "/busca/request_total_imoveis_pelo_estado.aspx",
				type: "POST",
				data: { 
					id: _id
				},
				success: function(e){
					$('.pre-home .box-items-found').animate({ left: '790px' },{ time: .8}).find('dl dt').html(e.toString());
				}
			});			
		});
	},
	
	detachSelect: function(){
		$('.pre-home .box-state').animate({backgroundColor : '#01467d'}, {time: 500}).animate({backgroundColor : '#000f20'}, {time: 500});
	},
	
	detachButton: function(){
		$('.pre-home .box-items-found').animate({backgroundColor : '#01467d'}, {time: 500}).animate({backgroundColor : '#000f20'}, {time: 500});
	}
}

$(document).ready(function() { prehome.init(); });