var coordinates = new Array();

$(document).ready(function() {
	$("h4.search-field-title").bind("click", function() {
		var search_field_list = $(this).parent().children()[1];
		if ($(search_field_list).hasClass("hide")) {
			$(search_field_list).removeClass("hide");
		}
		else {
			$(search_field_list).addClass("hide");
		}
	});
	
	$('.show_hide a').click(function() {
		$('.nonpaid').toggle("fast");
		$('.show_hide').hide();
	});
	
	//show phone button
	$("a.showphone").each(function() {
		$(this).bind("click", function(event) {
			var self = $(this);
			listing_id = $(this).attr("id").substring(3, $(this).attr("id").length);
			$.getJSON("http://" + location.hostname + "/static/secure_omg/businesslisting_details.php?data_type=phone&id=" + listing_id,
				function(data){
					if (data != undefined) {
						if ((data.phone != undefined) && (data.phone != "")) {
							self.after("<div>" + data.phone + "</div>");
							self.hide();
							$("#phone_refer_"+listing_id).toggle("fast");
						}
						if ((data.tracking != undefined) && (data.tracking != "")) {
							self.after('<img width="0" height="0" src="http://tracker.omg.com.au/' + data.tracking + '" />');
						}
					}
				}
			);
			event.preventDefault();
		});
	});

	//show image previews
	$(".stat_icon.photos").hover(function() {
		$(".image_preview", $(this).parents(".col_body_inner")).show(50);
	}, function() {
		var preview_plane = $(".image_preview", $(this).parents(".col_body_inner"));
		var timeout_preview = setTimeout(function() {$(preview_plane).hide(50)}, 2000);
		imgPreviewReset(preview_plane, timeout_preview);
	});

	/* swap the sponsored listings */
	if (typeof(swap_cpc) != 'undefined') {
		if (swap_cpc == 1) {
			var adhtml = $('#sidebar #ad-list').html();
			if(adhtml != null) {
				$('#end_of_paid_listings').html('<div id="ad-list">' + adhtml + '</div>').show();
				$('#sidebar #ad-list #listing-1').hide();
				$('#sidebar #ad-list #listing-2').hide();
				$('#sidebar #ad-list #listing-3').hide();
				$('#end_of_paid_listings #listing-4').hide();
				$('#end_of_paid_listings #listing-5').hide();
				//$('#sidebar #ad-list').html('');
			}
		}
	}
});

function imgPreviewReset(preview_plane, ref) {
	$(preview_plane).hover(function() {
		clearTimeout(ref);
	}, function() {
		$(this).hide(50);
	});	
}
