var overScreens = true;
var state = "in";
var darkUp = "off";
var keyboardUp = "off";
var guidedUp = "off";
var phoneUp = "off";
var nextCount = 4;
var prevCount = 4;
var currentId = "0";
var tourActivated = "";

/* Intro Video Trace Function */
function traceVideo(id)
{
	if(id.match("COMPLETED"))
	{
		if(videoPlay == "play")
		{
			overScreens = true; 
			/* Resume Running Picture Frame Slideshow */
			$('#framepics').cycle('resume');
			$("#intro_video").html("");	
			$("#intro_video").css("display", "none");
			$("#skip_video").css("display", "none");
		}
	}
}

window.onload=function()
{	
	$("#darkloading").css("display", "none");
	$("#bigloading").css("display", "none");
	
	/*
	 * Check to see if intro video should be played
	 */
	
	if(videoPlay == "play")
	{
		/* Pause Running Picture Frame Slideshow */
		//$('#framepics').cycle('pause');
		$("#intro_video").html("");
		//$("#intro_video").flash({src: "videos_vt/player.swf?file=VT_tour4_anim2.flv&autostart=true&controlbar=none&tracecall=traceVideo&displayclick=none", width: 490, height: 301, allowfullscreen: true});
		$('#intro_video').html('<embed width="490" height="301" flashvars="file=VT_tour4_anim2.flv&autostart=true&controlbar=none&tracecall=traceVideo&displayclick=none" allowscriptaccess="always" allowfullscreen="true" quality="high" src="videos_vt/player.swf" type="application/x-shockwave-flash">');
	}
	else
	{
		overScreens = true;
		$("#skip_video").css("display", "none");
		$("#intro_video").css("display", "none");
	}
	
}

