// JavaScript Document

var photoGalleryPhoto = 1;
var timer;
var time = 6500; //the time in milliseconds between the cycles of the main image and it's contents; initial setting 3500
var newIndex = 0; //the current thumbnail/image
var thumbnailClicked = false;




$(document).ready(function() { 	
	
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
{
                $("#home #leftNav").css("margin-left","0px");
}

//display the thumbnails (will not show when JS is turned off)
	$('ul#thumbnails').css("display","block");
	
	//start the timer
	clearTimeout(timer);
	timer = setTimeout("timedCount()",time);  

	//a thumbnail has been clicked
	$("#thumbnails li a").click(function()
	{
		//get the thumbnail that has been clicked
		var num = $("#thumbnails li a").index(this);

		//reset the z-index and opacity of all images to zero
		$('#mainImage img').css("z-index", "0").css("opacity", "0");
		
		//keep the current image viewable so the new image that was clicked on can fade into it
		$('.mainImg'+(newIndex)).css("opacity", "1");
		
		//put the current image on top
		$('.mainImg'+num).css("z-index", "1").animate({opacity:1}, 1000);

		//remove the border from all thumbnails
		$('#thumbnails > li a').removeClass("activeThumb");
		
		//add a border to the current thumbnail
		$(this).addClass("activeThumb");
		
		//display the correct info for the current photo
		$('#photoInfo > p').css("display", "none");
		$('#photoInfo p.photo'+num).css("display", "block");
		
		//update the current thumbnail that has been clicked
		newIndex = num;
		
		//do not let the images cycle through once a thumbnail has been clicked on
		clearTimeout(timer);
		thumbnailClicked = true;
		
		return false;
	});
	
	
	//Pause the main image from rotating when the image or the thumbnails are hovered over. Resume the cycle after the hover
	$("#mainImage img, #thumbnails li a").hover(
		function()
		{
			clearTimeout(timer);
		},
		function() 
		{	
			//a thumbnail has only been hovered over, not clicked...reset the cycle
			if(thumbnailClicked == false)
			{
				clearTimeout(timer);
				timer = setTimeout("timedCount()",time); 
			}
		}
	);
	
	
//	/***************************************************************/
//	/*  This jQuery function rotates the images                    */
//	/*  in the Photo Gallery tab.                                  */
//	/***************************************************************/
//
//	$("#photoGallery").jCarouselLite({btnPrev: ".galleryLeft", btnNext: ".galleryRight", visible: 1});
	

	if($.browser.msie && $.browser.version=="6.0") 
	{
		$("#globalNav ul li").hover(
		  function () {
			$(this).addClass("hover");
		  }, 
		  function () {
			$(this).removeClass("hover");
		  }
		);
		
		$("#home #leftNav ul li").hover(
		  function () {
			$(this).addClass("hover");
		  }, 
		  function () {
			$(this).removeClass("hover");
		  }
		);
		
		$("ul#largeButtons li").hover(
		  function () {
			$(this).addClass("hover");
		  }, 
		  function () {
			$(this).removeClass("hover");
		  }
		);
		
		//some ie6 housekeeping
		$("#home #slideshow li").css("position","relative").css("zoom","1").css("height","176px").css("width","290px");

		$("#home #leftNav").css("position","absolute").css("left","0px").css("top","0px").width("313px").css("z-index", "2000").css("zoom","1").css("display","block");
		$("#mainImage").css("margin-left","313px");
		$("#photoInfo").css("margin-left","155px").width("567px");
		
		$("#photoGalleryContent").css("position","absolute").css("zoom","1").css("z-index","1000").css("display","block");
		$("#photoGalleryContent p").css("position","absolute").css("zoom","1").css("z-index","1000");
		
		$("#photoGallery a").css("position","absolute").css("top","0px").css("left","0px").css("zoom","1").css("z-index","2000").css("display","block").width("19px").height("16px");
		$("#photoGallery a img.galleryLeft").css("position","absolute").css("top","250px").css("left","20px").css("zoom","1").css("z-index","2000").css("display","block").width("19px").height("16px");
		$("#photoGallery a img.galleryRight").css("top","250px").css("left","400px").css("position","absolute").css("zoom","1").css("z-index","2000").css("display","block").width("19px").height("16px");		
	}//end of IE6 if statement
	
	
	$('#leftNav ul li').css("position","relative").css("z-index","200");
});

	/***************************************************************/
	/*  This jQuery function controls the functionality of the     */
	/*  tabbedPanel on the homepage								   */
	/***************************************************************/

