/// <reference path="~/js/jquery-1.3.2.js"/>

jQuery.fn.hint = function() {
	return this.each(function() {
		var t = jQuery(this); // get jQuery version of 'this'
		var title = t.attr('title'); // get it once since it won't change
		if (title) { // only apply logic if the element has the attribute
			// on blur, set value to title attr if text is blank
			t.blur(function() {
				if (t.val() == '') {
					t.val(title);
					t.addClass('blur');
				}
			});
			// on focus, set value to blank if current value matches title attr
			t.focus(function() {
				if (t.val() == title) {
					t.val('');
					t.removeClass('blur');
				}
			});
			// now change all inputs to title
			t.blur();
		}
	});
}


$(document).ready(function() {

	$('div.bookingform> div.controls').hide();

	$('div.summaryitem.accordion> div.name').click(function() {
		if ($(this).attr("id") == "clicked") return true;
		$('div.details:visible').slideUp('fast').prev().attr("id", "").parent().removeClass("selected");
		$(this).attr("id", "clicked").next('div:hidden').slideToggle('slow').parent().addClass("selected");
		return false;
	});

	$(".list").css({
		'overflow': 'hidden',
		'cursor': 'n-resize'
	});


	$('.list').mousedown(function(event) {
		$(this)
                .data('down', true)
                .data('y', event.clientY)
                .data('scrollTop', this.scrollTop);

		return false;
	}).mouseup(function(event) {
		$(this).data('down', false);
	}).mouseleave(function(event) {
		$(this).data('down', false);
	})
	.mousemove(function(event) {
		if ($(this).data('down') == true) {
			this.scrollTop = $(this).data('scrollTop') + $(this).data('y') - event.clientY;
		}
	});

	var dId;

	$("#fsDown").mousedown(function(event) {
		dId = setInterval("move('fs', 5)", 25);
	});

	$("#fsUp").mousedown(function(event) {
		dId = setInterval("move('fs', -5)", 25);
	});

	$("#frDown").mousedown(function(event) {
		dId = setInterval("move('fr', 5)", 25);
	});

	$("#frUp").mousedown(function(event) {
		dId = setInterval("move('fr', -5)", 25);
	});


	$("#fsUp, #fsDown, #frUp, #frDown")
		.mouseout(function() { clearInterval(dId) })
		.mouseleave(function() { clearInterval(dId) })
		.mouseout(function() { clearInterval(dId) })
		.mouseup(function() { clearInterval(dId) });


});

function move(panelid, offset) {
	var o = $('#' + panelid);
	o.scrollTop(o.scrollTop() + offset);
}