$(function(){
	var bg_table = null;
	$('#estate_min table tr').mouseover(function(){
		bg_table = $(this).css('background-color');
		$(this).css('background-color', '#FAE7E4');
	});
	$('#estate_min table tr').mouseout(function(){
		$(this).css('background-color', bg_table);
	});
});

function change_psn(__this, right){
		var _this = $(__this).parent();
		var psn = _this.find('.photo_scroll_numbers').text();
		var a = psn.split('/');
		psn = a[0];
		var direct = 'rl';
		if (right){
			psn++;
		} else {
			psn--;
			direct = 'lr';
		}
		if (psn == 0) psn = a[1];
		if (psn > a[1]) psn = 1;
		_this.find('img').eq(2).attr('src');
		_this.find('.flip').flip({
			direction:direct,
			speed:200,
			content:'<img src="'+_this.find('img').eq(psn).attr('src')+'"/>'
		});
		_this.find('.photo_scroll_numbers').text(psn+'/'+a[1]);
}

function clear_form_elements(ele) {
    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
};

$(function(){
	$('.btn_left_scroll').click(function(){
		change_psn(this, false);
	});
	$('.btn_right_scroll').click(function(){
		change_psn(this, true);
	});

	$('#searchform legend').click(function(){
		clear_form_elements($(this).parent());
		getCountEstate();
	});

	var legend_color = false;
	$('#searchform legend').mouseover(function(){
		legend_color = $(this).css('color');
		$(this).css('color', '#008040');
	});
	$('#searchform legend').mouseout(function(){
		$(this).css('color', legend_color);
	});

	$("#searchform input[name='type']").change(function(){		if ($(this).val()=='buy') {
			$("#searchform input[name='status[]']").removeAttr('disabled');
		} else {			$("#searchform input[name='status[]']").attr('disabled', 'disabled');		}	});
});
