$(document).ready(function() {
	// this handles the coupon links on the exhibitor list
	$('p.couponLink a').click(function() {
		if (pageTracker) {
			pageTracker._trackEvent('Downloads', 'Coupon', $(this).closest('div.exhibitor').attr('id'));
		};
	});
	
	/*$("div.exhibitorName").click(function() {
		$(this).next("div.exhibitorInfo").slideToggle();
	});
	$("div.exhibitorName").hover(
		function() {
			$(this).toggleClass("exhibitorNameHover");
		},
		function() {
			$(this).toggleClass("exhibitorNameHover");
		}
	);*/
	//hideAllSpeakers();
	hideAllClasses();
	hideAllExhibitors();
	
	//$("div.classListing div.classInfo").show();
	
	//$("div.exhibitor.sponsor div.expandLink").hide();
	//$("div.expandLink").hide();
	$("div.exhibitor:not(.sponsor) div.expandLink").show();
	$("div.exhibitor:not(.sponsor,.noMoreInfo) div.exhibitorName, div.exhibitor:not(.sponsor,.noMoreInfo) div.expandLink, div.classListing div.className, div.classListing div.expandLink").addClass("cursor");
	//$("p#expandCollapse").show();
	
	
	$("form#exhibBrands fieldset:gt(0)").hide();
	$("p#addBrand").show();
	$("p#addBrand input").removeAttr("disabled");
	
	//$('input#specialservices').click(function(){scrollToError();});
	
	$("div.exhibitor:not(.sponsor,.noMoreInfo) div.exhibitorName").click(function() {
		var infoDiv = $(this).nextAll("div.exhibitorInfo");
		var setH = $(infoDiv).height();
		$(infoDiv).height(setH);
		infoDiv.slideToggle();
		$(this).nextAll("div.expandLink").children("p").toggleClass("expanded");
	});
	$("div.exhibitor:not(.sponsor,.noMoreInfo) div.expandLink").click(function() {
		$(this).nextAll("div.exhibitorInfo").slideToggle();
		$(this).children("p").toggleClass("expanded");
	});
	$("div.exhibitor:not(.sponsor,.noMoreInfo) div.exhibitorName, div.exhibitor:not(.sponsor,.noMoreInfo) div.expandLink").hover(
		function() {
			$(this).parent().children("div.expandLink").addClass("expandLinkHover");
			$(this).parent().children("div.exhibitorName").addClass("exhibitorNameHover");
		},
		function() {
			$(this).parent().children("div.expandLink").removeClass("expandLinkHover");
			$(this).parent().children("div.exhibitorName").removeClass("exhibitorNameHover");
		}
	);

	/*$("div.speakerName").click(function() {
		$(this).nextAll("div.speakerInfo").slideToggle();
		//$(this).nextAll("div.expandLink").children("p").toggleClass("expanded");
	});*/
	/*$("div.speaker div.expandLink").click(function() {
		$(this).nextAll("div.speakerInfo").slideToggle();
		$(this).children("p").toggleClass("expanded");
	});
	$("div.speakerName, div.speaker div.expandLink").hover(
		function() {
			$(this).parent().children("div.expandLink").addClass("expandLinkHover");
			$(this).parent().children("div.speakerName").addClass("speakerNameHover");
		},
		function() {
			$(this).parent().children("div.expandLink").removeClass("expandLinkHover");
			$(this).parent().children("div.speakerName").removeClass("speakerNameHover");
		}
	);*/
	//$("div.speakerName").hover( function() {$(this).addClass("speakerNameHover");},function() {$(this).removeClass("speakerNameHover");});
	$("div.className").click(function() {
		$(this).nextAll("div.classInfo").slideToggle();
		$(this).nextAll("div.expandLink").children("p").toggleClass("expanded");
	});
	$("div.classListing div.expandLink").click(function() {
		$(this).nextAll("div.classInfo").slideToggle();
		$(this).children("p").toggleClass("expanded");
	});

	$("div.className, div.classListing div.expandLink").hover(
		function() {
			$(this).parent().children("div.expandLink").addClass("expandLinkHover");
			$(this).parent().children("div.className").addClass("classNameHover");
		},
		function() {
			$(this).parent().children("div.expandLink").removeClass("expandLinkHover");
			$(this).parent().children("div.className").removeClass("classNameHover");
		}
	);
	
	startSponsorShow();

	//registration table/schedule highlighting	
	var mwBody = "body#Midwest-Register ";
	var ncBody = "body#California-Register ";
	var advEdItems = "#col2Content li.advEdItem";
	var summitItems = "#col2Content li.medSummit";
	var expoItems = "#col2Content li.expoItem, #col2Content li.liveDemos";
	var suppClassItems = "#col2Content li.suppClassItem";
	var partnerItems = "#col2Content p#partnerSchedule, #col2Content li.medSummit";
	
	//setting up the package options for each show
	var opt1ItemsMW  = $(mwBody).find(advEdItems+","+expoItems+","+suppClassItems+","+partnerItems);
	var opt1ItemsNC  = $(ncBody).find(advEdItems+","+summitItems+","+expoItems+","+suppClassItems);
	var opt1Items = $("table .option1").add(opt1ItemsNC).add(opt1ItemsMW);
	
	var opt2ItemsMW  = $(mwBody).find(expoItems+","+suppClassItems+","+partnerItems);
	var opt2ItemsNC  = $(ncBody).find(advEdItems+","+expoItems+","+suppClassItems);
	var opt2Items = $("table .option2").add(opt2ItemsNC).add(opt2ItemsMW);
	
	var opt3ItemsMW  = $(mwBody).find(expoItems+","+suppClassItems+","+partnerItems);
	var opt3ItemsNC  = $(ncBody).find(expoItems+","+suppClassItems+","+partnerItems);
	var opt3Items = $("table .option3").add(opt3ItemsNC).add(opt3ItemsMW);
	
	var opt4ItemsMW  = $(mwBody).find(expoItems+","+suppClassItems+","+partnerItems);
	var opt4ItemsNC  = $(ncBody).find(expoItems+","+suppClassItems);
	var opt4Items = $("table .option4").add(opt4ItemsNC).add(opt4ItemsMW);
	
	var opt5ItemsMW  = $(mwBody).find(expoItems+","+suppClassItems+","+partnerItems);
	var opt5ItemsNC  = $(ncBody).find(expoItems+","+suppClassItems);
	var opt5Items = $("table .option5").add(opt5ItemsNC).add(opt5ItemsMW);
	
	//highlighting in the schedule when hovering over each feature
	$("#feature1 td.featureName").hover(function() {$(advEdItems).addClass("highlight");},function() {$(advEdItems).removeClass("highlight");});
	$("#feature2 td.featureName").hover(function() {$(expoItems).addClass("highlight");},function() {$(expoItems).removeClass("highlight");});
	$("#feature3 td.featureName").hover(function() {$(suppClassItems).addClass("highlight");},function() {$(suppClassItems).removeClass("highlight");});
	$("#feature4 td.featureName").hover(function() {$(partnerItems).addClass("highlight");},function() {$(partnerItems).removeClass("highlight");});
	
	//highlighting in the schedule all of the components for each package when hovering over that package in the chart
	$("table#ncRegChart .option1, table#mwRegChart .option1").hover(function() {opt1Items.addClass("highlight");},function() {opt1Items.removeClass("highlight");});
	$("table#ncRegChart .option2, table#mwRegChart .option2").hover(function() {opt2Items.addClass("highlight");},function() {opt2Items.removeClass("highlight");});
	$("table#ncRegChart .option3, table#mwRegChart .option3").hover(function() {opt3Items.addClass("highlight");},function() {opt3Items.removeClass("highlight");});
	$("table#ncRegChart .option4, table#mwRegChart .option4").hover(function() {opt4Items.addClass("highlight");},function() {opt4Items.removeClass("highlight");});
	$("table#ncRegChart .option5, table#mwRegChart .option5").hover(function() {opt5Items.addClass("highlight");},function() {opt5Items.removeClass("highlight");});
	
	//special events highlighting in the schedule
	$("li#spaTour").hover(function(){$("#col2Content ul li.tour").addClass("highlight");},function(){$("#col2Content ul li.tour").removeClass("highlight");});
	$("li#eveningOut").hover(function(){$("#col2Content ul li.eveningOut").addClass("highlight");},function(){$("#col2Content ul li.eveningOut").removeClass("highlight");});
	$("li#networkingLunch").hover(function(){$("#col2Content ul li.lunch").addClass("highlight");},function(){$("#col2Content ul li.lunch").removeClass("highlight");});
});


