/*
 * Subject to copyright.
 *
 * Web Development - LOOKsystems Limited
 * mailto:info@looksystems.ltd.uk
 * http://www.looksystems.ltd.uk
 *
 */

jQuery.fn.curvyCorner = function(options) { 

	var settings = { 
		tl: { radius:10 },
		tr: { radius:10 },
		bl: { radius:10 },
		br: { radius:10 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	};

	if (options && typeof(options) != 'string') jQuery.extend(settings, options); 
	return this.each(function() {
		new curvyObject(settings,this).applyCorners(); 
	});

};

function property_showimage(imgsrc) {
	$('.property-image img').attr('src', imgsrc);
	return false;
}

$(document).ready(function(){

	// set focus
	// var $input = $("input[type='text'],input[type='password'],textarea");
	// if ($input.length) $input.get(0).focus();

	// round corners
	$('.curvy').addClass('curved').curvyCorner();

	// initialise legacy script
	if (typeof(init) == 'function') init();

	// initialise lightbox
	if (typeof($.fn.prettyPhoto) == 'function') {

		$("a[rel^='lightbox']").prettyPhoto();

		$(".lightwindow").prettyPhoto({
			width: 800,
			height: 600,
			theme: 'light_square',
			iframe: true
		});

		$(".lightbox-start").click(function() {
			$("a[rel^='lightbox']:first").click();
			return false;
		});
	}

	// pendra hover buttons
	$('.pendrabutton').hover(
		function() { $(this).css({'background-position': '170px 0'}) },
		function() { $(this).css({'background-position': '0'})  }
	);

	// back-to-search
	$('.back-to-search').click(function(e) {
		e.preventDefault();
		history.go(-1);
	});

	// submit once
	$(".enquiryform #recalculate").click(function() {
		this.form['recalc'].value = 1;
	});
	$("form").submit(function() {
		$(".enquiryform .button").attr("disabled", "true");
	});

	// valid dates
	var restrictedDates = (typeof seasonDates != 'undefined') ? seasonDates : new Array();
	function isSeasonSaturday(date) {
		var restricted = false;
		for (d in restrictedDates) {
			var season = restrictedDates[d];
			if (date < season[0] || date > season[1]) continue;
			restricted = true;
			break;
		}
		if (!restricted) return [true, ''];
		return [date.getDay() == 6, ''];
	}

	// date picker
	$(".date-pick").datepicker({
		dateFormat: 'dd/mm/yy',
		buttonImageOnly: true,
		buttonImage: 'img/calendar.gif',
		duration: '',
		firstDay: 6,
		minDate: new Date,
		numberOfMonths: 2,
		showOn: 'button',
		beforeShowDay: isSeasonSaturday
	});

});