$(document).ready(function()
{
	/*
	 * Starting Values
	 */

	/* Dark Background Overlay Set */
	$("#darkloading").animate({opacity: ".85"}, 1);
	$("#dark").animate({opacity: "0"}, 1);
	$("#dark").css("display", "none");

	/* Big Items Initial Set */
	$("#bigloading").animate({opacity: ".85"}, 1);
	$("#big").animate({opacity: "0"}, 1);
	$("#big").css("display", "none");
	
	//$("#bar_campusvisits").animate({opacity: "0"}, 1);
	//$("#bar_admissions").animate({opacity: "0"}, 1);
	
	/* Image Map Overlay Initial Set */
	$("#overlayhidden").animate({opacity: "0"}, 1);

	/* Screen Overlay (Hover Effect) Initial Set */
	$(".screenover").animate({opacity: "0"}, 1);
	$(".screenover").css("display", "none");

	/* Screen Text Box Opacity */
	$(".text").animate({opacity: ".25"}, 1);

	/* Bear Animation Div Initial Set */
	$("#bear_over").css("display", "none");
	$("#bear_over_push").animate({opacity: "0"}, 1, function(){$("#bear_over_push").css("display", "none");});
	$("#bear_over_push_keyboard").animate({opacity: "0"}, 1, function(){ $("#bear_over_push_keyboard").css("display", "block");});
	$("#bear_over_guided").animate({opacity: "0"}, 1, function(){ $("#bear_over_push_keyboard").css("display", "block");});

	/* Time Push on Iphone */
	$("#time_push").css("display", "none");

	/* Start Item Roll Over Initial Sets */

		/* Phone */
		$("#item_over_phone").animate({opacity: "0"}, 1);
		
		/* Keys */
		$("#item_over_keys").animate({opacity: "0"}, 1);
		//$("#item_over_keys_menu").animate({opacity: "0"}, 1);
		$("#item_over_keys_menu").css("display", "none");
		
		/* Keyboard */
		$("#item_over_keyboard").animate({opacity: "0"}, 1);
		
		/* Football */
		$("#item_over_football").animate({opacity: "0"}, 1);
		//$("#item_over_football_menu").animate({opacity: "0"}, 1);
		$("#item_over_football_menu").css("display", "none");
		
		/* Books */
		$("#item_over_books").animate({opacity: "0"}, 1);
		//$("#item_over_books_menu").animate({opacity: "0"}, 1);
		$("#item_over_books_menu").css("display", "none");
		
		/* Bible */
		$("#item_over_bible").animate({opacity: "0"}, 1);
		//$("#item_over_bible_menu").animate({opacity: "0"}, 1);
		$("#item_over_bible_menu").css("display", "none");
		
		/* Cup */
		$("#item_over_cup").animate({opacity: "0"}, 1);
		//$("#item_over_cup_menu").animate({opacity: "0"}, 1);
		$("#item_over_cup_menu").css("display", "none");
		
		/* Camera */
		$("#item_over_camera").animate({opacity: "0"}, 1);
		
		/* Picture */
		$("#item_over_picture").animate({opacity: "0"}, 1);
		//$("#item_over_picture_menu").animate({opacity: "0"}, 1);
		$("#item_over_picture_menu").css("display", "none");

	/* End Item Roll Over Initial Sets */

	/* Guided Tour Items Initial Set */
	$("#guided_over").css("display", "none");
	$("#item_over_guided_menu").css("display", "none");
	
	
	/*
	 * Standard Zoom Out functions
	 */

	$(".out").click(function()
	{
		moveOut($(this).attr("id"), "none");
	});
	
	$("#close_guided").click(function()
	{
		moveOut($(this).attr("id"), "none");
	});

	$(document).keyup(function(event){
		if (event.keyCode == 27) {
			if(guidedUp == "on")
			{
				moveOut($("#close_guided").attr("id"), "none");
			}
		}
	});
	
	/*
	 * Standard Zoom In Functionality
	 */

	$(".click").click(function()
	{
		moveIn($(this).attr("id"));
	});
	
	/* Start Hover Effects for buttons */
	$(".hover").hover(
	function()
	{
		if($(this).hasClass("hover"))
		{
			height = $(this).height();
			$(this).css("background-position", "0px -"+height+"px");
		}

	},
	function()
	{
		if($(this).hasClass("hover"))
		{
			$(this).css("background-position", "0px 0px");
		}

	});

	/*
	 * Start ROLL-OVER Effects for Desk Items
	 */
	$(".click").mouseover(
	function()
	{
		objectId = $(this).attr("id");
		objectName = objectId.split("_")[1];
		if(objectName != "keyboard")
		{
			$("#item_over_"+objectName).css("display", "block");
			$("#item_over_"+objectName).stop();
			$("#item_over_"+objectName).animate({opacity: 1}, 300);
	
			$("#item_over_"+objectName+"_menu").css("display", "block");

			if(overScreens == true)
			{
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}

	});

	$(".click").mouseout(function()
	{
		objectIdout3 = $(this).attr("id");
		objectNameout3 = objectIdout3.split("_")[1];
		if(objectName != "keyboard")
		{
			$("#item_over_"+objectNameout3).stop();
			$("#over_"+objectNameout3).stop();
	
			//$("#item_over_"+objectNameout3).animate({opacity: 0}, 300, function(){ $("#item_over_"+objectNameout3).css("display", "none");});
			$("#item_over_"+objectNameout3).animate({opacity: 0}, 300);
			$("#item_over_"+objectNameout3+"_menu").css("display", "none");
	
			$("#over_"+objectNameout3).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout3).css("display", "none"); });
		}
	});

	$(".click_nomenu").mouseover(
	function()
	{
		objectId = $(this).attr("id");
		objectName = objectId.split("_")[1];

		$("#item_over_"+objectName).css("display", "block");
		$("#item_over_"+objectName).stop();
		$("#item_over_"+objectName).animate({opacity: 1}, 300);

		if(objectName == "phone" || objectName == "keyboard")
		{
			$("#nav_"+objectName).css("background-image", "url(images_vt/top_bar_rollover.jpg)");
			$("#nav_"+objectName).css("background-repeat", "repeat-x");
		}
		if(overScreens == true)
		{
			$("#over_"+objectName).css("display", "block");
			$("#over_"+objectName).stop();
			$("#over_"+objectName).animate({opacity: 1}, 300);
		}
		
		//$("#over_"+objectName).animate({opacity: 1}, 300);
	});

	$(".click_nomenu").mouseout(
	function()
	{
		objectIdout2 = $(this).attr("id");
		objectNameout2 = objectIdout2.split("_")[1];

		$("#item_over_"+objectNameout2).stop();
		$("#over_"+objectNameout2).stop();

		//$("#item_over_"+objectNameout2).animate({opacity: 0}, 300, function(){ $("#item_over_"+objectNameout2).css("display", "none");});
		$("#item_over_"+objectNameout2).animate({opacity: 0}, 300);
		//$("#over_"+objectName).animate({opacity: 0}, 300);
		
		if(objectName == "phone" || objectName == "keyboard")
		{
			$("#nav_"+objectNameout2).css("background-image", "none");
		}

		$("#over_"+objectNameout2).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout2).css("display", "none"); });
	});

	/*
	 * End ROLL-OVER Effects for Desk Items
	 */

	 
	 /*
	  * Phone Admissions Campus Visits tab changes
	  */

	  $("#bar_campusvisits").click(function()
	  {
		$("#big_phone_bar").css("background-position", "0px 0px");
		$(".big_phone_main_header_logo").css("background-position", "0px 0px");
		
		$("#bar_admissions").css("background-position", "0px 0px");
		$("#bar_campusvisits").css("background-position", "0px -21px");
		$("#big_phone_main_admissions").css("display", "none");	
		$("#big_phone_main_campusvisits").css("display", "block");
	  });
	  
	  $("#bar_admissions").click(function()
	  {
		$("#big_phone_bar").css("background-position", "0px -45px");
		$(".big_phone_main_header_logo").css("background-position", "0px -69px");
		
		$("#bar_admissions").css("background-position", "0px -21px");
		$("#bar_campusvisits").css("background-position", "0px 0px");
		$("#big_phone_main_admissions").css("display", "block");	
		$("#big_phone_main_campusvisits").css("display", "none");
	  });
	 
	 
	/*
	 * Start Click effects for Nonmenu desktop items
	 */

	$(".dark").click(function()
	{
		if(state == "in" && darkUp != "on")
		{
			objectId = $(this).attr("id");
			objectName = objectId.split("_")[1];
	
				/* Clear Intro Video if it exists */
				if(videoPlay == "play")
				{
					$("#intro_video").html("");	
					$("#intro_video").css("display", "none");
					$("#skip_video").css("display", "none");
				}
	
			$("#dark").css("display", "block");
			$("#dark").animate({opacity: ".70"}, 1);
	
			$("#big").css("display", "block");
			$("#big_"+objectName).css("display", "block");
	
			$("#big").animate({opacity: 1}, 500, function()
			{
				if(objectName == "phone")
				{
					phoneUp = "on";	
				}
				else if(objectName == "camera")
				{
					$("#wallpaper_thumbnails").html('<img id="loader" src="images_vt/loading.gif" />');
					getWallpapers(screenx, 'big_camera_screen');
				}
				darkUp = "on";
			});

		}
		else
		{
			if(darkUp != "on")
			{
				if(objectName == "phone")
				{
					moveOut("_"+objectName, "darkIn");
				}
			}
			else
			{
				if(objectName == "phone" && phoneUp != "on")
				{
					$("#big_camera").css("display", "none");	
					darkOut(objectName, "darkIn");
				}
			}
		}
	});

	$(".closebig").click(function()
	{
		if(state == "in" && darkUp == "on")
		{
			objectId = $(this).attr("id");
			objectName = objectId.split("_")[2];
	
			$("#big").animate(
			{
				opacity: 0
			}, 
			500, 
			function()
			{

				if(objectName == "camera")
				{
					$("#wallpaper_full").html("");
					$("#wallpaper_loading").html("");
					$("wallpaper_thumbnails").html("");			
	
	
					$("#big_camera_goback").css("display", "none");
					$("#big_camera_previous").css("display", "none"); 
					$("#big_camera_next").css("display", "none"); 
					$("#wallpaper_full").css("display", "none");
				}


				$("#big_camera").css("display", "none");
				$("#big_phone").css("display", "none");

				$("#big").css("display", "none");
				$("#dark").css("display", "none");
				darkUp = "off";
				phoneUp = "off";	
			});
		}

	});


	/*
	 * End Click effects for Nonmenu desktop items
	 */


	/*
	 * Skip Video Click event
	 */
	
	$("#skip_video").click(function()
	{
		/* Clear Intro Video if it exists */
 		if(videoPlay == "play")
		{
			overScreens = true; 
			/* Resume Running Picture Frame Slideshow */
			$('#framepics').cycle('resume');

			$("#intro_video").html("");	
			$("#intro_video").css("display", "none");
			$("#skip_video").css("display", "none");
		}
	});

	/*
	 * Play Video Click event
	 */
	
	$(".play_intro").click(function()
	{
		videoPlay = "play";
		/* Clear Intro Video if it exists */
 		if(videoPlay == "play")
		{
			overScreens = false; 

			/* Pause Running Picture Frame Slideshow */
			$('#framepics').cycle('pause');
			$("#intro_video").html("");
			$("#intro_video").css("display", "block");
			$("#skip_video").css("display", "block");
			$("#intro_video").flash({src: "videos_vt/player.swf?file=VT_tour4_anim2.flv&autostart=true&controlbar=none&image=images_vt/virtual_tour-monitor-home.jpg&tracecall=traceVideo&displayclick=none", width: 490, height: 301, allowfullscreen: true});
		}
	});

	/*
	 * END Skip Video Click event
	 */


	/* 
	 * Start ROLL-OVER Effects for Header Nav Items
	 */

	$("ul.navitem li").hover(
	function()
	{
		objectId = $(this).attr("id");
		objectName = objectId.split("_")[1];

		$(this).css("background-image", "url(images_vt/top_bar_rollover.jpg)");	
		$(this).css("background-repeat", "repeat-x");	

		if(objectName == "phone")
		{
			if(overScreens == true && state == "in")
			{
				$("#item_over_"+objectName).css("display", "block");
				$("#item_over_"+objectName).stop();
				$("#item_over_"+objectName).animate({opacity: 1}, 300);
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}

		if(objectName == "keyboard")
		{

			if(overScreens == true && state == "in")
			{
				$("#item_over_"+objectName).css("display", "block");
				$("#item_over_"+objectName).stop();
				$("#item_over_"+objectName).animate({opacity: 1}, 300);
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}
		
		if(objectName == "visit")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}
		
		if(objectName == "homepage")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}
		
		if(objectName == "apply")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectName).css("display", "block");
				$("#over_"+objectName).stop();
				$("#over_"+objectName).animate({opacity: 1}, 300);
			}
		}
		
	},
	function()
	{
		objectIdout = $(this).attr("id");
		objectNameout = objectId.split("_")[1];

		$(this).css("background-image", "none");

		if(objectNameout == "phone")
		{
			$("#item_over_"+objectNameout).stop();
			$("#item_over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#item_over_"+objectNameout).css("display", "none");});
			$("#over_"+objectNameout).stop();
			$("#over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout).css("display", "none"); });
		}

		if(objectNameout == "keyboard")
		{
			$("#item_over_"+objectNameout).stop();
			$("#item_over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#item_over_"+objectNameout).css("display", "none");});
			$("#over_"+objectNameout).stop();
			$("#over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout).css("display", "none"); });
		}
		
		if(objectNameout == "visit")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectNameout).stop();
				$("#over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout).css("display", "none"); });
			}
		}

		if(objectNameout == "homepage")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectNameout).stop();
				$("#over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout).css("display", "none"); });
			}
		}

		if(objectNameout == "apply")
		{
			if(overScreens == true && state == "in")
			{
				$("#over_"+objectNameout).stop();
				$("#over_"+objectNameout).animate({opacity: 0}, 300, function(){ $("#over_"+objectNameout).css("display", "none"); });
			}
		}		
		
	});


	/* 
	 * End ROLL-OVER Effects for Header Nav Items
	 */

	/*
	 * Guided Tour Sign Effect
	 */
	$(".guided_over").mouseover(
	function()
	{
			$("#guided_over").movieSlide.hover = true;
			$("#guided_over").movieSlide.interrupt = false;
			$("#guided_over").movieSlide("1,0,1,2,3,4,3,2", 1, 188, 100, true, true, true);
	});
	$(".guided_over").mouseout(
	function()
	{
			$("#guided_over").movieSlide.hover = false;
			$("#guided_over").movieSlide.interrupt = true;
	});

	
	/*
	 * Guided Tour Close Button Effect
	 */
	$("#close_guided").mouseover(
	function()
	{
			$("#close_guided").movieSlide.hover = false;
			$("#close_guided").movieSlide.interrupt = false;
			$("#close_guided").movieSlide("1,2", 1, 76, 100, false, false, false);
	});
	$("#close_guided").mouseout(
	function()
	{
			$("#close_guided").movieSlide.hover = false;
			$("#close_guided").movieSlide.interrupt = false;
			$("#close_guided").movieSlide("1,0", 1, 76, 100, false, false, false);
	});

	 
	 
	/*
	 * Bear Mouse-over effect
	 */
	$("#map_bear").mouseover(
	function()
	{
			$("#item_over_picture").stop();
			$("#item_over_picture").animate({opacity: "0"}, 1);
			$("#bear_over").movieSlide.hover = true;
			$("#bear_over").movieSlide.interrupt = false;
			$("#bear_over").movieSlide("1,2,1,0,3,4,3,0", 1, 57, 100, true, true, true);
	});
	$("#map_bear").mouseout(
	function()
	{
			$("#bear_over").movieSlide.hover = false;
			$("#bear_over").movieSlide.interrupt = true;
	});

	$("#bear_over_push").mouseover(
	function()
	{
			$("#bear_over_push").movieSlide.hover = true;
			$("#bear_over_push").movieSlide.interrupt = false;
			$("#bear_over_push").movieSlide("1,2,1,0,3,4,3,0", 1, 89, 100, true, true, false);
	});
	$("#bear_over_push").mouseout(
	function()
	{
			$("#bear_over_push").movieSlide.hover = false;
			$("#bear_over_push").movieSlide.interrupt = true;
	});


	$("#bear_over_push_keyboard").mouseover(
	function()
	{
			$("#bear_over_push_keyboard").movieSlide.hover = true;
			$("#bear_over_push_keyboard").movieSlide.interrupt = false;
			$("#bear_over_push_keyboard").movieSlide("1,2,1,0,3,4,3,0", 1, 89, 100, true, true, false);
	});
	$("#bear_over_push_keyboard").mouseout(
	function()
	{
			$("#bear_over_push_keyboard").movieSlide.hover = false;
			$("#bear_over_push_keyboard").movieSlide.interrupt = true;
	});

	$("#bear_over_guided").mouseover(
	function()
	{
			$("#bear_over_guided").movieSlide.hover = true;
			$("#bear_over_guided").movieSlide.interrupt = false;
			$("#bear_over_guided").movieSlide("1,2,1,0,3,4,3,0", 1, 89, 100, true, true, false);
	});
	$("#bear_over_guided").mouseout(
	function()
	{
			$("#bear_over_guided").movieSlide.hover = false;
			$("#bear_over_guided").movieSlide.interrupt = true;
	});	

	/*
	 * Picture Frame Rotation
	 */

	$("#framepics").cycle(
	{
		fx: 'fade',
		speedIn: 1,
	   	speedOut: 1000,
		containerResize: 1,
		pause: 1
	});

	/* 
	 * Get Time from Server Every Minute
	 */
	getTime('time');
	setInterval("getTime('time');", 60000);

	/*
	 * Detect Closest Resolution for Wallpapers
	 */
	screenx = screen.width;
	screeny = screen.height;
	$("#big_camera_screensize option:contains("+screenx+"x)").attr("selected", true);

	$("#big_camera_screensize select").styledSelect();

	
	$("#big_camera_screensize select").bind('change', function()
	{
		$("#big_camera_goback").css("display", "none");
		$("#big_camera_previous").css("display", "none"); 
		$("#big_camera_next").css("display", "none"); 
		$("#wallpaper_full").css("display", "none");


		$("#wallpaper_thumbnails").html('<img id="loader" src="images_vt/loading.gif" />');

		getWallpapers(this.value, 'big_camera_screen');
	});
	
	
	switch(screenx)
	{
		case "1024":
			wallpaperSize = screenx;
			break;
		case "1280":
			wallpaperSize = screenx;
			break;
		case "1440":
			wallpaperSize = screenx;
			break;
		case "1600":
			wallpaperSize = screenx;
			break;
		case "1680":
			wallpaperSize = screenx;
			break;
		case "1920":
			wallpaperSize = screenx;
			break;
		default:
			var aspect = screenx / screeny;
			var std = Math.abs(aspect - 1.333);
			var wide = Math.abs(aspect - 1.6);
			if( wide < std )
			{
				if( screenx > 1800 )
				{
				        wallpaperSize = '1920';
					screenx = 1920;
					screeny = 1200;
			        } 
				else if( screenx > 1500 )
				{
			        	wallpaperSize = '1680';
					screenx = 1680;
					screeny = 1050;
			        }
				else
				{
				        wallpaperSize = '1600';
					screenx = 1600;
					screeny = 1200;
			      	} 
			} 
			else 
			{
				if( screenx > 1400 )
				{
			        	wallpaperSize = '1440';
					screenx = 1440;
					screeny = 900;
			      	}
				else if( screenx > 1100 )
				{
			        	wallpaperSize = '1280';
					screenx = 1280;
					screeny = 1024;
			      	}
				else
				{
			        	wallpaperSize = '1024';
					screenx = 1024;
					screeny = 768;
			      	} 		
			}
			break;
	}

	/* WALL PAPER GALLERY CONTROLS */

	$("#big_camera_goback").click(function()
	{
		$("#wallpaper_full").html("");
		$("#wallpaper_loading").html("");

		$("#big_camera_goback").css("display", "none");
		$("#big_camera_previous").css("display", "none"); 
		$("#big_camera_next").css("display", "none"); 
		$("#wallpaper_full").css("display", "none");

	});

	$("#big_camera_next").click(function()
	{
		currentId = parseInt(currentId) + 1;

		if(parseInt(currentId) > parseInt(imageArray.length - 1))
		{
			currentId = 0;
		}
		$(".wallpaper_selected").removeClass("wallpaper_selected"); 
		$("#"+currentId).addClass("wallpaper_selected");

		//LOADING
		$("#wallpaper_full").html("");
		$("#wallpaper_loading").html("");
		$("#wallpaper_full").html('<img id="loader" src="images_vt/loading.gif" />');
			
		getWallpaper(imageArray[currentId], "wallpaper_full", "wallpaper_loading");
	});

	$("#big_camera_previous").click(function()
	{
		currentId = parseInt(currentId) - 1;

		if(parseInt(currentId) < 0)
		{
			currentId = parseInt(imageArray.length - 1);
		}		
		$(".wallpaper_selected").removeClass("wallpaper_selected"); 
		$("#"+currentId).addClass("wallpaper_selected");

		//LOADING
		$("#wallpaper_full").html("");
		$("#wallpaper_loading").html("");
		$("#wallpaper_full").html('<img id="loader" src="images_vt/loading.gif" />');
			
		getWallpaper(imageArray[currentId], "wallpaper_full", "wallpaper_loading");
	});
	
	/* Guided Tour Stuff */
	$("#video_list li").hover(
		function()
		{
			objectId = $(this).attr("id");
			objectName = objectId.split("_")[2];
			if(tourActivated != objectName)
			{
				$("#video_list_"+objectName).css("background-position", "0px -77px");
			}
		},
		function()
		{
			objectId = $(this).attr("id");
			objectName = objectId.split("_")[2];
			if(tourActivated != objectName)
			{
				$("#video_list_"+objectName).css("background-position", "0px 0px");
			}
		}
	);	
	
	$("#video_list li").click(function()
	{
		$(".video_loading_images").css("display", "none");
		$("#video_list_"+tourActivated).stop();
		
		objectId = $(this).attr("id");
		objectName = objectId.split("_")[2];
		$("#video_list_"+tourActivated).css("background-position", "0px 0px");
		$("#video_list_"+objectName).css("background-position", "0px -154px");
		tourActivated = objectName;		
		
		//$("#video_output").html("");
		$("#video_container").html("");
		$("#video_loading_"+objectName).css("display", "block");
		
		$("#video_list_"+objectName).animate
		(
			{
				left: "4px"
			}
			, 2000, 
			function()
			{
				//alert("fest");
				//$("#video_loading_"+objectName).css("display", "none");
				$("#video_container").html("");
				$(".video_loading_images").css("display", "none");
				//$("#video_container").flash({src: $(this).attr("videosrc"), width: 480, height: 290, allowfullscreen: true});
				$('#video_container').html('<embed width="480" height="290" flashvars="'+$(this).attr("videosrc").split("?")[1]+'" allowscriptaccess="always" allowfullscreen="true" quality="high" src="'+$(this).attr("videosrc").split("?")[0]+'" type="application/x-shockwave-flash">');
			}
		);
		
	});

});

