
$(document).ready(function()
{

	$('.col-act a, th[title]').tipsy({gravity: $.fn.tipsy.autoNS, fade: true});
	$('td:not(.col-act) a[title]').tipsy({gravity: $.fn.tipsy.autoWE, fade: true});
	$('img.propthumb').tipsy({gravity:'w', html:true, opacity:1, title:function()
	{
		var img = $(this).clone();
		img.attr('src', img.attr('src').replace(/sml/, 'med'));
		return img;
	}});

	changeAuthority = function()
	{
		if ($('#f-authority').val() == 'auction')
		{
			if (!$('#f-auction').val())
			{
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				if (month < 10)
					month = '0' + month.toString();
				var day = date.getDate();
				if (day < 10)
					day = '0' + day.toString();
				$('#f-auction').val(year + '-' + month + '-' + day + ' 00:00:00');
			}
			$('#li-f-auction').show();
		}
		else
			$('#li-f-auction').hide();
	}

	changeAuthority();

	$('#f-authority').change(changeAuthority);

	if ($('#f-auction').length)
		$('#f-auction').datetime({});
/*
	if ($('#f-auction').length)
		$('#f-auction').AnyTime_picker({
			format:     "%Y-%m-%d %h:%i:%s",
			//format:     "%Y-%m-%d %T",
			baseYear:   2010,
			earliest:   new Date(2010,0,1,0,0,0),
			firstDOW:   1
		});

	if ($('#f-dateavailable').length)
		$('#f-dateavailable').AnyTime_picker({
			format:     "%Y-%m-%d",
			baseYear:   2010,
			earliest:   new Date(2010,0,1,0,0,0),
			firstDOW:   1
		});
*/
	if ($('#f-dateavailable').length)
		$('#f-dateavailable').datepicker();

	findDTs();



	changeStatus = function()
	{
		if ($('#f-status').val() == 'sold')
			$('#f-solddetails').show();
		else
			$('#f-solddetails').hide();
	}

	changeStatus();

	$('#f-status').change(changeStatus);

	$('#feature').click(function(event)
	{

		if (!$('#agree').attr('checked'))
		{
			alert('Please agree to the terms of use to continue');
			return false;
		}

		return true;

	});

});



findDTs = function()
{

	if ($('#f-ofidate').length)
		$('#f-ofidate').datepicker({dateFormat: 'yy-mm-dd'});
/*
		$('#f-ofidate').AnyTime_picker({
			format:     "%Y-%m-%d",
			baseYear:   2010,
			earliest:   new Date(2010,0,1,0,0,0),
			firstDOW:   1
		});
*/
	if ($('#f-ofistart').length)
		$('#f-ofistart').timepickr();
/*
		$('#f-ofistart').AnyTime_picker({
			format:     "%h:%i%p",
			baseYear:   2010,
			earliest:   new Date(2010,0,1,0,0,0),
			firstDOW:   1
		});
*/
	if ($('#f-ofiend').length)
		$('#f-ofiend').AnyTime_picker({
			format:     "%h:%i%p",
			baseYear:   2010,
			earliest:   new Date(2010,0,1,0,0,0),
			firstDOW:   1
		});

};



removeOFI = function(a)
{

    $(a).parent().find('input').AnyTime_noPicker();

    $(a).parent().remove();

    return false;

};



addOFI = function()
{

    var newOFI = '<li>On '
        + '<input class="input-date" name="ofis[][date]"  type="date" value="" />'
        + ' from '
        + '<input class="input-time" name="ofis[][start]" type="time" value="" />'
        + ' till '
        + '<input class="input-time" name="ofis[][end]"   type="time" value="" />'
        + '<a href="#" onclick="return removeOFI(this)">Remove</a>'
        + '</li>';

    $('#ofilist').append(newOFI);

};



featureProperty = function(link, type, id, address)
{

	if ($('#feature-property-confirm').length)
		$('#feature-property-confirm').remove();

	// make a nice div and position it relative to property or something?
	var div = '<div id="feature-property-confirm" class="dialogue">'
		+ '<h3>Feature &mdash; ' + address + '</h3>'
		+ '<p>Please confirm that you wish to feature this property, for the life of the listing. The property will be featured immediatley, however you will not be invoiced until the next billing cycle.</p>'
		+ '<p><a href="/agency/property/' + type + '/feature/' + id + '/moreinfo">Find out more about feature property and featuring all your listings</a></p>'
		+ '<a class="input-submit " href="/agency/property/' + type + '/feature/' + id + '">Feature This Property</a>'
		+ '<a class="button button-negative" href="#" onclick="return $(this).parent().remove()">Cancel</a>'
		+ '</div>';
	$(div).insertAfter('header');
return false;
}
