$(document).ready(function(){
/******************** BEGIN - HEADER NAVIGATION PREPARATION ********************/
	// remove link background images since we're re-doing the hover interaction below 
	// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
	// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
	$(".headerNav").children("li").each(function(){
		var current = "headerNav current-" + ($(this).attr("class"));
		var parentClass = $(".headerNav").attr("class");
		if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}
	})
	
	// create events for each nav item
	attachNavEvents(".headerNav", "home");
	//attachNavEvents(".headerNav", "tour");
	attachNavEvents(".headerNav", "webinars");
	attachNavEvents(".headerNav", "liveWebinars");
	attachNavEvents(".headerNav", "tools");
	attachNavEvents(".headerNav", "videos");
	//attachNavEvents(".headerNav", "onsite");
	attachNavEvents(".headerNav", "bookstore");
	
	// this sets up the function for interactive events
	function attachNavEvents(parent, myClass) {
		$(parent + " ." + myClass).hover(
			function(e){
				$(this).append('<div class="headerNav-' + myClass + '"></div>');
				$("div.headerNav-" + myClass).css({display:"none"}).fadeIn(200);
			},
			function(e){
				$("div.headerNav-" + myClass).fadeOut(275, function() {
					$(this).remove();
				});
			}
		);
	}
/******************** END - HEADER NAVIGATION PREPARATION ********************/

/******************** BEGIN - DIALOG BOX PREPARATION ********************/
	if ($("#enrollDialog").length){
		setTimeout('tb_show("<strong>Enrollment</strong>","#TB_inline?height=100&amp;width=400&amp;inlineId=enrollDialog",null)', 100);
	}
	if ($("#cancelDialog").length){
		setTimeout('tb_show("<strong>Event Cancellation</strong>","#TB_inline?height=100&amp;width=400&amp;inlineId=cancelDialog",null)', 100);
	}
	
/******************** END - DIALOG BOX PREPARATION ********************/

/******************** BEGIN - SEMINAR LISTING PREPARATION ********************/

	$(".upcomingEvents .topic .name").each(function(){
		// remove links since we have javascript
		$(".upcomingEvents .topic .name .semTitle").each(function(){
			$(this).replaceWith($(this).html())
		});
		
		// add click event to sort by topic section
		var myParent = $(this).parent();
		$(this).click(function(){
			if(myParent.hasClass("active")){
				myParent.removeClass("active");
			}else{
				$(".upcomingEvents .active").removeClass("active");
				myParent.addClass("active");
			}
		});
	});
	
	$(".upcomingEvents .eventByDate .row, .upcomingEvents .topic .event").each(function(){
		// add mouse over event to rows
		$(this).hover(
			function(e){
				$(this).addClass("rowOver");
			},
			function(e){
				$(this).removeClass("rowOver");
			}
		);
	});

/******************** END - SEMINAR LISTING PREPARATION ********************/

/******************** BEGIN - ENROLLMENT PREPARATION ********************/
	
	/*$(".enrollment .row input, .enrollment .row select").each(function(){
		// add focus event to input fields
		$(this).focus(
			function(e){
				$(this).addClass("focus");
			}
		);
		$(this).blur(
			function(e){
				$(this).removeClass("focus");
			}
		)
	});*/
	
	$(".enrollment input[name='doEnroll']").val("0");
		
	$(".enrollment #payMethod").change(
		function(e){
			var chosenMethod = $(".enrollment #payMethod option:selected").val();
			$(".enrollment .display").removeClass("display");
			$("#method_" + chosenMethod).addClass("display");
			
			// If a payment method is chosen, allow the enrollment (data will still be verified)
			if(chosenMethod != ""){$(".enrollment input[name='doEnroll']").val("1");}
			else{$(".enrollment input[name='doEnroll']").val("0");}
		}
	);
	
	$("form.enrollment").submit(function(){
		if($(".enrollment #payMethod option:selected").val() == "1"){
			
		}
	});
	
/******************** END - ENROLLMENT PREPARATION ********************/

});