/* Guided Tour Videos Trace Function */
function guidedTourTrace(id)
{
	//$("#video_output").append(id);
	if(id.match("COMPLETED") || id.match("STOP"))
	{
		$(".video_loading_images").css("display", "none");
		
		$("#video_container").html("");
		$(".video_list_items").css("background-position", "0px 0px");
		tourActivated = "";
	}
}	


/*
 * movieSlide jQuery Plugin -- REQUIRES jQuery to work!!
 * Author: Lyle Pratt - Baylor University
 * ================ Variables ==========================
 * orderString = a sequence of frames to show, or just a total number of frames which will be displayed in order
 * startingFrame = the frame the animation will start on
 * frameHeight = the height of 1 frame of the background (the portion of the image being displayed)
 * speed = the length of time to pause in between frames
 * hideAfter = toggle whether or not to hide the object (element) after the animation is finished (useful for pages
 *          with multiple animations which have to toggle back to a core (base) image)
 * loop = true will make the animation loop if being hovered
 * variable to check to see if the element is being hovered on (useful for looping)
 *
 * remove = whether to set to display none or just set opacity to 0
 */ 

$.fn.movieSlide = function (orderString, startingFrame, frameHeight, speed, hideAfter, loop, remove)
{

	$(this).css("display", "block");
	$(this).animate({opacity: "1"}, 1);

	elementId = $(this).attr('id');	

	//Setup Frame Array, check for string or total number of frames
	if(orderString.match(","))
	{
		orderArray = orderString.split(",");
	}
	else
	{
		var frame = 0;
		for(var i = 1; i <= orderString; i++)
		{
			frame = i;
			orderArray[frame] = i;
		}
	}

	if($.fn.movieSlide.interrupt == true)
	{
		startingFrame = total + 1;
		if(hideAfter == true)
		{
			if(remove == true)
			{
				$(this).css("display", "none");
			}
			$(this).animate({opacity: "0"}, 1);
		}
		
	}

	total = orderArray.length;
	if(startingFrame > total && loop == true && $.fn.movieSlide.hover == true)
	{
		startingFrame = 1;
	}

	height = orderArray[parseInt(startingFrame) - 1] * parseInt(frameHeight);

	if(startingFrame <= total)
	{
		$(this).css("background-position", "0px -"+ parseInt(height) +"px");
		
		startMore = startingFrame + 1;

		setTimeout("$('#"+ elementId +"').movieSlide('"+ orderString +"', "+ startMore +", "+ frameHeight +", "+ speed +", "+ hideAfter +", "+ loop +")", speed);
	}
	else
	{
		if(hideAfter == true)
		{
			if(remove == true)
			{
				$(this).css("display", "none");
			}
			$(this).animate({opacity: "0"}, 1);
		}
		
	}
}

