(function(){
		  
	//Create Namespace
	if(!window.UPS) {window['UPS'] = {}}
	
	//Sets up Image slider given the index of the media carousel tab that has the list of images (these are used as carousel controls)
	var imageCarousel = function(index, controlIndex) {
		
		if(!index) {
			index = 0;
		}
		
		if(!controlIndex) {
			controlIndex = index;
		}
		
		
		$('#image-carousel .carousel-container:eq(' + index + ')').show();
		$('#image-carousel .carousel-container:not(:eq(' + index + '))').hide();
		
		var myControls = [];
		
		$('.media-carousel-list:eq(' + controlIndex + ') li.images a').each(function() {										   
			
			myControls.push(this);	
			
		});
		
		$('#image-carousel .carousel-container:eq(' + index + ')').jCarouselLite({
															   
				btnNext: '#image-carousel #arrow-next',
				btnPrev: '#image-carousel #arrow-prev',
				visible: 1,
				scroll: 1,
				btnGo: myControls,
				circular: false
		});
			
	}
	window['UPS']['imageCarousel'] = imageCarousel;
	
	//Activates on-click functionality of image slider arrows
	var imageCarouselArrows = function(carousel_index) {
	
		//Get number of images in visible image list (carousel length)
		var carLength = 0;
		$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li').each(function() {
			carLength++;
		})
		//carLength = carLength - 1;
		
		var counter = $('#imageIndex').text();
		
		
		$("#arrow-next").click(function() {	
			if (counter < carLength - 1) {
				counter = $('#imageIndex').text();
				counter++;
				UPS.setImageIndex(counter);
				UPS.setMediaTop(carousel_index, counter);
				//Image tracking
				UPS.trackMedia($('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a').attr('href'),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.name').text(),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.pClass').text(),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.sClass').text());
			}
		});
		
		$("#arrow-prev").click(function() {
			if (counter > 0) {
				counter = $('#imageIndex').text();
				counter--;
				UPS.setImageIndex(counter);
				UPS.setMediaTop(carousel_index, counter);
				//Image tracking
				UPS.trackMedia($('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a').attr('href'),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.name').text(),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.pClass').text(),
						$('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + counter + ') a span.sClass').text());
			}
		});
	}
	window['UPS']['imageCarouselArrows'] = imageCarouselArrows;
	
	//sets category, title and description above the media player given a carousel index and a media item index 
	var setMediaTop = function(carousel_index, media_index) {
		//get category, title and description
		var category = $('#media-carousel-pulldown .current-topic').text();
		var title = $('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + media_index + ') a span.name').text();
		var description = $('#media-carousel .media-carousel-list:eq(' + carousel_index + ') ul li:eq(' + media_index + ') a span.description').text();
		
		//set category, title and description in 
		$('#media-player-top span.category').text(category + " > ");
		$('#media-player-top span.title').text(title);
		$('#media-player-top p').text(description);
	}
	window['UPS']['setMediaTop'] = setMediaTop;
	
	
	//re-creates image slider when image list item is clicked. supports multiple image lists
	var imageCarouselSwitch = function(carousel_index) {
		var imageListCount = 0;
		
		//Determine whether there is more than one image list
		$('#media-carousel-pulldown .pulldown-list').find('li.images').each(function() {
			imageListCount++;
		});
		
		//Activate image slider generation on click if there is more than one image tab
		if (imageListCount > 1) {
	
			//interaction with image slider when carousel tabs are lists of images
			//$('.media-carousel-list ul.image').each(function() {
				
				//var my_index = $('.media-carousel-list ul.image').index(this);
		

			
				$('#media-carousel-pulldown .pulldown-list li:eq(' + carousel_index + ') a').click(function() {
					UPS.imageCarousel(carousel_index);
				
				});				
			//});

		}//end if
		else {
			var index = 0;	
			//get index of image list in carousel
			$('.media-carousel-list ul').each(function() {
				var my_index = $('.media-carousel-list ul').index(this);
				if ($(this).hasClass('image')) {
					index = my_index;
				}
			});
			//If index > 0 it means that image list is not first so generation of image slider should set that list as controls
			if(index > 0) {
				UPS.imageCarousel(0, carousel_index);
			}
		}
	}
	window['UPS']['imageCarouselSwitch'] = imageCarouselSwitch;
	
	
	//Gets a list of image paths and populates the image viewer
	var populateImageSlider = function(imagePathList) {
		
		if (imagePathList && imagePathList.length > 0) {
			
			//Create carousel container div
			var containerDiv = $('<div class="carousel-container"></div>');
			var imageList = $('<ul></ul>');
			
			//Append content to container div
			for(var i=0; i < imagePathList.length; i++) {
				var listItem = $('<li><img src=' + imagePathList[i] + ' alt="" /></li>');
				$(imageList).append(listItem);
				
			}
			$(containerDiv).append(imageList);
	
			//Insert container div before end of image carousel div
			$('#arrow-next').before(containerDiv);
			
		}
		
	}
	window['UPS']['populateImageSlider'] = populateImageSlider;
	
	//Sets media player title and description based on first item in media carousel (only for use in media center landing page)
	//Also sets media download links based on first item 
	var setMediaInfo = function() {
		//first carousel item
		var item = $('#media-carousel .media-carousel-list:eq(0) ul li:eq(0)');
		//media item info
		var title = "";
		var desc = "";
		var category = "";
		//media download links
		var hiResLink = "";
		var loResLink = "";
		var mediaLink = "";
		var permaLink = "";
		var embedCode = "";
		//this class corresponds to the media type
		var mediaType = $(item).attr('class');
		
		title = $(item).find('a span.name').text();
		desc = $(item).find('a span.description').text();
		//category = $(item).find('a span.category').text();
		category = $('#media-carousel-pulldown .current-topic').text();
		permaLink = $(item).find('a span.permalink').text();
		mediaLink = $(item).find('a span.mediaLink').text();
		
		//set permaLink
		$('#mediacenter-download .links .permalink a').attr('href', permaLink);
		$('#mediacenter-download .links .permalink a').text(permaLink);
		if (permaLink != "") {
			$('#mediacenter-download .links .permalink').show();
		}
		
		//set media file information (title, category)
		if (category != "") { 
			$('#media-player-top h1 span.category').text(category + ' > ');
		}
		else {
			$('#media-player-top h1 span.category').text('');
		}
		$('#media-player-top h1 span.title').text(title);
		$('#media-player-top p').text(desc);	
		
		if (mediaType == "images") {
			//get media item links
			hiResLink = $(item).find('a span.hireslink').text();
			loResLink = $(item).find('a span.loreslink').text();
			if (hiResLink != "") {
				$('#mediacenter-download .links .hireslink a').attr('href', hiResLink);
				$('#mediacenter-download .links .hireslink a').text("Download High-Res Image");
				$('#mediacenter-download .links .hireslink').show();
			}
			if (loResLink != "") {
				$('#mediacenter-download .links .loreslink a').attr('href', loResLink);
				$('#mediacenter-download .links .loreslink a').text("Download Low-Res Image");
				$('#mediacenter-download .links .loreslink').show();
			}
		}
		else if (mediaType == "videos") {
			embedCode = $(item).find('a span.embedcode').text();
			
			hiResLink = $(item).find('a span.hireslink').text();
			loResLink = $(item).find('a span.loreslink').text();
				
			if (hiResLink != "") {
				$('#mediacenter-download .links .hireslink a').attr('href', hiResLink);
				$('#mediacenter-download .links .hireslink a').text("View High-Res Video");
				$('#mediacenter-download .links .hireslink').show();
			}
			if (loResLink != "") {
				$('#mediacenter-download .links .loreslink a').attr('href', loResLink);
				$('#mediacenter-download .links .loreslink a').text("View Low-Res Video");
				$('#mediacenter-download .links .loreslink').show();
			}
			
			if(embedCode != "") {
				$('#mediacenter-download .links #embed-code').text(embedCode);
				$('#mediacenter-download .links .embed').show();
			}
			
		}
		//static files, audio files or unsupported files
		else {
			//set download link
			var downloadLink = $(item).find('a').attr("href");
			$('#mediacenter-download .links .medialink a').attr('href', downloadLink);
			$('#mediacenter-download .links .medialink a').text('Download File');
			$('#mediacenter-download .links .medialink').show();
		}
	
	}
	window['UPS']['setMediaInfo'] = setMediaInfo;
	
	//load appropriate player depending on media type of first item in carousel
	var loadPlayer = function() {
		//first carousel item
		var item = $('#media-carousel .media-carousel-list:eq(0) ul li:eq(0)');
		var mediaType = $(item).attr('class');
		//get player path from DOM
		var playerPath = $('#media-player-path').text();	
		var filePath = $(item).find('a').attr('href');
		var title = $(item).find('a span.name').text();
		var desc = $(item).find('a span.description').text();
		//var category = $(item).find('a span.category').text();
		var category = $('#media-carousel-pulldown .current-topic').text();
		var pClass = $(item).find('a span.pClass').text();
		var sClass = $(item).find('a span.sClass').text();
		
		//Show image slider
		if (mediaType == "images") {
			setMediaPlayer('Image');
		}
		else if (mediaType == "videos") {
			setMediaPlayer('Video');
			
			var featuredExists = document.getElementById("FeaturedMediaSearchForm");
			
			if(featuredExists){
				setMedia(filePath, 'Video', title, desc, category, playerPath, 'true', pClass, sClass);
			}
			else{
				setMedia(filePath, 'Video', title, desc, category, playerPath, 'false', pClass, sClass);
			}
			//Make hi-res/lo-res video links play video
			var link1 = $('#mediacenter-download .links .hireslink a');
			var link2 = $('#mediacenter-download .links .loreslink a');
			var href1 = $('#mediacenter-download .links .hireslink a').attr("href");
			var href2 = $('#mediacenter-download .links .loreslink a').attr("href");
			linkMediaPlay(link1, 'Video', href1, title, desc, category, playerPath, undefined, pClass, sClass);
			linkMediaPlay(link2, 'Video', href2, title, desc, category, playerPath, undefined, pClass, sClass);
		}
		else if (mediaType == "audio") {
			setMediaPlayer('Audio');
			setMedia(filePath, 'Audio', title, desc, category, playerPath, 'false', pClass, sClass);
		}
		else {
			
			var stillImage = $(item).find('a span.stillimage').text();
			
			setMediaPlayer('SingleImage');
			setMedia(stillImage, 'Image', title, desc, category,undefined, undefined, pClass, sClass);
		}
	}
	window['UPS']['loadPlayer'] = loadPlayer;

	
	//function to switch to appropriate media player/image slider depending on carousel selections
	var mediaSwitch = function () {
	
		var carouselHeight = $('#media-carousel').height();
		
		var videoHeight = 387;
		
		//get player path from DOM
		var playerPath = $('#media-player-path').text();		
	
		//Switch to appropriate player depending on type of media clicked, set values in download links
		$('#media-carousel .media-carousel-list').each(function() {
		//$('.media-carousel-list').find('ul').each(function() {
			var index = $('#media-carousel .media-carousel-list').index(this);
			var fileName = "";
			var desc = "";
			var category = "";
			var hiResLink = "";
			var loResLink = "";
			var mediaLink = "";
			var permaLink = "";
			var embedCode = "";
			var stillImage = "";
		
			$(this).find('ul').each(function() {
								
				$(this).find('li a').click(function() {
								
					fileName = $(this).find('span.name').text();
					desc = $(this).find('span.description').text();
					//category = $(this).find('span.category').text();
					category = $('#media-carousel-pulldown .current-topic').text();
					permaLink = $(this).find('span.permalink').text();
					hiResLink = $(this).find('span.hireslink').text();
					loResLink = $(this).find('span.loreslink').text();
					mediaLink = $(this).find('span.medialink').text();
					embedCode = $(this).find('span.embedcode').text();
					stillImage = $(this).find('span.stillimage').text();
					var pClass = $(this).find('span.pClass').text();
					var sClass = $(this).find('span.sClass').text();
					
													
					if ($(this).parent().is('li.videos')) {
											
						setMediaPlayer('Video');
						
						setMedia(this.href, 'Video',  fileName, desc, category, playerPath, undefined, pClass, sClass);

						setMediaLinks('video', permaLink, hiResLink, loResLink, mediaLink, embedCode);

						//Make hi-res/lo-res video links play video
						var link1 = $('#mediacenter-download .links .hireslink a');
						var link2 = $('#mediacenter-download .links .loreslink a');
						linkMediaPlay(link1, 'Video', hiResLink, fileName, desc, category, playerPath, undefined, pClass, sClass);
						linkMediaPlay(link2, 'Video', loResLink, fileName, desc, category, playerPath, undefined, pClass, sClass);
						
					}
					
					else if ($(this).parent().is('li.audio')) {
						
						setMediaPlayer('Audio');
						setMedia(this.href, 'Audio', fileName, desc, category, playerPath, undefined, pClass, sClass);
						setMediaLinks('audio', permaLink, hiResLink, loResLink, mediaLink, embedCode);
					}
					
					else if ($(this).parent().is('li.images')) {
						
						setMediaPlayer('Image');
						
						setMediaLinks('image', permaLink, hiResLink, loResLink, mediaLink, embedCode);
						
						var imageIndex = $('#media-carousel .media-carousel-list:eq(' + index +') ul li.images').index($(this).parent());
						// since set media is not called directly here, we call tracking directly
						// Track this image....
						UPS.trackMedia(this.href,
								fileName,
								pClass,
								sClass);
 						
						//set index of image in image viewer
						UPS.setImageIndex(imageIndex);
						
						//set file title, category and description
						if (category != "") {
							$('#media-player-top h1 span.category').text(category + ' > ');
						}
						else {
							$('#media-player-top h1 span.category').text('');
						}
						$('#media-player-top h1 span.title').text(fileName);
						$('#media-player-top p').text(desc);
					}
				
					else {
						setMediaPlayer('SingleImage');
						setMedia(stillImage, 'Image', fileName, desc, category, undefined, undefined, pClass, sClass);
						
						var downloadLink = $(this).attr("href");
						
						setMediaLinks('', permaLink, hiResLink, loResLink, downloadLink, embedCode);
						//Open link in new window and let browser handle download/display from there
						UPS.openWindow(this.href, '633', '400');
					}
					
					resetHeight();
					UPS.layout();
					
					var retVal = false;
					
					return retVal;
					
				});
															   
			 }); //end each ul
		});
				
	}
	window['UPS']['mediaSwitch'] = mediaSwitch;
	
	//Switches between image, audio and video player
	var setMediaPlayer = function(playerType) {
		
		var carouselHeight = $('#media-carousel').height();
		
		//set image as default if no type is specified
		if(!playerType) {
			playerType = 'Image';	
		}
		
		if (playerType == 'Image') {
			
			if ($('#media-image-slider').is(':hidden')) {
		
					$('#media-image-slider').show();
					$('#single-image-view').hide();
					$('#media-player-container').hide();
			}
		}
		
		else if (playerType == 'SingleImage') {
			
			if($('#single-image-view').is(':hidden')) {
				
				$('#single-image-view').show();
				$('#media-image-slider').hide();
				$('#media-player-container').hide();
			
			}
		}
		
		else if (playerType == 'Video') {
			
			if ($('#media-player-container').is(':hidden')) {
				
				$('#media-player-container').show();
				$('#media-image-slider').hide();
				$('#single-image-view').hide();
				
				/*var videoHeight = 387;
				resetHeight(videoHeight);*/
				
			}
			
			if ($('#media-player-container').hasClass('audio')) {
				$('#media-player-container').removeClass('audio');
				$('#media-player-container').addClass('video');
				//change height of carousel back to original 
				//$('#media-carousel').height(carouselHeight);
			}

		}
		
		else if (playerType == 'Audio') {
		
			if ($('#media-player-container').is(':hidden')) {
				$('#media-player-container').show();
				$('#media-image-slider').hide();
				$('#single-image-view').hide();
			}
			
			if($('#media-player-container').hasClass('video') || $('#media-player-container').is(':hidden')) {
						
				$('#media-player-container').removeClass('video');
				$('#media-player-container').addClass('audio');
				
				//resize bottom portlets to even layout on the bottom when media player becomes shorter
				/*$('.layout-bottom').each(function() {
					$(this).height("auto");
				});*/
				//UPS.layout();
				//resetHeight();
			}
		}
		
		else if (playerType == 'none') {
			$('#media-player-container').hide();
			$('#media-image-slider').hide();
			$('#single-image-view').hide();
		}
	}
	window['UPS']['setMediaPlayer'] = setMediaPlayer;

	var resetHeight = function(playerHeight) {
		//reset all heights
		$('.layout-bottom').each(function() {
			$(this).height("auto");
		});

	}
	window['UPS']['resetHeight'] = resetHeight;
	
	
	//Function that sends media object data to the media player 
	var setMedia = function(filePath, fileType, fileName, fileDesc, category, playerPath, autoPlay, pClass, sClass) {
	
		if (!autoPlay) {
			autoPlay = true;
		}
		
		// This code block IGNORES page defaults. comment to start using defaults instead of blanks.
		if (!pClass) {
			pClass = "";
			sClass = "";
		} else if (!sClass) {
			sClass = "";
		}

		// track media here.
		UPS.trackMedia(filePath,fileName,pClass, sClass);
		//set title, category and description 
		if (category != "") {
			$('#media-player-top h1 span.category').text(category + " > ");
		}

		$('#media-player-top h1 span.title').text(fileName);
		$('#media-player-top p').text(fileDesc);
		
		if (fileType == "Image") {
			
			UPS.setMediaPlayer('SingleImage');
			
			//show default image if none is passed
			if (filePath == "") {
				$('#single-image-view .image-container').html("");
				$("#single-image-view .default-image").show();
			}
			else {
				$("#single-image-view .default-image").hide();
				$('#single-image-view .image-container').html($('<img src="' + filePath + '" alt="' + fileName + '" />'));	
			}
		}
		else if (fileType == "Video") {
			
			UPS.setMediaPlayer('Video');
			UPS.mediaPlayer(playerPath, filePath, 'video', autoPlay);		
		}
		else if (fileType == 'Audio') {
		
			UPS.setMediaPlayer('Audio');
			UPS.mediaPlayer(playerPath, filePath, 'audio', autoPlay);
		}
	}
	window['UPS']['setMedia'] = setMedia;
	
	function generateMediaTracker () {
		var safeUri = location.href;
		var mediaTracked = false; // set to true on first call to tracker
		var safePClass = ""; // dont need safe values. dcsAdv will regen
		var safeSClass = ""; // dont need safe values. dcsAdv will regen

		// trackUri = filePath;
		// title = fileName;
		// pClass, sClass =  classifications (optional in that order). Rules are:
		//     if you give me a pClass that is not false, you forfiet defaults for pClass and sClass
		//     if you give me only an sClass, I use default pClass (should never happen tho)
		//     if you give me nothing, I use page defaults. you want to fail page defaults? call trackMedia(x,x,"","")
		return function (trackUri, title, pClass, sClass) {
			// Track activity
			if (typeof(dcsVar)=="function") {
				if (typeof(DCS.dcsuri)!="undefined") {
					// following will have global impact. Things change here!
					dcsVar();
					dcsMeta();
					dcsFunc("dcsAdv");
					DCS.dcsref = safeUri;
					DCS.dcsuri = trackUri;
					WT.ti = title;
					if (pClass) {
						WT["cg_n"] = pClass;
						if (sClass) {
							WT["cg.s"] = sClass;
						} else {
							WT["cg.s"] = "";
						}
					}
					dcsTag();
					safeUri = trackUri; // our referer just became this image/movie/audio
				}
			}
		};		
	};
	window['UPS']['trackMedia'] = generateMediaTracker();
	
	
	//sets links in media download links portlet
	var setMediaLinks = function(linkType, permaLink, hiResLink, loResLink, mediaLink, embedCode) {
		
		if (linkType == "image") {
			//Hide 'Download Video' link and embed code
			$('#mediacenter-download p.medialink').hide();
			$('#mediacenter-download p.embed').hide();
			$('#mediacenter-download p#embed-code').hide();
			
			//Set value for low res link, show it if it has a value
			if (loResLink != "") {
				$('#mediacenter-download p.loreslink a').attr('href', loResLink);
				$('#mediacenter-download p.loreslink a').text('Download Low-Res Image');
				$('#mediacenter-download p.loreslink').show();
			}
			else {
				$('#mediacenter-download p.loreslink').hide();
			}
			
			//Set value for hi res link, show it if it has a value
			if (hiResLink != "") {
				$('#mediacenter-download p.hireslink a').attr('href', hiResLink);
				$('#mediacenter-download p.hireslink a').text('Download High-Res Image');
				$('#mediacenter-download p.hireslink').show();
			}
			else {
				$('#mediacenter-download p.hireslink').hide();
			}
			
		}
		else {
			
			//set and show media link
			$('#mediacenter-download p.medialink a').attr('href', mediaLink);
			
			if (linkType == "video") {
				
				//Set value for low res link, show it if it has a value
				if (loResLink != "") {
					$('#mediacenter-download p.loreslink a').attr('href', loResLink);
					$('#mediacenter-download p.loreslink a').text('View Low-Res Video');
					$('#mediacenter-download p.loreslink').show();
				}
				else {
					$('#mediacenter-download p.loreslink').hide();
				}
				//Set value for hi res link, show it if it has a value
				if (hiResLink != "") {
					$('#mediacenter-download p.hireslink a').attr('href', hiResLink);
					$('#mediacenter-download p.hireslink a').text('View High-Res Video');
					$('#mediacenter-download p.hireslink').show();
				}
				else {
					$('#mediacenter-download p.hireslink').hide();
				}
				
				//$('#mediacenter-download p.medialink a').text('Download Video');
			}
			else if (linkType == "audio") {
				//Hide low res and hi res links
				$('#mediacenter-download p.loreslink, #mediacenter-download p.hireslink').hide();
				
				//Show download link
				$('#mediacenter-download p.medialink a').attr('href', mediaLink);
				$('#mediacenter-download p.medialink a').text('Download Audio File');
				$('#mediacenter-download p.medialink').show();
			}
			else {
				$('#mediacenter-download p.medialink a').text('Download File');
				$('#mediacenter-download p.medialink').show();
			}
			
			//set and show embed code
			if (embedCode != "" && embedCode != null) {
				$('#mediacenter-download p#embed-code').text(embedCode);
				$('#mediacenter-download p.embed').show();
			}
			else {
				$('#mediacenter-download p#embed-code').hide();
				$('#mediacenter-download p.embed').hide();
			}
			
		}
		
		//set permalink
		$('#mediacenter-download p.permalink a').attr('href', permaLink);
		$('#mediacenter-download p.permalink a').text(permaLink);
		
	}
	window['UPS']['setMediaLinks'] = setMediaLinks;
	
	
	//activates media player with swfoject. Takes 2 parameters: the url of the media file and the file type. The type can be either 'audio' or 'video'.
	//This function is called directly on the Media Center Page
	 var mediaPlayer = function (playerPath, fileUrl, fileType, start) {
		 
		 if (!playerPath) {
			playerPath  = 'flash/player.swf';
		 }
		
		if (!fileUrl) {
			fileUrl = "";	
		}
		
		if (!fileType) {
			fileType = 'video';	
		}
		
		if (!start) {
			start = 'false';	
		}
		
		var playerHeight = '367'; //default height for video player
		
	
		if (fileType == 'audio') {
			playerHeight = '20'; //default height for audio player	
		}
		
		var expressInstallUrl = 'http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75';
		
		var flashvars = {
			
			file: fileUrl,
			autostart: start
		};
		
		var params = {
			wmode: 'transparent',
			allowscriptaccess: 'always'
		};
		
		var attributes = {};
		
		swfobject.embedSWF(playerPath, 'video-preview', '436', playerHeight , '9.0.0', expressInstallUrl, flashvars, params, attributes);
				
	}
	window['UPS']['mediaPlayer'] = mediaPlayer;
	
	//Function to activate functionality of "embed" code snippet on video links
	var videoLinkEmbed = function (){
	
		$('#embed-trigger').click(function() {
				$(this).toggleClass('on');
				$('#embed-code').slideToggle('normal');
			
				return false;
		 	});

	}
	window['UPS']['videoLinkEmbed'] = videoLinkEmbed;
	
	//Function that is only used on media display page for static files
	var staticFileDisplay = function(stillImagePath, filePath, fileName, desc, permalink, setLinks, pClass, sClass) {
		
		if (!setLinks) {
			setMediaLinks('', permalink, '', '', filePath, undefined, undefined, pClass, sClass);
		}
		
		setMediaPlayer('SingleImage');
		setMedia(stillImagePath, 'Image', fileName, desc, '', undefined, undefined, pClass, sClass);
		//open pop-up with file
	//	UPS.openWindow(filePath, '633', '400');
		
	}
	window['UPS']['staticFileDisplay'] = staticFileDisplay;	 
	
	//function that plays video/audio given a link
	var linkMediaPlay = function(link, playerType, href, fileName, desc, category, playerPath, pClass, sClass) {
		
		$(link).click(function() {
			setMediaPlayer(playerType);
			setMedia(href, playerType, fileName, desc, category, playerPath, undefined, pClass, sClass);
			return false;
		});
	}
	window['UPS']['linkMediaPlay'] = linkMediaPlay;
	
	//for image lists, fills in the index of the current carousel item in a div so that the image slider knows which is the current image
	var setImageIndex = function(index) {
		$('#imageIndex').text(index);
	}
	window['UPS']['setImageIndex'] = setImageIndex;	
	
	var setMediaByDateOrder = function(){
		
		function StringBuffer() { 
			this.buffer = []; 
		} 

		StringBuffer.prototype.append = function append(string) { 
		   this.buffer.push(string); 
		   return this; 
		}; 

		StringBuffer.prototype.toString = function toString() { 
		  return this.buffer.join(""); 
		};
		
		var dropdownList = new StringBuffer();
		
		dropdownList.append('<li><a class="this week" href="#" style="background-image: none;">This Week</a></li>');
		dropdownList.append('<li><a class="past two weeks" href="#">Past Two Weeks</a></li>');
		dropdownList.append('<li><a class="past four weeks" href="#">Past Four Weeks</a></li>');
		dropdownList.append('<li><a class="past six weeks" href="#">Past Six Weeks</a></li>');
		dropdownList.append('<li><a class="past eight weeks" href="#">Past Eight Weeks</a></li>');
		dropdownList.append('<li><a class="past three months" href="#">Past Three Months</a></li>');
		dropdownList.append('<li><a class="past four months" href="#">Past Four Months</a></li>');
		dropdownList.append('<li><a class="past six months" href="#">Past Six Months</a></li>');
		dropdownList.append('<li><a class="archive" href="#">Archive</a></li>');
		
		$('#media-carousel-pulldown ul.pulldown-list').html(dropdownList.toString());
		
		var lists = new Array();
		
		$("#media-carousel div.media-carousel-list").each(function(i){
			$("#media-carousel div.media-carousel-list").each(function(j){
				switch(i){
				case 0:
					if(j==8){
						lists[i] = $(this).html();
					}
					break;
				case 1:
					if(j==4){
						lists[i] = $(this).html();
					}
					break;
				case 2:
					if(j==1){
						lists[i] = $(this).html();
					}
					break;
				case 3:
					if(j==2){
						lists[i] = $(this).html();
					}
					break;
				case 4:
					if(j==7){
						lists[i] = $(this).html();
					}
					break;
				case 5:
					if(j==6){
						lists[i] = $(this).html();
					}
					break;
				case 6:
					if(j==0){
						lists[i] = $(this).html();
					}
					break;
				case 7:
					if(j==5){
						lists[i] = $(this).html();
					}
					break;
				case 8:
					if(j==3){
						lists[i] = $(this).html();
					}
					break;
				}
			});
		});
		
		$("#media-carousel div.media-carousel-list").each(function(k){
			$(this).html(lists[k]);
		});
	}
	window['UPS']['setMediaByDateOrder'] = setMediaByDateOrder;

})();
		