function hideAllExhibitors() {
	$("div.exhibitor:not(.upgraded) div.exhibitorInfo").hide();
	$("div.exhibitor:not(.upgraded) div.expandLink p").removeClass("expanded");
}
function expandAllExhibitors() {
	$("div.exhibitor:not(.upgraded) div.exhibitorInfo").slideDown();
	$("div.exhibitor:not(.upgraded) div.expandLink p").addClass("expanded");
}
function collapseAllExhibitors() {
	$("div.exhibitor:not(.upgraded) div.exhibitorInfo").slideUp();
	$("div.exhibitor:not(.upgraded) div.expandLink p").removeClass("expanded");
}

function stopPkgRotate() {
	clearTimeout(highlightTO);
	allExpoItems.removeClass("highlight").removeClass("lowlight");
	$("table#midwestRegChart .expo1dayPackage, table#midwestRegChart .expo2dayPackage").removeClass("highlight");
}

/*function hideAllSpeakers() {
	$("div.speakerInfo").hide();
	$("div.speaker div.expandLink p").removeClass("expanded");
}
function expandAllSpeakers() {
	$("div.speakerInfo").slideDown();
	$("div.speaker div.expandLink p").addClass("expanded");
}
function collapseAllSpeakers() {
	$("div.speakerInfo").slideUp();
	$("div.speaker div.expandLink p").removeClass("expanded");
}*/