/* jQuery image preload function/plugin
 */

jQuery.preloadImages = function()
{
  jQuery.each (arguments,function (e)
  {
    jQuery("<img>").attr("src", this);
  });
}


/* Check if object is in the DOM */
$.fn.inDOM =function()
{
	return !!$(this).parents('html').length;
}

/*
 * Function to get time from server
 */

function getTime(field)
{
	var url = site_url+"?time=true";
	$.ajax(
	{
		url: url,
		cache: false,
		success: function(response)
		{
			$("#"+field+"").html("<p>"+response+"</p>");
			$("#"+field+"_push").html("<p>"+response+"</p>");
		}
	});

}

function getWallpapers(screenx, field)
{
	response = "";
	var url = site_url+"?screenx="+screenx;
	$.ajax(
	{
		dataType: "html",
		url: url,
		cache: true,
		success: function(response)
		{
			$("#"+field+"").html("");
			$("#"+field+"").html(response);
			$(".wallpaper_thumb").click(function()
			{
				currentId = $(this).attr("full").split(";")[0];

				$(".wallpaper_selected").removeClass("wallpaper_selected"); 
				$("#"+currentId).addClass("wallpaper_selected");

				//LOADING
				$("#wallpaper_full").html('<img id="loader" src="images_vt/loading.gif" />');

				$("#wallpaper_full").css("display", "block");
				$("#big_camera_goback").css("display", "block");
				$("#big_camera_previous").css("display", "block"); 
				$("#big_camera_next").css("display", "block"); 

				getWallpaper($(this).attr("full").split(";")[1], "wallpaper_full", "wallpaper_loading");
			}); 	
		}
	});
}