$(function(){
	// set all content containers to invisible
	$("#tabWrapper > div").css("display","none");
	// set active content container to visible
	$("#tabWrapper > div.active").css("display","block");
	$("#tabs li a").click(function()
	{
		// remove active class from currently visible content area
		$("#tabWrapper > div.active").removeClass("active");
		// get href attribute value from clicked link to determine which content area to make visible and set active class to that div
		$(("#tabWrapper > div"+$(this).attr("href"))).addClass("active");
		// make all content areas invisible
		$("#tabWrapper > div").css("display","none");
		// make new active content area visible
		$("#tabWrapper > div.active").css("display","block");
		// remove active class from old tab
		$("#tabs li.active").removeClass("active");
		// set active class to new tab based on the click
		$(this).parent().addClass("active");
		// prevent browser from scrolling to the div anchor
		return false;
	});
	
	
	
	/***************************************************************/
	/*  This function is used for the videos tab on the homepage.  */
	/*  When a small image is clicked on, it will update the large */
	/*  video. 													   */
	/***************************************************************/
			
	$('#videoImages img').click(function() {
										 
		var video = "";
		
		if($(this).attr("alt") == 'video image 1')
		{
			video = "<object id=\"limelight_player_769639o\" width=\"279\" height=\"210\" data=\"http://assets.delvenetworks.com/player/loader.swf\" type=\"application/x-shockwave-flash\"><param name=\"wmode\" value=\"transparent\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowFullScreen\" value=\"true\" /><param name=\"flashvars\" value=\"playerForm=7834b4da0f3946688cb5669cb7154901&amp;channelId=50e9adf255f24507bde79a1cb174e9b4&amp;deepLink=true\" /><param name=\"src\" value=\"http://assets.delvenetworks.com/player/loader.swf\" /><param name=\"name\" value=\"limelight_player_769639e\" /><param name=\"allowfullscreen\" value=\"true\" /></object><p>Close-Up: What Are You Waiting For?<br />&nbsp;<br />&nbsp;<br /><a href=\"/ocm/videogallery.php\">Visit our video gallery &rsaquo;</a><p>";
		}
		else if($(this).attr("alt") == 'video image 2') 
			video = "<object width=\"279\" height=\"210\" id=\"limelight_player_182764o\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"window\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashvars\" value=\"deepLink=true&amp;channelId=78b8fce7645646768b618b1389934fa6&amp;playerForm=7834b4da0f3946688cb5669cb7154901\"/><embed src=\"http://assets.delvenetworks.com/player/loader.swf\" name=\"limelight_player_182764e\" wmode=\"window\" width=\"279\" height=\"210\" allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"deepLink=true&amp;channelId=78b8fce7645646768b618b1389934fa6&amp;playerForm=7834b4da0f3946688cb5669cb7154901\"></embed></object><p>Close-Up: The Power of UIU<br />&nbsp;<br />&nbsp;<br /><a href=\"/ocm/videogallery.php\">Visit our video gallery &rsaquo;</a><p>";
		else  
			video = "<object width=\"279\" height=\"219\" id=\"delve_player79086o\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"window\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashvars\" value=\"playerForm=ef321ae6defb417f8c8119ec4b7db59b&amp;channelId=b804a696964c4cfaa6ceecf8394ac354&amp;mediaId=7e03c6b3348d4330aa5665fef5d3f6d6\"/><embed src=\"http://assets.delvenetworks.com/player/loader.swf\" name=\"delve_player79086e\" wmode=\"window\" width=\"279\" height=\"219\" allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"playerForm=ef321ae6defb417f8c8119ec4b7db59b&amp;channelId=b804a696964c4cfaa6ceecf8394ac354&amp;mediaId=7e03c6b3348d4330aa5665fef5d3f6d6\"></embed></object><p>Close-Up: Education Anywhere<br />&nbsp;<br />&nbsp;<br /><a href=\"/ocm/videogallery.php\">Visit our video gallery &rsaquo;</a><p>";
		
		$('#largeVideo').html(video);
		
		return false;
	})
	

/* revised script for photogallery tab */


$('#smallPhoto img').click(function() {
										 
		var photo = "";
		
		if($(this).attr("alt") == 'photo image 1')
		{
			photo = "<a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/72157623170123173/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_studentlife');\"><img src=\"/images/default/tabs/gallery/Life-At-UIU-lg.jpg\" alt=\"Student Life at UIU Photo Gallery\" /></a><p>Close-Up: Life at UIU<br />(Opens in new window)<br />&nbsp;<br /><a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_photogallery');\">Visit our photo gallery &rsaquo;</a></p>";
		}
		else if($(this).attr("alt") == 'photo image 2') 
			photo = "<a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/72157623294527682/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_homecoming');\"><img src=\"/images/default/tabs/gallery/Homecoming-lg.jpg\" alt=\"Homecoming Weekend Photo Gallery\" /></a><p>Close-Up: Homecoming<br />(Opens in new window)<br />&nbsp;<br /><a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_photogallery');\">Visit our photo gallery &rsaquo;</a></p>";
		else  
			photo = "<a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/72157623165687839/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_commencement');\"><img src=\"/images/default/tabs/gallery/Commencement-lg.jpg\" alt=\"Commencement at UIU Photo Gallery\" /></a><p>Close-Up: Commencement<br />(Opens in new window)<br />&nbsp;<br /><a href=\"http://www.flickr.com/photos/upperiowauniversity/sets/\" target=\"_blank\" onClick=\"javascript: pageTracker._trackPageview('/outbound/flickr_photogallery');\">Visit our photo gallery &rsaquo;</a></p>";
		
		$('#largePhoto').html(photo);
		
		return false;
	})



	/***************************************************************/
	/*  This function is used for the Photo Gallery tab on the     */
	/*  homepage. This is where the photo content goes. 		   */
	/***************************************************************/
	
	$('.galleryLeft').click(function() {					 
		photoGalleryPhoto--;
		
		if(photoGalleryPhoto < 1)
		{
			photoGalleryPhoto = $("#photoGallery li").length-2;
		}
		
		galleryText(photoGalleryPhoto);
	})
	
	
	$('.galleryRight').click(function() {					 
		
		if(photoGalleryPhoto >= $("#photoGallery li").length-2)
		{
			photoGalleryPhoto = 0;
		}
		
		photoGalleryPhoto++;
		
		galleryText(photoGalleryPhoto);
	})
	
	
	function galleryText(number)
	{
		$('#photoGalleryContent > p').css("display", "none");
		$('#photoGalleryContent p.galleryText'+number).css("display", "block");
	}
});


