$(function() {
	var url = window.location.href;
	
	$("#site-search").toggleVal({
		populateFrom: "label",
		focusClass: "focus",
		changedClass: "changed"
	});
	
	$("#banner-slideshow").cycle({
		delay: -1500,
		timeout: 4500
	});
	
	if (url.indexOf("?q=") > 0) { 
		$("#search-panel").show();
	}
	$("#toolbar-search").click(function() {
		$("#search-panel").slideToggle();
		return false;
	});
	$("#close-search-panel").click(function() {
		$("#search-panel").slideUp();
		return false;
	});	
	$(document).click(function(e) {
		if (e.button == 0) {
			$("#search-panel").slideUp();
		}
	});
	$("#search-panel").click(function(e) {
		e.stopPropagation();
	});
	
	$("#tt-advantage a").hover(
		function() {
			$("#banner-1").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-1").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	$("#programs a").hover(
		function() {
			$("#banner-2").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-2").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	$("#facility a").hover(
		function() {
			$("#banner-3").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-3").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	$("#student-work a").hover(
		function() {
			$("#banner-4").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-4").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	$("#instructors a").hover(
		function() {
			$("#banner-5").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-5").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	$("#contact a").hover(
		function() {
			$("#banner-6").stop().animate({"width": "721px"}, 300, "easeOutSine");
		},
		function() {
			$("#banner-6").stop().animate({"width": "0"}, 300, "easeInSine");
		}
	);
	
	$(".panes div.pane-content").hide().css("position", "absolute");
	$("ul.tabs").tabs("div.pane-content", {
		onBeforeClick: function(event, tabIndex) {
			$("div.panes").animate({
				height: $("div.pane-content").eq(tabIndex).innerHeight() + "px"
			});
		}
	});
	
	$(".software-icons img").tooltip({
		delay: 0,
		fade: 250,
		showURL: false,
		track: true
	});
		
	$("a.image").colorbox({
		rel: "group",
		transition: "fade",
		onCleanup: function() {
			if ($("#video-player").is(":parent")) {
				$("#video-player").children().remove();
			}
			$.colorbox.close()
		}
	});
	
	$("a.image-nogroup").colorbox({
		transition: "fade",
		onCleanup: function() {
			if ($("#video-player").is(":parent")) {
				$("#video-player").children().remove();
			}
			$.colorbox.close()
		}
	});
	
	$("a.video").colorbox({
		href: "#video-player",
		innerHeight: 486,
		innerWidth: 864,
		inline: true,
		rel: "group",
		scrolling: false,
		onComplete: function() {
			var videoUrl = $(this).attr("href");
			var playerUrl = "/includes/flash/flowplayer/flowplayer.commercial-3.2.3.swf";
			$f("video-player", playerUrl, {
				key: "#$6541fa259e0d0aced8c",
				clip: {
					autoPlay: false,
					autoBuffering: true,
					scaling: "fit",
					url: videoUrl
				}
			});
		},
		onCleanup: function() {
			$("#video-player").children().remove();
			$.colorbox.close()
		}
	});
	
	$("a.video-nogroup").colorbox({
		href: "#video-player",
		innerHeight: 486,
		innerWidth: 864,
		inline: true,
		scrolling: false,
		onComplete: function() {
			var videoUrl = $(this).attr("href");
			var playerUrl = "/includes/flash/flowplayer/flowplayer.commercial-3.2.3.swf";
			$f("video-player", playerUrl, {
				key: "#$6541fa259e0d0aced8c",
				clip: {
					autoPlay: false,
					autoBuffering: true,
					scaling: "fit",
					url: videoUrl
				}
			});
		},
		onCleanup: function() {
			$("#video-player").children().remove();
			$.colorbox.close()
		}
	});
	
	$(".colorbox").colorbox({
		rel: "group",
		scrolling: false,
		transition: "fade",
		onComplete: function() { 
			$.colorbox.resize();
		}
	});
	
	$(".colorbox-nogroup").colorbox({
		scrolling: false,
		transition: "fade",
		onComplete: function() { 
			$.colorbox.resize();
		}
	});
	
	$(document).bind("cbox_open", function() {
		$("#pipeline-globe").css({"visibility": "hidden"}); 
	}).bind("cbox_closed", function() {
		$("#pipeline-globe").css({"visibility": "inherit"}); 
	});
	
	/* Articles */
	$("#comments").hide();
	
	if (url.indexOf("#comments") > 0) { 
		$("#comments").show();
	}
	$("#comments-link").click(function(e) {
		if ($("#comments").css("display") != "none") {
			e.preventDefault();
		}
		$("#comments").slideToggle("slow");
	});
	
	flashembed("pipeline-globe", {
		loop: true,
		src: "/resources/pipeline-globe.swf"
	});
});