function getWallpaper(imageId, field, loadingField)
{
	response = "";
	var url = site_url+"?imageId="+imageId;
	$.ajax(
	{
		dataType: "html",
		url: url,
		cache: true,
		success: function(response)
		{
			imageUrl = response.split('src="')[1].split('"')[0];

			$("#"+loadingField+"").html("");
  			$("#"+loadingField+"").image(imageUrl,function()
			{
					//$("#"+field+"").html("");
        			$("#"+field+"").html(response);
       		});     
		}
	});
}


$.fn.image = function(src, f)
{
	return this.each(function()
	{
		var i = new Image();
		i.onload = f;
		i.src = src;
		this.appendChild(i);
	});
}

function darkIn(objectName)
{
				/* Clear Intro Video if it exists */
				if(videoPlay == "play")
				{
					$("#intro_video").html("");	
					$("#intro_video").css("display", "none");
					$("#skip_video").css("display", "none");
				}
	
			$("#dark").css("display", "block");
			$("#dark").animate({opacity: ".70"}, 1);
	
			$("#big").css("display", "block");
			$("#big_"+objectName).css("display", "block");
	
			$("#big").animate({opacity: 1}, 500, function()
			{
				if(objectName == "phone")
				{
					phoneUp = "on";
				}
				else if(objectName == "camera")
				{
					$("#wallpaper_thumbnails").html('<img id="loader" src="images_vt/loading.gif" />');
					getWallpapers(screenx, 'big_camera_screen');
				}
				darkUp = "on";
			});

}

