/*
Author: Marc Lloyd
*/

$(function(){
	$('#form input, #form textarea, #form select').focus(function(){
		$(this.parentNode).addClass('highlight');
	}).blur(function(){
		$(this.parentNode).removeClass('highlight');
	});
});


/* IE6 DROPDOWN MENU */

$(function(){
	$('#main-nav li').hover(function(){
		$(this).find('ul').css('display', 'block');
	}, function(){
		$(this).find('ul').css('display', 'none');
	});
});

/* IE6 HIGHLIGHT HOVER */

$(function(){
	$('ul#highlights li a').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
});

/* DATE PICKER */
/** NEW WINDOWS **/
$(function() {

	var user_selected_end_date = false;

	$('.date-picker').datepicker({"dateFormat" : 'd MM yy'});

	// For date selector, at client request, advance date by 28 days 
	//I.e. if you select 1 april and the to date was not manually selected, it will default to 29 april.
	// This only happens if the user didn't select the end date manually.
	$('#event_after').datepicker({
		"dateFormat" : 'd MM yy',
		onSelect: function(dateText, inst) {
			 var date = new Date($.datepicker.parseDate('d MM yy', dateText));
			 var d = date.getDate();
			 var m = date.getMonth();
			 var y = date.getFullYear();
			 // advance date by 28 days...
			 var edate= new Date(y, m, d+28);

				if(!user_selected_end_date) {
					$('#event_before').val($.datepicker.formatDate('d MM yy', edate));
				}
		}
	});
	
	$('#event_before').datepicker({
		"dateFormat" : 'd MM yy',
		onClose: function(dateText, inst) {
			user_selected_end_date = (dateText.length > 0);
		}
	});



	
	$('a.new-window').click(function() {
		$(this).attr('target', '_blank');
		return true;
	});

	// Accommodation finder show/hide stuff.
	$('a.show-accommodation').toggle(function() {
		var the_id = $(this).attr('rel');
		$('#'+the_id).slideDown();
		$(this).find('span').html('hide');
		return false;
	}, function() {
		var the_id = $(this).attr('rel');
		$('#'+the_id).slideUp();
		$(this).find('span').html('show');
		return false;
	}
	);
});