function timedCount()
{	
	//find the total number of thumbnails (and main images)
	var totalThumbs = $("#thumbnails li").length-1;

	//make sure this function gets called on a timer
	clearTimeout(timer);
	timer = setTimeout("timedCount()",time);
	
	//find the number of the active thumbnail
	newIndex = $("#thumbnails li a").index($("#thumbnails li a.activeThumb"))+1;

	//reset the z-index and opacity of all images to zero
	$('#mainImage img').css("z-index", "0").css("opacity", "0");

	//if the timer has reached the end of the thumbnails, reset it to zero
	if(newIndex > totalThumbs)
	{
		newIndex = 0;
		//make the last image viewable so the first one can fade into it
		$('.mainImg'+totalThumbs).css("opacity", "1");
	}
		
	if(newIndex > 0)
	{	
		//make the last image viewable so the new one can fade into it
		$('.mainImg'+(newIndex-1)).css("opacity", "1");
	}

	//put the current image on top
	$('.mainImg'+newIndex).css("z-index", "1").animate({opacity:1}, 1000);
	
	//remove the active class from all thumbnails and apply it to the new one
	$("#thumbnails li a").removeClass("activeThumb");
	$("#thumbnails li a:eq("+newIndex+")").addClass("activeThumb");

	//change the photo text for the new image
	$('#photoInfo > p').css("display", "none");
	$('#photoInfo p.photo'+newIndex).css("display", "block");
	
	//make sure the left nav is still visible above the main image
	$('#leftNav ul li').css("position","relative").css("z-index","200");
}