function darkOut(objectName, animation)
{	
			$("#big").animate(
			{
				opacity: 0
			}, 
			500, 
			function()
			{
				$("#big_camera").css("display", "none");
				$("#big_phone").css("display", "none");
				$("#big").css("display", "none");
				$("#dark").css("display", "none");
				phoneUp = "off";
				darkUp = "off";
				if(animation == "darkIn")
				{
					darkIn(objectName);
				}
				else if(animation == "moveIn")
				{
					moveIn("_"+objectName)
				}
			});
}

function switchDisplay(objectName)
{
	$(".itemscreen").css("display", "none");

	//Reset Slideshow
	$('.primary').cycle("stop");
	$(".scrollwrap").animate({left: "0px"});

	
	/* BEAR OVER PUSH */
	if(objectName == "keyboard")
	{
		keyboardUp = "on";
		$("#bear_over_push_keyboard").css("display", "block");
		$("#bear_over_guided").css("display", "none");
		$("#bear_over_push").css("display", "none");
	}
	else if(objectName == "guided")
	{
		guidedUp = "on";
		$("#bear_over_guided").css("display", "block");
		$("#bear_over_push_keyboard").css("display", "none");
		$("#bear_over_push").css("display", "none");
	}
	else
	{
		keyboardUp = "off";
		guidedUp = "off";
		$("#bear_over_guided").css("display", "none");
		$("#bear_over_push_keyboard").css("display", "none");
		$("#bear_over_push").css("display", "block");
	}

	$("#screen_"+objectName).css("display", "block");
}

