
$(window).load(function() {
	// flash variables to be sent into the banner image
	var flashvars = new Object();

	// get the source images
	var i=0;
	$("#bannerImages img").each(function() {
		flashvars["image"+(i++)] = $(this).attr("src")
	});

	flashvars["numberOfImages"] = String(i);

	// load up the flash
	var banner = $("#banner");
	swfobject.embedSWF("images/banner_pop.swf", "banner", "940", "180", "9.0.0", "/expressInstall.swf", flashvars, { menu: "false", wmode: "transparent" }, {id: "banner", name: "banner"});
});

$(document).ready(function() {
	
	// setup tooltips
	$("td.colHead").Tooltip({
		delay: 0,
		fixPNG: true,
		bodyHandler: getBlipBody,
		top: 100,
		left: -30,
		orientation: "vertical",
		track: true
	});

	$("td.rowHead").Tooltip({
		delay: 0,
		fixPNG: true,
		bodyHandler: getBlipBody,
		top: -30,
		left: 99,
		track: true
	});

	
	// make the itinerary items clickable
	$("div.itinerary .h1")
		.click(function() {
			if($(this).hasClass("expanded")) {
				$(this).siblings(".description").slideUp(200);
				$(this).removeClass("expanded");
			} else {
				$(this).siblings(".description").slideDown(200);
				$(this).addClass("expanded");
			}
		})
		.hover(
			function() {
				$(this).parent().addClass('hover');
			},
			function() {
				$(this).parent().removeClass('hover');
			}
		)
		.addClass('expanded')
		.siblings(".description").slideDown(0);
		//.hide(); // starts them out collapsed

	
	$("#copyArea").scroll(function() {
		$("#tooltip").hide();
	});
	
	
	$(window).bind("scroll", updateLeftLinks);


	$(".sectionHead").toggle(
		function() {
			var id = $(this).attr("id");
			var body = $("#"+id+"_body");
			
			// hide the body
			body.hide();
			
			// add the expanded class
			$(this).addClass("sectionHeadColapsed");
			
			// make sure the logos follow (ie 6)
			$("#logos").css({bottom: "10px", position: "absolute"});
			$("#logos").css({bottom: "0px", position: "absolute"});
			
			// make sure they are in the screen if we condesne too far
			updateLeftLinks();
		
		},
		function() {
			var id = $(this).attr("id");
			var body = $("#"+id+"_body");
			
			// hide the body
			body.show();
			
			// add the expanded class
			$(this).removeClass("sectionHeadColapsed");
	
			// make sure the logos follow (ie 6)
			$("#logos").css({bottom: "10px", position: "absolute"});
			$("#logos").css({bottom: "0px", position: "absolute"});
	
			// make sure they are in the screen if we condesne too far
			updateLeftLinks();
		
		}
	);



	$("#leftLinks li").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);





});		


function updateLeftLinks() {
	var wh = $(window).height();			// window height
	var wt = $(window).scrollTop();		// window top
	var lh = $("#leftLinks").outerHeight();		// links height
	var lt = $("#leftLinks").position().top;	// links top
	var copyBottom = $('#copyArea').position().top + $('#copyArea').outerHeight();
	var wb = wt + wh;
	var lb = lt + lh;
	var offset;
	
	// if our links are shorter than the window
	if(lh <= wh) {
		offset = Math.max(190, wt);
		
		// if our offset makes them go below the logos, stop at the logos
		if(offset + lh > copyBottom) {
			offset = copyBottom - lh;
		}
	
		// scroll it
		$("#leftLinks").stop().animate({top: offset}, 800);
		
	} else {
		
		// if we have scrolled above it, move it up
		if(wt <= lt) {
			offset = Math.max(190, wt);
	
			// scroll it
			$("#leftLinks").stop().animate({top: offset}, 800);
		} else if(wb >= lb) {
			offset = wb - lh - 20;
	
			// if our offset makes them go below the bottom, stop before there
			if(offset + lh > copyBottom) {
				offset = copyBottom - lh;
			}

			// scroll it
			$("#leftLinks").stop().animate({top: offset}, 800);
		}
		
	}

}


function expandItinerary() {
	$("div.itinerary div.itinerary_section span.h1").addClass('expanded').siblings(".description").show()
}

function collapseItinerary() {
	$("div.itinerary div.itinerary_section span.h1").removeClass('expanded').siblings(".description").hide()
}