$(window).load(function() {
	$("#image-carousel div.carousel-container ul li img").each(function(i){
		
		var imageHeight = this.height;
		var imageWidth = this.width;
		
		var marginLeft = (403 - imageWidth) / 2;
		var marginTop = (291 - imageHeight) / 2;
		 
		$(this).css('margin-top', marginTop + 'px');
		$(this).css('margin-left', marginLeft + 'px');
	
	});
});
		
$(document).ready(function(){
	
	if(UPS.exists('media-carousel') && UPS.exists('media-image-slider')) {
		
		//Load image carousel 
		$('#media-carousel .media-carousel-list ul.image').each(function() {
			var index = $('#media-carousel .media-carousel-list ul').index(this);
			UPS.imageCarousel(index);
			//activate on-click function for media carousel topics: re-creates image slider when image topic is clicked
			UPS.imageCarouselSwitch(index);
			//activate on-click functions of carousel arrows
			UPS.imageCarouselArrows(index);
		});
	}
	
	//if page is media center, activate media carousel/media player interaction
	if(UPS.exists('media-carousel') && UPS.exists('media-player-container')) {
		UPS.mediaSwitch();	
	}
			
	//activate video embed code display
	if (UPS.exists('mediacenter-download')) {
		UPS.videoLinkEmbed();
	}
	
	//If page is Media Center landing, load title and description of first media carousel item into media player, and load media download links
	if(UPS.exists('media-getter')) {
	}
	else {
		UPS.setMediaInfo();
		UPS.loadPlayer();
	}
	
	if(UPS.exists('media-carousel-pulldown') && $('#breadcrumb ul li.active').html().indexOf('Media by Date') > -1){
		UPS.setMediaByDateOrder();
	}
	
	UPS.layout();
	
});


