

function set_hovers() {

	// Set up mouseenter, mouseleave and onclick events for the panels 

	$('.panel').each(function(id, el)
	{

		$(el).mouseover(function() {
			$(el).addClass('red');
		});
		
		$(el).mouseout(function() {
			$(el).removeClass('red');
		});
	});	
}



function toggle_div(div_id, display){
	
	if(display==true) {
		$(div_id).show();
	}
	else{
		$(div_id).hide();
	}
	return true;
}

function refresh_div(div_id){
	$('#'+div_id).hide();
	$('#'+div_id).fadeIn(0.3);
	return true;
}


function toggle_div_fade(div_id, display){
	
	if(display==true) {
		$('#'+div_id).fadeIn(0.3);
	}
	else{
		$('#'+div_id).fadeOut(0.3);
	}
	return true;
}

function appear_if_not_visible(div_id){
	if ($('#'+div_id).css('display') == 'none'){
		$('#'+div_id).fadeIn(0.3);
	}
	return true;
}

var up = false;

function toggle_affiliates(){
	var factor = 1;
	if(up==false) {
		$('affclick').hide();
		$('window').show();
		new Effect.Move('affbox', { x: 0, y: -60 });
		up = true;
	}
	else{
		new Effect.Move('affbox', { x: 0, y: 60 });
		$('affclick').show();
		$('window').hide();
		up = false;
	}
	return true;
}



// Now bung in rel=external hack
$(document).ready(function() 
{
	set_hovers();
    $('a[rel="external"]').each(function(i, theLink){
        if($(theLink).attr('href') != '' && $(theLink).attr('href') != '#'){
            $(theLink).attr('target','_blank');
        }
    });
	
	$(function() 
	{	
		$('#livesearch').autocomplete('/search/all/quick/', 
		{ 
		  minChars: 3, mustMatch: false, selectFirst: false, autoFill: false, dataType: 'json',
		  matchSubset: false,  scroll: false,  width: 330,
		  
		  parse: function(jdata) {
			var parsed_data = []; 
			if (!jdata || jdata.length == 0) {
				 // handle no results case specially
				parsed_data[0] = {data: {id:-1, url:'#'}};
			}
			else {
				for (var i=0; i<jdata.length; i++){
					obj = jdata[i];
					parsed_data[i] = { 
						data: obj, id: obj.id
					};
				}
			}
			return parsed_data;
		  },
		  formatItem: function(property, i, n){
			if(property.id==-1){	
				return '<div class="ajax">Sorry, no results<\/div>';
			}
			var html = '<div class="ajax clearfix">';
			if(property.image){
				html += '<img src="' + property.image + '" style="float:left; width: 100px; height: 75px;" \/>';
			}

			html += '<p class="address" style="display: inline; width: 100px; padding-top: 15px;" ><strong>' + property.address + '<\/strong><br \/>';
			if(property.bedrooms>1) html += property.bedrooms + ' Bed ';
			if(property.name) html +=  property.name;
			html += '<\/p><p class="price_str">' + property.price_str + '<\/p><\/div>';
			return html;
		  }
		}).result(function(event, item){
			location.href = item.url;
		});
	});
	
	$('div.faux_select_med, div.faux_select_short, div.faux_select_long').each(function() {
		
		span = $(this).children('span');
		selectedText = $(this).find('select option:selected').text();
		if (selectedText != '')
		{
			$(span).text(selectedText);
		}
	});
	
});