function moveOut(item, afterAnimation)
{
	objectName = item.split("_")[1];

	if(state == "out" && darkUp == "off")
	{

		$("#time_push").css("display", "none");

		$("#screen_keys").css("display", "none");
		$("#screen_cup").css("display", "none");
		$("#screen_football").css("display", "none");
		$("#screen_books").css("display", "none");
		$("#screen_picture").css("display", "none");
		$("#screen_bible").css("display", "none");
		$("#screen_keyboard").css("display", "none");
		$("#screen_guided").css("display", "none");

		/* BEAR OVER PUSH */
		if(objectName == "keyboard")
		{
			keyboardUp = "off";
			$("#bear_over_push_keyboard").css("display", "none");
		}
		else if(objectName == "guided")
		{
			guidedUp = "off";
			$("#bear_over_guided").css("display", "none");
			$("#video_list_1").css("background-position", "0px 0px");
			$("#video_list_2").css("background-position", "0px 0px");
			$("#video_list_3").css("background-position", "0px 0px");
			$("#video_list_4").css("background-position", "0px 0px");
			$("#video_container").html("");
			tourActivated = "";
			
			$(".video_loading_images").css("display", "none");			
		}
		else
		{
			keyboardUp = "off";
			$("#bear_over_push").css("display", "none");
		}

		//Clear out flash videos
		$('.primaryvideo').html("");

		$("#screen").css("display", "none");
		//$("#screen_"+objectName).css("display", "none");
		
		$("#bgimage").fadeIn(300);
		$("#bgimage").animate
		(
			{
				left: "0px",
				width: "904px",
				
				top: "0px",
				height: "616px"
			}
			, 1500, 
			function()
			{
				/* Resume Running Picture Frame Slideshow */
				$('#framepics').cycle('resume');
				
				$("#framepics").css("display", "block");

				$("#overlayhidden").css("display", "block");

				$("#time").css("display", "block");

				$("#play_intro").css("display", "block");

				//Reset Slideshow
				$('.primary').cycle("stop");
				$(".scrollwrap").animate({left: "0px"});

				state = "in";
				if(afterAnimation == "darkIn")
				{
					darkIn(objectName);
				}
				else if(afterAnimation == "moveIn")
				{
					moveIn(item)
				}
			}
		);
	}
}	

