$(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
	
	//set up some shortcut variables
	dailyExpoItems = $("#col2Content li.expoItem, #col2Content li.suppClassItem, #col2Content li.liveDemos");
	allExpoItems = $("#col2Content li.expoItem, #col2Content li.suppClassItem, #col2Content li.liveDemos, #col2Content p#partnerSchedule");
	day1expoItems = $("#col2Content ul#dayOne").children("li.expoItem, li.suppClassItem, li.liveDemos");
	day2expoItems = $("#col2Content ul#dayTwo").children("li.expoItem, li.suppClassItem, li.liveDemos");
	day3expoItems = $("#col2Content ul#dayThree").children("li.expoItem, li.suppClassItem, li.liveDemos");

	$("table#midwestRegChart tr#advEdItem td.ticketItem").hover(function(){$("#col2Content ul li.advEdItem").addClass("highlight");},function(){$("#col2Content ul li.advEdItem").removeClass("highlight");});
	$("table#midwestRegChart tr#expoItem td.ticketItem").hover(function(){$("#col2Content ul li.expoItem, #col2Content ul li.liveDemos").addClass("highlight");},function(){$("#col2Content ul li.expoItem, #col2Content ul li.liveDemos").removeClass("highlight");});
	$("table#midwestRegChart tr#suppClassItem td.ticketItem").hover(function(){$("#col2Content ul li.suppClassItem").addClass("highlight");},function(){$("#col2Content ul li.suppClassItem").removeClass("highlight");});
	$("table#midwestRegChart tr#absItem td.ticketItem").hover(function(){$("#col2Content p#partnerSchedule").addClass("highlight");},function(){$("#col2Content p#partnerSchedule").removeClass("highlight");});
	
	$("body#Midwest-Register div#col1Content li#eveningOut").hover(function(){$("#col2Content ul li.eveningOut").addClass("highlight");},function(){$("#col2Content ul li.eveningOut").removeClass("highlight");});
	$("body#Midwest-Register div#col1Content li#networkingLunch").hover(function(){$("#col2Content ul li.lunch").addClass("highlight");},function(){$("#col2Content ul li.lunch").removeClass("highlight");});

	//$("table#midwestRegChart tr#eveningOut td").hover(function(){$("#col2Content ul li.eveningOut").addClass("highlight");},function(){$("#col2Content ul li.eveningOut").removeClass("highlight");});
	//$("table#midwestRegChart tr#lunch td").hover(function(){$("#col2Content ul li.lunch").addClass("highlight");},function(){$("#col2Content ul li.lunch").removeClass("highlight");});
	
	$("table#midwestRegChart .advEdPackage").hover(
		function() {
			allExpoItems.addClass("highlight");
			$("#col2Content ul li.advEdItem, table#midwestRegChart .advEdPackage").addClass("highlight");
		},
		function() {
			allExpoItems.removeClass("highlight");
			$("#col2Content ul li.advEdItem, table#midwestRegChart .advEdPackage").removeClass("highlight");
		}
	);
	
	$("table#midwestRegChart .expo3dayPackage").hover(
		function() {
			allExpoItems.addClass("highlight");
			$("table#midwestRegChart .expo3dayPackage").addClass("highlight");
		},
		function() {
			allExpoItems.removeClass("highlight");
			$("table#midwestRegChart .expo3dayPackage").removeClass("highlight");
		}
	);
	$("table#midwestRegChart .expo2dayPackage").hover(
		function() {
			allExpoItems.addClass("highlight");
			$("table#midwestRegChart .expo2dayPackage").addClass("highlight");
		},
		function() {
			allExpoItems.removeClass("highlight");
			$("table#midwestRegChart .expo2dayPackage").removeClass("highlight");
		}
	);
	$("table#midwestRegChart .expo1dayPackage").hover(
		function() {
			allExpoItems.addClass("highlight");
			$("table#midwestRegChart .expo1dayPackage").addClass("highlight");
		},
		function() {
			allExpoItems.removeClass("highlight");
			$("table#midwestRegChart .expo1dayPackage").removeClass("highlight");
		}
	);

	
	
	/*$("table#midwestRegChart .expo2dayPackage").hover(
		function() {
			dailyExpoItems.addClass("lowlight");
			$("#col2Content p#partnerSchedule, table#midwestRegChart .expo2dayPackage").addClass("highlight");
			lowlightDay3();
		},
		function() {
			stopPkgRotate();
		}
	);
	$("table#midwestRegChart .expo1dayPackage").hover(
		function() {
			allExpoItems.addClass("lowlight");
			$("#col2Content p#partnerSchedule, table#midwestRegChart .expo1dayPackage").addClass("highlight");
			highlightDay1();
		},
		function() {
			stopPkgRotate();
		}
	);*/
	
	
});

var allExpoItems;
var day1expoItems;
var day2expoItems;
var day3expoItems;

/*
var highlightTO;
var dailyExpoItems;

function highlightDay1() {
	day2expoItems.removeClass("highlight");
	day3expoItems.removeClass("highlight");
	day1expoItems.addClass("highlight");
	highlightTO = setTimeout(highlightDay2, 750);
}

function highlightDay2() {
	day1expoItems.removeClass("highlight");
	day3expoItems.removeClass("highlight");
	day2expoItems.addClass("highlight");
	highlightTO = setTimeout(highlightDay3, 750);
}

function highlightDay3() {
	day1expoItems.removeClass("highlight");
	day2expoItems.removeClass("highlight");
	day3expoItems.addClass("highlight");
	highlightTO = setTimeout(highlightDay1, 750);
}

function lowlightDay3() {
	day1expoItems.addClass("highlight");
	day2expoItems.addClass("highlight");
	day3expoItems.removeClass("highlight");
	highlightTO = setTimeout("lowlightPause1(1)", 900);
}

function lowlightDay1() {
	day1expoItems.removeClass("highlight");
	day2expoItems.addClass("highlight");
	day3expoItems.addClass("highlight");
	highlightTO = setTimeout("lowlightPause1(2)", 900);
}
function lowlightDay2() {
	day1expoItems.addClass("highlight");
	day2expoItems.removeClass("highlight");
	day3expoItems.addClass("highlight");
	highlightTO = setTimeout("lowlightPause1(3)", 900);
}

function lowlightPause1(nextDay) {
	dailyExpoItems.removeClass("highlight");
	if (nextDay == '1') {
		highlightTO = setTimeout(lowlightDay1, 100);
	} else if (nextDay == '2'){
		highlightTO = setTimeout(lowlightDay2, 100);
	} else if (nextDay == '3'){
		highlightTO = setTimeout(lowlightDay3, 100);
	}
}
*/

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 scrollToError() {
	//alert("scroll");
	var errorTop;
	if ($('#exhibInfoError').length > 0) {
		//var errorBorderColor = $('#exhibInfoError').css('border-color');
		//var errorColor = $('#exhibInfoError').css('color');
		$('#exhibInfoError').css({'opacity' : '0'});
		errorTop = $('#exhibInfoError').offset().top - 10;
		$('#exhibInfoError').animate({
			opacity: 1
		}, 2000);
	} else {
		errorTop = 0;
	}
	$('html, body').animate({
		scrollTop: errorTop
	}, 800);
}
*/
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";
}
