var initMyJQ = function() {
	$('.subMenuCell').hover(
	function() {
		$(this).css('backgroundImage','url(/user_data/Image/mnu_item_over.png)');
	},
	function() {
		$(this).css('backgroundImage','url(/user_data/Image/mnu_item.png)');
	});
	$("ul.horNav").superfish({
		hoverClass	: "sfHover",
		currentClass	: "current",
		delay		: 200,
		animation	: {opacity:"show", height:"show"},
		speed		: "normal"
	});

	// Adults fields generator
	$('#ad_number').bind('keydown', function() {
		displayFields($('#adult'), $(this));
	});

	$('#ad_number').bind('keyup', function() {
		displayFields($('#adult'), $(this));
	});

	$('#ad_number').bind('change', function() {
		displayFields($('#adult'), $(this));
	});

	// Children fields generator
	$('#ch_number').bind('keydown', function() {
		displayFields($('#child'), $(this));
	});

	$('#ch_number').bind('keyup', function() {
		displayFields($('#child'), $(this));
	});

	$('#ch_number').bind('change', function() {
		displayFields($('#child'), $(this));
	});
}

var displayFields = function(objc,obji) {
	var i = obji.val(), id = objc.attr("id");

	if(i) {
		var tbl = '<table cellpadding="0" cellspacing="3" border="0" width="100%">', loc=0;
		for(var idx=0;idx<i;idx++) {
			tbl += '<tr><td><p> ' + id.titleCase() + '\'s no. ' + (idx + 1) + ' name:</p></td><td><p><input type="text" name="' + id + '_' + idx + '_firstname" id="' + id + '_' + idx + '_firstname">&nbsp;<span class="required">*</span></p></td></tr>';
			tbl += '<tr><td><p> ' + id.titleCase() + '\'s no. ' + (idx + 1) + ' last name:</p></td><td><p><input type="text" name="' + id +'_' + idx + '_lastname" id="' + id + '_' + idx + '_lastname">&nbsp;<span class="required">*</span></p></td></tr>';

			if(id=='child') {
				tbl += '<tr><td><p> ' + id.titleCase() + '\'s no. ' + (idx + 1) + ' birth date:</p></td><td><p><input id="' + id + '_' + idx + '_birth_date" name="' + id + '_' + idx + '_birth_date" type="hidden"><span class="emphOrange" id="' + id + '_' + idx + '_birthday" style="cursor: pointer;">Click here to choose</span>&nbsp;<span class="required">*</span></p></td></tr>';
			}
			
			tbl += '<tr><td colspan="2" height="10"><img src="images/spacer.gif" height="10"></td></tr>';

			loc = val_names.length;
			val_names = val_names.insert(loc,id + '_' + idx + '_firstname');
			val_types = val_types.insert(loc,0);
			val_titles = val_titles.insert(loc,'Please enter the ' + id + '\'s no. ' + (idx + 1) + ' first name!');

			val_names = val_names.insert(loc+1,id + '_' + idx + '_lastname');
			val_types = val_types.insert(loc+1,0);
			val_titles = val_titles.insert(loc+1,'Please enter the ' + id + '\'s no. ' + (idx + 1) + ' last name!');

			if(id=='child') {
				val_names = val_names.insert(loc+2,id + '_' + idx + '_birth_date');
				val_types = val_types.insert(loc+2,0);
				val_titles = val_titles.insert(loc+2,'Please enter the ' + id + '\'s no. ' + (idx + 1) + ' birth date!');
			}
		}
		tbl += '</table>';
		objc.html(tbl);

		for(var idx=0;idx<i;idx++) {
			if(id=='child') {
				Calendar.setup({
					inputField : id + '_' + idx + '_birth_date', // id of the input field
					ifFormat : "%Y-%m-%d", // format of the input field (even if hidden, this format will be honored)
					displayArea : id + '_' + idx + '_birthday', // ID of the span where the date is to be shown
					daFormat : "%A, %B %d, %Y",// format of the displayed date
					align : "Tl", // alignment (defaults to "Bl")
					singleClick : true,
					showsTime : false
				});
			}
		}
	} else {
		objc.html('&nbsp;');
	}

	//alert(val_titles[1]);
	extractNumber(document.getElementById(obji.attr("id")),0,false);
	return false;
}
