// JavaScript Document
var menuTimeout;
function AddMenu(){
	$( "#dialog" ).dialog( "destroy" );		
		
	$( "#dialog-form" ).dialog({
		autoOpen: false,
		height: 350,
		width: 500,
		modal: true,
		buttons: {
			"Send Email": function() {
					var nm = $( "#name" ).val(),
					emlFrm = $( "#email" ).val(),
					qst = $( "#question" ).val();
					
					$.post("php/sendemail.php",
						{ emailFrom: emlFrm, userName: nm, msg: qst, reqType: "contact" },
							function(data){
								$( "#dialog-form" ).dialog( "close" );
							}
						 );
					}
		}
	});

	$( "#opener" ).click(function() {
		$( "#dialog-form" ).dialog( "open" );
		return false;
	});


	$("ul#topnav li").hover(function() { //Hover over event on list item
		clearTimeout(menuTimeout);
		$("ul#topnav li").removeClass('over');
		$("ul#topnav li > span").hide();
		$(this).addClass('over');//Add background color and image on hovered list item
		$(this).find("span").show(); //Show the subnav
	} , function() { //on hover out...
			menuTimeout = setTimeout(function(){
				$("ul#topnav li").removeClass('over');
				$("ul#topnav li > span").hide();
			},
			2000);//Hide the subnav
	});
}

function LoadTrainingXML(sideMenu, descs, descDiv){
	$.ajax({
		type: "GET",
		url: "http://www.fourlegspets.com/dev/Data/trainingPrices.xml",
		dataType: "xml",
		success: function(xml) {
			var i = 0;
			$(xml).find('class').each(function(){
				var name = $(this).find('name').text();
				var duration = ($(this).find('duration').text() == '')?'&nbsp;':$(this).find('duration').text();
				var cost = $(this).find('price').text();
				var desc = $(this).find('description').text();
				var waiver = ($(this).find('waiver').text() == '')?"":"<br /><br /><a href='http://www.fourlegspets.com/dev/" + $(this).find('waiver').text() + "' target='blank'>Class Waiver</a>";
				
				var message ="<div class='TrainingClass'>" +
							"Description:<br />" + desc +
							"<br /><br />" +
							"Duration:&nbsp;&nbsp;" + duration +
							"<br /><br />" +
							"Cost:&nbsp;&nbsp;" + cost +
							"<div class='name'><a href='#'>"+name+"</a></div>" +
							"<div class='duration'>"+duration+"</div>" +
							"<div class='cost'>"+cost+"</div>" +
							"<div class='desc'>"+desc+
							waiver + 
							"</div>" +
							"</div>" +
							"<div class='clear'></div>";
				
				descs[i] = desc;
				var sideNavHTML = sideNavHTML + "<li onclick='SwapTrainingDesc(this, " + i + ", descs);'>" + name + "</li>";
				
				i++;
				
				$( sideMenu ).append(sideNavHTML);
				$( "#divPrices" ).append(message);
			});
		}
	});
}