function hideAllClasses() {
	$("div.classInfo").hide();
	$("div.classListing div.expandLink p").removeClass("expanded");
}
function expandAllClasses() {
	$("div.classInfo").slideDown();
	$("div.classListing div.expandLink p").addClass("expanded");
}
function collapseAllClasses() {
	$("div.classInfo").slideUp();
	$("div.classListing div.expandLink p").removeClass("expanded");
}

var fieldsetCounter = 4;

function addBrand() {
	$("form#exhibBrands fieldset:hidden:first").show();
	fieldsetCounter = $("form#exhibBrands fieldset:hidden").length;
	$("span#brandsLeft").text(fieldsetCounter);
	if (fieldsetCounter == 0) {
		$("p#addBrand input").attr("disabled","true");
		$("p#addBrand input").css("cursor","default");
	}
}


function startSponsorShow() {
	$('div#sponsorList div.sponsor').css({opacity: 0.0});
	$('div#sponsorList div.sponsor:first').css({opacity: 1.0});
	jQuery.each($('div#sponsorList div.sponsor a img'), function(){
		if ($(this).attr('height') > 140) {
			$(this).attr('height', '140').removeAttr('width');
		}
		if ($(this).attr('height') < 140) {
			var logoHeight = $(this).attr('height');
			var newMarginTop = Math.floor((140 - logoHeight) / 2)
			$(this).css('marginTop', newMarginTop);
		}
	});
	if ($('div#sponsorList div.sponsor').length > 1) {
		setInterval(rotateSponsors, 6000);
	}
}


function rotateSponsors() {
	var currentSponsor;
	var nextSponsor;
	var oldSponsors;
	
	//find the current one and then the others are the old ones
	if ($('div#sponsorList div.topLogo').length = 1) {
		currentSponsor = $('div#sponsorList div.topLogo');
	} else {
		currentSponsor = $('div#sponsorList div.sponsor:first');
		currentSponsor.addClass('topLogo');
	}
	
	//the unused sponsons should be all that do not have the class of topLogo
	oldSponsors = $('div#sponsorList div.sponsor:not(.topLogo)');
	
	//make sure only the current one is visible and reset z-index of others back to default (20)
	oldSponsors.css({opacity: 0.0}).removeClass('oldLogo');
	
	//find the next one - either the next, or the first if the current sponsor is last in the list
	if (currentSponsor.next().length > 0) {
		nextSponsor = currentSponsor.next();
	} else {
		nextSponsor = $('div#sponsorList div.sponsor:first');
	}

	// move current sponsor back a few z's
	currentSponsor.addClass('oldLogo').removeClass('topLogo');
	
	//move the next one to the front and thenfade in new one on top of the old one
	nextSponsor.addClass('topLogo').animate({opacity: 1.0}, 1000);	
	
}


function toggleDiv(){
	var hiddenDiv = document.getElementById('collapse');
	var toggleLink = document.getElementById('toggleLink');
	
	if (hiddenDiv.style.display == "none") {
		$('#collapse').slideDown();
		$('p#toggleText').addClass('expanded');
		toggleLink.innerHTML = "collapse";
	}
	else {
		$('#collapse').slideUp();
		$('p#toggleText').removeClass('expanded');
		toggleLink.innerHTML = "expand";
	}
	return false;
}

function closeDevDiv() {
	document.getElementById('devHeader').style.display = "none";
}