function moveIn(item)
{
	objectName = item.split("_")[1];
	
	if(state == "in" && darkUp == "off")
	{
		state = "mid";

		/* Clear Intro Video if it exists */
		if(videoPlay == "play")
		{
			overScreens = true;
			$("#intro_video").html("");	
			$("#intro_video").css("display", "none");
			$("#skip_video").css("display", "none");
		}

		$("#play_intro").css("display", "none");

		/* START Stop/Hide Rollovers and Objects before Zoom */
		
		/* Pause Running Picture Frame Slideshow */
		$('#framepics').cycle('pause');

		/* Hide Time on Iphone */
		$("#time").css("display", "none");

		/* Screen Overlays */
		$(".screenover").css("display", "none");

		/* Item object overlays */
		$(".itemover").css("display", "none");

		/* Item Menu */
		$(".itemovermenu").css("display", "none");

		/* Image Map Transparent Overlay */
		$("#overlayhidden").css("display", "none");

		/* Rotating picture frame images */
		$("#framepics").css("display", "none");

		/* END Stop/Hide Rollovers and Objects before Zoom */

		/* BEAR OVER PUSH */
		if(objectName == "keyboard")
		{
			keyboardUp = "on";
			$("#bear_over_push_keyboard").css("display", "block");
			$("#bear_over_guided").css("display", "none");
			$("#bear_over_push").css("display", "none");
		}
		else if(objectName == "guided")
		{
			guidedUp = "on";
			$("#bear_over_guided").css("display", "block");
			$("#bear_over_push_keyboard").css("display", "none");
			$("#bear_over_push").css("display", "none");
		}
		else
		{
			keyboardUp = "off";
			guidedUp = "off";
			$("#bear_over_guided").css("display", "none");
			$("#bear_over_push_keyboard").css("display", "none");
			$("#bear_over_push").css("display", "block");
		}
		
		/* START ZOOM IN ANIMATION */
		$("#bgimage").animate(
		{
			left: "-290px",
			width: "1410px",
			
			top: "0px",
			height: "965px"
		}
		, 1500, 
		function()
		{
			$("#bgimage").fadeOut(300);

			$("#screen").css("display", "block");
			$("#screen_"+objectName).css("display", "block");

			$("#time_push").css("display", "block");

			/*Scroll Pane */	
			//$('#items_'+objectName).css("display", "block");
			//$('#scrollwrap_'+objectName).css("display", "block");
			//$('#items_'+objectName).animate({opacity: "1"}, 1);
			//$('#item_'+objectName).animate({opacity: "1"}, 1);
			//$('#scrollwrap_'+objectName).animate({opacity: "1"}, 1);

			$('#scrollwrap_'+objectName).jScrollPane(
			{
				showArrows: true,
				animateTo: true,
				animateStep: "5",
				scrollbarWidth: "16",
				scrollbarHeight: "348",
				dragMaxHeight: "35",
				dragMinHeight: "35",
				reinitialiseOnImageLoad: true
			});

			function prevNext(isNext, index, element)
			{	

			}
			
			function onBefore(currSlideElement, nextSlideElement, options, forwardFlag)
			{
				count = $(".item_"+objectName).size();
				if($('#primaryvideo_'+objectName).html() != "")
				{
					$('#primaryvideo_'+objectName).html("");
					$('#primary_'+objectName).css("display", "block");
				}
				//$('#text_'+objectName+' h2').html($(this).attr("title"));
				//$('#text_'+objectName+' p').html($(this).attr("text"));
				$('#slidecount_'+objectName).html((options.currSlide + 1)+" of "+(count));
			}
			
			var scrollWrap = $('#scrollwrap_'+objectName)[0];
			function onAfter(currSlideElement, nextSlideElement, options, forwardFlag)
			{
				scrollWrap.scrollTo(".activeSlide");
				count = $(".item_"+objectName).size();
				$('#slidecount_'+objectName).html((options.currSlide + 1)+" of "+(count));
				if($(this).is(".video"))
				{
					//$('#primary_'+objectName).css("display", "none");
					$('#primaryvideo_'+objectName).html('<embed width="556" height="312" flashvars="'+$(this).attr("videosrc").split("?")[1]+'" allowscriptaccess="always" allowfullscreen="true" quality="high" src="'+$(this).attr("videosrc").split("?")[0]+'" type="application/x-shockwave-flash">');
					//$('#primaryvideo_'+objectName).html('<embed width="556" height="312" flashvars="file=http://edge.baylor.edu/media/112079/112079-wvideo.mp4&autostart=false&controlbar=bottom&image=http://edge.baylor.edu/media/85488/85488pw.png" allowscriptaccess="always" allowfullscreen="true" quality="high" src="http://www.baylor.edu/virtualtour//videos_vt/player.swf" type="application/x-shockwave-flash">');
					//$('#primaryvideo_'+objectName).flash({src: $(this).attr("videosrc"), width: 556, height: 312, allowfullscreen: true});
				}

				$('#pageright_'+objectName).css("background-position", "0px 0px");
				$('#pageright_'+objectName).addClass("hover");
				$('#pageleft_'+objectName).css("background-position", "0px 0px");
				$('#pageleft_'+objectName).addClass("hover");
			}
			
			$('#primary_'+objectName).cycle(
			{ 
				fx: 'scrollHorz',
				timeout: 0,
				next: '.pageright_'+objectName,
				prev: '#pageleft_'+objectName,
				before: onBefore,
				after: onAfter,
				pager: '#pager_'+objectName,
				prevNextClick: prevNext,
				nowrap: 0,
				pagerAnchorBuilder: function(idx, slide)
				{ 
					return '#pager_'+objectName+' li:eq(' + idx + ') a';
				}
			});

			
			state = "out";

		}
		);
		/* END ZOOM IN ANIMATION */
	}
	else
	{
		if(objectName == "keyboard" && keyboardUp == "off")
		{
			if(darkUp == "on")
			{
				darkOut(objectName, "moveIn");
			}
			else
			{
				//zoomOut(objectName, "zoomIn");
				switchDisplay(objectName);
			}
		}
	}
}
