
var pageAssetName = ''; // the name of the asset, e.g. Majorca
var mmShowcaseObj = new Object(); // the object used to store the mm showcase content

// set up a variable for detecting if photo opacity is already changing
var photoOpacChanging = false;
var switchPhotoOpac = null;

// create object to store selected photo and set initially selected photo
var selectedMMPhotoID = new Object();
selectedMMPhotoID.id = 'mmShow_photos_full_0';

var fadeOutObj = new Object();
var fadeInObj = new Object();

//if the 'altGallery' variable is defined (externally to script) set the scroll rate to 2, else 6
if ( typeof( window[ 'altGallery' ] ) != "undefined" ) {	//The alternative gallery is used on the cruise > ships section
	var scrollRate = 2;
	var photoThumbPixels = 68;
}
else {
    var scrollRate = 6;			//used on destinations gallery
 	var photoThumbPixels = 54;
}

//var openExtrasElems = new Array(); // embed this array of extras id attributes into a page to have them default to open


	function styleMediaLink(mediaNamesArray,mediaType) {
		for(var i=0; i < mediaNamesArray.length; i++) {
			if(document.getElementById('p_mmShowcase_menu_'+mediaNamesArray[i])) {
				//document.getElementById('p_mmShowcase_menu_'+mediaNamesArray[i]).getElementsByTagName('a')[0].style.fontWeight = (mediaNamesArray[i] != mediaType ? 'normal' : 'bold');
				document.getElementById('p_mmShowcase_menu_'+mediaNamesArray[i]).getElementsByTagName('a')[0].style.textDecoration = (mediaNamesArray[i] != mediaType ? 'underline' : 'none');
				document.getElementById('p_mmShowcase_menu_'+mediaNamesArray[i]).getElementsByTagName('a')[0].style.color = (mediaNamesArray[i] != mediaType ? '#3250be' : '#000');
			}
		}
	}


	function resetMediaModules(mediaType, inlineMedia, mediaNamesArray) {
		for(var i=0; i < inlineMedia.length; i++) {
			if(inlineMedia[i] != mediaType) {
				if(document.getElementById('mmShow_'+inlineMedia[i]+'_container')) {
					document.getElementById('mmShow_'+inlineMedia[i]+'_container').style.display = 'none';
					// clear video to stop playback
					if(inlineMedia[i] == 'video') { document.getElementById('mmShow_video_container').innerHTML = ''; }
					// unload gmap resources to free up memory
					if(inlineMedia[i] == 'gmap' && isVarDefined('gMapsIncluded')) { GUnload(); }
				}
			}
		}
	}



	function goToMediaModule(mediaType) {
		// mediaNamesArray is an array of all the media object names
		var mediaNamesArray = new Array('photos', 'video');
		// inlineMedia is an array of the elements which need to show/hide (i.e. not open externally to the page)
		var inlineMedia = new Array('photos', 'video');

		switch(mediaType) {
			case 'video':
				resetMediaModules(mediaType, inlineMedia, mediaNamesArray);
				styleMediaLink(mediaNamesArray,mediaType);

				document.getElementById('mmShow_video_container').style.display = 'block';
				var outputVideo = '<div class="mm_video_container">'+(mmShowcaseObj.videos.length>1?'<a id="vivBanner" href="'+mmShowcaseObj.videos[1].href+'" onclick="popVividas(this);return false;"><img src="/images/videos/banner-vividas.jpg" /></a>':'')+'<object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="538" height="410">'
					+ '<param name="URL" value="' + mmShowcaseObj.videos[0].href + '">' + '<param name="autoStart" value="true">' + '<param name="uimode" value="mini">'
					+ '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="538" height="410" src="' + mmShowcaseObj.videos[0].href + '" showcontrols="1" autostart="1">'
				+ '</object></div>';

				// vividas change
				document.getElementById('mmShow_video_container').innerHTML = outputVideo + '<div id="mmShow_video_container_sideNav">'+(mmShowcaseObj.videos[1]?'<div class="p_mmShowcase_video_icon" id="mm_vid_viv"><a href="' + mmShowcaseObj.videos[1].href + '" onclick="popVividas(this);return false;">High quality, full-screen version</a></div>':'')+'<div class="p_mmShowcase_video_icon" id="mm_vid_ext"><a href="' + mmShowcaseObj.videos[0].href + '">Play video in external player</a></div><div class="p_mmShowcase_video_icon" id="mm_vid_all"><a href="/destinations/videos/videos.html">View our full range of videos</a></div></div>';
				//document.getElementById('mmShow_video_container').innerHTML = outputVideo + '<p><a href="' + mmShowcaseObj.videos[0].href + '">Play video in external player</a></p><p><a href="/destinations/videos/videos.html">View our full range of videos</a></p>';

				//Omniture VS tag//
				if(typeof _MT!="undefined")_MT.MT();
				//alert("Video1");

			break;
			case 'photos':

				resetMediaModules(mediaType, inlineMedia, mediaNamesArray)
				styleMediaLink(mediaNamesArray,mediaType);

				document.getElementById('mmShow_photos_container').style.display = 'block';

			break;
		}

		return false;

   }



	function buildMediaModuleVideo() {
		mmShowcaseObj.videos = document.getElementById('p_mmShow_video').getElementsByTagName('a');
		if(mmShowcaseObj.videos.length > 0) {
			mmShowcaseObj.outputHTML_sidebar += '<div id="p_mmShowcase_menu_video" class="showcaseVideoMenu" onclick="changeMenuClass(this); return goToMediaModule(\'video\');"><a href="#">Video</a></div>';
			mmShowcaseObj.outputHTML_modules += '<div id="mmShow_video_container">&nbsp;</div>';
		}
	}



	function buildMediaModule360Tours() {

		var newOutputHTML = '';

		mmShowcaseObj.tours = document.getElementById('p_mmShow_360tour').getElementsByTagName('a');

		if(mmShowcaseObj.tours.length > 0) {

			//NewLayout
			if (document.getElementById('localInfo-d'))
	            {

					newOutputHTML += '<div id="locationBox360" onclick="return openSelfNewWindow(\'' + mmShowcaseObj.tours[0] + '\', \'\', \'resizable=yes,toolbar=no,width=800,height=580\');"><a href="#">See our 360 resort tour</a></div>';
		       		document.getElementById('p_mmShow_360tourAlt').style.display = 'block';
		       		document.getElementById('p_mmShow_360tourAlt').innerHTML = newOutputHTML;

	            }

	       // Default

	       else
				{
					mmShowcaseObj.outputHTML_sidebar += '<div id="p_mmShowcase_menu_360tour" onclick="return openSelfNewWindow(\'' + mmShowcaseObj.tours[0] + '\', \'\', \'resizable=yes,toolbar=no,width=800,height=580\');"><a href="#">360 tour</a></div>';
				}

		}
	}





/* ###################################################################### *\
	Function: buildMediaModule
	Build the multimedia module from the distinct elements
\* ###################################################################### */

	function buildMediaModule(locLevel, themeType) {


		mmShowcaseObj.outputHTML = '';
		mmShowcaseObj.outputHTML_title = '';
		mmShowcaseObj.outputHTML_sidebar = '';
		mmShowcaseObj.outputHTML_modules = '';


		// build to locLevel spec
		switch (locLevel) {
			case 'unit':

				if(document.getElementById('p_mmShow_photos') ||
				document.getElementById('p_mmShow_video') ||
				document.getElementById('p_mmShow_360tour')) { // check that at least one of the required sections is present
					mmShowcaseObj.outputHTML_title = '<h2>' + pageAssetName + ' multimedia showcase</h2></div><div class="p_clearBoth_h10">&#160;</div>';
					if(document.getElementById('p_mmShow_photos')) { buildMediaModulePhotos(); }
					if(document.getElementById('p_mmShow_video')) { buildMediaModuleVideo(); }
					if(document.getElementById('p_mmShow_360tour')) { buildMediaModule360Tours(); }

				} else {
					if(document.getElementById('p_mmShowcase')) { document.getElementById('p_mmShowcase').parentNode.removeChild(document.getElementById('p_mmShowcase')); }
				}

			break;
		}



		// build the media showcase modules
		if(mmShowcaseObj.outputHTML_title && (mmShowcaseObj.outputHTML_title != '')) {
			mmShowcaseObj.outputHTML = mmShowcaseObj.outputHTML_title
			+ '<div id="p_mmShowcase_menu">'
			+ mmShowcaseObj.outputHTML_sidebar
			+ '</div><div id="p_mmShowcase_content">'
			+ mmShowcaseObj.outputHTML_modules
			+ '</div><div class="p_clearBoth_h30">&#160;</div>';

		}

		if(mmShowcaseObj.outputHTML && (mmShowcaseObj.outputHTML != '')) {
			if(document.getElementById('p_mmShowcase')) { document.getElementById('p_mmShowcase').innerHTML = mmShowcaseObj.outputHTML; }
		}


		// initiate image slideshow functionality
		if(mmShowcaseObj.photoModule) {
			for(var i=1; i < mmShowcaseObj.mediaPhotoObj.numImgs; i++) {
				if(document.getElementById('mmShow_photos_full_' + i)) {
					if(i > 0) {
						alterBorderColor('mmShow_photos_thumb_' + i, false);
						//alterOpacity('mmShow_photos_thumb_' + i, 40);
					}
					document.getElementById('mmShow_photos_full_' + i).style.display = 'none';
				}
			}
			mmThumbInitScroll();
		}

		if(document.getElementById('mmShow_photos_container')) {
			goToMediaModule('photos');
		} else if(document.getElementById('mmShow_video_container')) {
			goToMediaModule('video');
		}

	}


			/* ###################################################################### *\
				Function: isVarDefined
				Check if a variable has been defined
			\* ###################################################################### */

			function isVarDefined(checkVar) {
				return eval('(typeof('+checkVar+') != "undefined");');
			}


			/* ###################################################################### *\
				Function: alterOpacity
				Set an element's opacity to the input amount (as a percentage where
				100 is fully opaque and 0 fully transparent)
			\* ###################################################################### */

			function alterOpacity(elemID, transAmount) {
				var transObj = document.getElementById(elemID).style;
				transObj.opacity = (transAmount / 100);
				transObj.MozOpacity = (transAmount / 100);
				transObj.KhtmlOpacity = (transAmount / 100);
				transObj.filter = "alpha(opacity=" + transAmount + ")";
			}



	/* ###################################################################### *\
	   Function: alterBorderColor
	   Changes an elements border color to #ccc
	\* ###################################################################### */

        function alterBorderColor (elemID, selected) {
           var transObj = document.getElementById(elemID).style;
			if (selected) { transObj.borderColor = "#3250be"; }
			else { transObj.borderColor = "#ccc"; }
        }




	function buildMediaModulePhotos() {
		var linkContainer = document.getElementById('p_mmShow_photos');
		var linkTags = linkContainer.getElementsByTagName('a');
		if(linkTags.length > 0) {
			mmShowcaseObj.photoModule = true;

			mmShowcaseObj.mediaPhotoObj = new Object();

			for(var i=0; i < linkTags.length; i++) {
				mmShowcaseObj.mediaPhotoObj[i] = new Image();
				//mmShowcaseObj.mediaPhotoObj[i].src = linkTags[i].href;

				mmShowcaseObj.mediaPhotoObj[i].src = (i==0 ? linkTags[i].href : '/images/assets/trans-spacer.gif');
				mmShowcaseObj.mediaPhotoObj[i].fullSrc = linkTags[i].href;

				imgJpgToGif = null;
				imgJpgToGif = linkTags[i].href.split('.jpg')[0] + '.gif';

				if(imgJpgToGif.split('lpp')[0] && (imgJpgToGif.split('lpp')[0] != '') && imgJpgToGif.split('lpp')[1] && (imgJpgToGif.split('lpp')[0] != '')) {
					mmShowcaseObj.mediaPhotoObj[i].thumbSrc = imgJpgToGif.split('lpp')[0] + 'lps' + imgJpgToGif.split('lpp')[1];
				} else {
					mmShowcaseObj.mediaPhotoObj[i].thumbSrc = linkTags[i].href;
				}

				mmShowcaseObj.mediaPhotoObj[i].loaded = false;
				mmShowcaseObj.mediaPhotoObj[i].alt = linkTags[i].title;
				mmShowcaseObj.mediaPhotoObj[i].title = linkTags[i].title;
				mmShowcaseObj.mediaPhotoObj.numImgs = (i+1);
			}

			mmShowcaseObj.outputHTML_sidebar += '<div id="p_mmShowcase_menu_photos" class="showcasePhotosMenuActive" onclick="changeMenuClass(this); return goToMediaModule(\'photos\');"><a href="#">Photos (' + mmShowcaseObj.mediaPhotoObj.numImgs + ')</a></div>';

			var thumbsHTML = createMediaPhotosThumbs();
			var imageHTML  = createMediaPhotosFull();

			//variables used when building HTML output below
			var pauseSlideshowText = 'Pause Slideshow';
	   		var playSlideshowText  = 'Play Slideshow';
	   		var pauseSlideshowImg  = 'menu-icon-pause.gif';
	   		var playSlideshowImg   = 'menu-icon-play.gif';

	   		altGalleryHTML = '';
	   		//if the 'altGallery' variable is defined
			if ( typeof( window[ 'altGallery' ] ) != "undefined" ) {
				pauseSlideshowText += '<br /> (' + linkTags.length + ' Photos)';
				playSlideshowText  += '<br /> (' + linkTags.length + ' Photos)';
				pauseSlideshowImg  = 'altMenuPauseIcon.jpg';
				playSlideshowImg   = 'altMenuPlayIcon.jpg';
			}

			mmShowcaseObj.outputHTML_modules += '<div id="mmShow_photos_container"><div id="mmShow_photos_full"><div id="mmShow_photos_full_img"><div id="mmShow_photos_full_brdr"><span>&#160;</span></div>'
			+ imageHTML
			+ '</div>'
			+ '<p id="mmShow_photos_caption">' + mmShowcaseObj.mediaPhotoObj[0].title + '</p>'
			+ '</div><div id="mmShow_photos_thumb">'
			+ '<div id="mmShow_photos_full_menu">'
			+ '<div id="mmShow_photos_pause"><img src="/images/media/' + pauseSlideshowImg + '" title="Pause" alt="Pause"/><span>' + pauseSlideshowText + '</span></div>'
			+ '<div id="mmShow_photos_play"><img src="/images/media/' + playSlideshowImg + '" title="Play" alt="Play"/><span>' + playSlideshowText + '</span></div></div>'
			+ '<div class="p_clearBoth"></div>'
			+ thumbsHTML
			+ altGalleryHTML
			+ '</div></div>';

		}

	}


	function checkImg(elemID) {
		var elemNum = parseInt(elemID.split('mmShow_photos_thumb_')[1]);
		if(!mmShowcaseObj.mediaPhotoObj[elemNum].loaded) {

			var loadingIcon = '<img style="display: inline; padding-right: 10px; margin-bottom: -5px;" src="/images/media/loadingIcon.gif" alt="" />';

			mmShowcaseObj.mediaPhotoObj[elemNum].loaded = true;
			document.getElementById('mmShow_photos_src_'+elemNum).src = mmShowcaseObj.mediaPhotoObj[elemNum].fullSrc;
			document.getElementById('mmShow_photos_src_'+elemNum).onload = function() { loadImg(elemID); }
			document.getElementById('mmShow_photos_src_'+elemNum).onerror = function() { fullPhotoLoadError(elemID); }
			document.getElementById('mmShow_photos_caption').innerHTML = loadingIcon + 'Loading image, please wait...';

		} else { callSwitchPhotoOpacity(elemID); }
	}


	function fullPhotoLoadError(elemID) {
		var elemNum = elemID.split('mmShow_photos_thumb_')[1];
		mmShowcaseObj.mediaPhotoObj[elemNum].fullSrc = '/images/assets/mm-error-full.gif';
		document.getElementById('mmShow_photos_src_'+elemNum).src = mmShowcaseObj.mediaPhotoObj[elemNum].fullSrc;
		document.getElementById('mmShow_photos_src_'+elemNum).onload = function() { loadImg(elemID); }
	}



	function loadImg(elemID) {
		callSwitchPhotoOpacity(elemID);
	}


	function mmLoadErrorThumb(elem) {
		elem.src = '/images/assets/mm-error-thumb.gif';
	}


	function createMediaPhotosThumbs() {
		var outputHTML = '';
		var inc = 0;
		outputHTML += '<div id="mmShow_photo_thumb_up"><span>&#160;</span></div>';
		outputHTML += '<div id="mmShow_photo_thumb_outer">';
		outputHTML += '<div id="mmShow_photo_thumb_inner">';
		while(mmShowcaseObj.mediaPhotoObj[inc]) {

			//mmShowcaseObj.mediaPhotoObj[inc].src
			//outputHTML += '<div id="mmShow_photos_thumb_' + inc + '" class="mmShow_photos_thumb_img" onclick="callSwitchPhotoOpacity(this.id);"><img src="' + mmShowcaseObj.mediaPhotoObj[inc].thumbSrc + '" alt="' + mmShowcaseObj.mediaPhotoObj[inc].alt + '" title="' + mmShowcaseObj.mediaPhotoObj[inc].title + '" /></div>';
			outputHTML += '<div id="mmShow_photos_thumb_' + inc + '" class="mmShow_photos_thumb_img" onclick="checkImg(this.id);"><img src="' + mmShowcaseObj.mediaPhotoObj[inc].thumbSrc + '" onerror="mmLoadErrorThumb(this);" alt="' + mmShowcaseObj.mediaPhotoObj[inc].alt + '" title="' + mmShowcaseObj.mediaPhotoObj[inc].title + '" /></div>';
			inc += 1;
		}

		outputHTML += '<div class="p_clearBoth"></div>';
		outputHTML += '</div></div>';
		outputHTML += '<div id="mmShow_photo_thumb_down"><span>&#160;</span></div>';
		//outputHTML += '<p>test</p>';



		//outputHTML += '<p class="mmShow_flickr_link" onclick="urchinTracker(\'/urchin-ga/mmshowcase/menu-icons/flickr\'); if (confirm(\'You are now leaving the Thomson Holidays website at  and we are not responsible for the accuracy or suitability of the content of the external sites that you are entering.\')) return openSelfNewWindow(\'/flickr/flickr-images.html?locName=' + document.getElementById('p_assetName').innerHTML + '\', \'\', \'resizable=yes,toolbar=no,width=600,height=800\');"><img src="/images/assets/your-photos.gif" alt=""/> <a href="#" title="Thomson Holidays is not responsible for the content of external sites.">Your photos</a></p>';

		if(document.getElementById('p_assetCode') && (document.getElementById('p_assetCode').className == 'p_assetUnit')) {} else {

			outputHTML += '<div class="mmShow_flickr_link" onclick="urchinTracker(\'/urchin-ga/mmshowcase/menu-icons/flickr\'); if (confirm(\'You are now leaving the Thomson Holidays website at  and we are not responsible for the accuracy or suitability of the content of the external sites that you are entering.\')) return openSelfNewWindow(\'/flickr/flickr-images.html?locName=' + document.getElementById('p_assetName').innerHTML + '\', \'\', \'resizable=yes,toolbar=no,width=600,height=800\');" title="Thomson Holidays is not responsible for the content of external sites."><img src="/images/assets/flicker-button.gif" alt=""/></div>';

		}

		if(outputHTML) { return outputHTML; }
	}



	function createMediaPhotosFull() {
		var outputHTML = '';
		var inc = 0;
		var maxWidth = 410;
		var maxHeight = 410;
		while(mmShowcaseObj.mediaPhotoObj[inc]) {
			var sizesXY = resizeImageThumbs(maxWidth, maxHeight, mmShowcaseObj.mediaPhotoObj[inc].width, mmShowcaseObj.mediaPhotoObj[inc].height);
			sizesXY.xOffSet = (!sizesXY.xOffSet ? '0' : sizesXY.xOffSet);
			sizesXY.yOffSet = (!sizesXY.yOffSet ? '0' : sizesXY.yOffSet);

			outputHTML += '<div id="mmShow_photos_full_' + inc + '" class="mmShow_photos_full_img"><div class="mmShow_photos_centre"><table><tr><td align="center">';
			outputHTML += '<img id="mmShow_photos_src_' + inc + '" src="' + mmShowcaseObj.mediaPhotoObj[inc].src + '" />';
			outputHTML += '</td></tr></table></div></div>';
			inc += 1;
		}
		if(outputHTML) { return outputHTML; }
	}




	function callSwitchPhotoOpacity(elemID){
		if(mmPhotoPlayingDetect) { return false; } else { switchPhotoOpacity(elemID); }
	}


	function switchPhotoOpacity(fadeIn) {
		fadeInNum = fadeIn.split('mmShow_photos_thumb_')[1]
		fadeInFull = 'mmShow_photos_full_' + fadeInNum;

		if(selectedMMPhotoID.id == fadeInFull) { return false; }
		if(photoOpacChanging == true) { return false; }

		for(var i=0; i < mmShowcaseObj.mediaPhotoObj.numImgs; i++) {
			if(fadeInNum == i) {
				alterBorderColor ('mmShow_photos_thumb_' + i, true);
			} else {
				alterBorderColor ('mmShow_photos_thumb_' + i, false);
			}
		}

		// fadeOut is the image that starts at 100% opacity, fadeIn starts at 0

		fadeOutObj.elemID = selectedMMPhotoID.id;
		fadeInObj.elemID = fadeInFull;

		fadeOutObj.currOpac = 100;
		fadeInObj.currOpac = 0;

		alterOpacity(fadeInObj.elemID, 0); // make sure hidden layer has 0 opacity

		document.getElementById(selectedMMPhotoID.id).style.zIndex = 501;
		document.getElementById(fadeInObj.elemID).style.zIndex = 500;

		document.getElementById(selectedMMPhotoID.id).style.display = 'block';
		document.getElementById(fadeInObj.elemID).style.display = 'block';

		if(document.getElementById('mmShow_photos_caption')) { document.getElementById('mmShow_photos_caption').innerHTML = (mmShowcaseObj.mediaPhotoObj[fadeInNum].title); }

		photoOpacChanging = true;
		switchPhotoOpac = setInterval('switchPhotoOpacityInt()', 10);

		//Omniture VS tag for Media Tracking//
		if(typeof _JT!="undefined"){
			//_JT.SET(querystring name, corresponding value)
			_JT.SET("slideshowthumbnail",fadeIn); //fadeIn: element id mmShow_photos_thumb_#
			_JT.SEND("SwitchMedia");
		}

	}


	/* ###################################################################### *\
		Function: switchPhotoOpacityInt
		Fade out/in media slideshow images
	\* ###################################################################### */

	function switchPhotoOpacityInt() {

		if(fadeOutObj.currOpac > 0) {
			fadeOutObj.currOpac -= 20;
			alterOpacity(fadeOutObj.elemID, fadeOutObj.currOpac);
		}
		if(fadeInObj.currOpac < 100) {
			fadeInObj.currOpac += 20;
			alterOpacity(fadeInObj.elemID, fadeInObj.currOpac);
		}

		if((fadeOutObj.currOpac <= 0) && (fadeInObj.currOpac >= 100)) {
			clearInterval(switchPhotoOpac);
			switchPhotoOpac = null;
			photoOpacChanging = false;
			selectedMMPhotoID.id = fadeInObj.elemID;
			return false;
		}

	}



	/* Variables to handle offer scrolling */
	var mmThumbIntv = null;
	var mmThumbCurrentTop = 0; 					// Initially 0 - the top of the container
	var mmThumbListItemSize = photoThumbPixels; // The height in pixels of each offer

	var mmThumbPixelsToScroll 		= mmThumbListItemSize * scrollRate; 	//total pixels to scroll per click
	var mmThumbDisplayedListSize 	= mmThumbListItemSize * scrollRate; 	//items per list

	var mmThumbScrollPixels = 12; //pixels to scroll by.

	var mmThumbScrollSpeed = 20; //timer interval. This determines how often animate() runs. On firefox, values <20 == 20

	var mmThumbScrolled = 0;
	var mmThumbList = null;


	/* ###################################################################### *\
		Function: scroll
		Fire the animate function at set intervals to create a scrolling effect
	\* ###################################################################### */

	function mmThumbscroll(direction, pixels) {
		var command = 'mmThumbAnimate(\''+direction+'\', '+pixels+')';
		mmThumbIntv = setInterval(command, mmThumbScrollSpeed)
	}




	/* ###################################################################### *\
		Function: animate
		Handle the scrolling of the offers in the specified direction and ensure
		that offers do not scroll too far
	\* ###################################################################### */

	function mmThumbAnimate(direction, pixels) {
		// temporarily disable arrows to prevent conflicting clicks
		document.getElementById("mmShow_photo_thumb_up").onclick='';
		document.getElementById("mmShow_photo_thumb_down").onclick='';

		mmThumbList = document.getElementById('mmShow_photo_thumb_inner');
		if(direction == 'down') { // down arrow clicked
			if(mmThumbCurrentTop > -(mmThumbList.offsetHeight - mmThumbDisplayedListSize) && mmThumbScrolled < mmThumbPixelsToScroll) {
				var tmpScroll = pixels
				// check the next iteration won't scroll past the bottom of the container
				if((mmThumbCurrentTop - tmpScroll) < -(mmThumbList.offsetHeight - mmThumbDisplayedListSize)) {
					while((mmThumbCurrentTop - tmpScroll) < -(mmThumbList.offsetHeight - mmThumbDisplayedListSize) && tmpScroll > 0) {
						tmpScroll -= 1;
					}
				}
				// check the next iteration won't exceed mmThumbPixelsToScroll when we're not at the bottom of the container
				if((mmThumbScrolled + tmpScroll) > mmThumbPixelsToScroll) {
					while((mmThumbScrolled + tmpScroll) > mmThumbPixelsToScroll && tmpScroll > 0) {
						tmpScroll -= 1;
					}
				}

				mmThumbCurrentTop -= tmpScroll;
				mmThumbScrolled += tmpScroll;
				mmThumbList.style.top = mmThumbCurrentTop + 'px';

			} else { mmThumbReEnableArrows(); }

		} else { // up arrow clicked
			if(mmThumbCurrentTop < 0 && mmThumbScrolled < mmThumbPixelsToScroll) {
				var tmpScroll = pixels

				// check the next iteration won't take us beyond container top
				if((mmThumbCurrentTop + tmpScroll) > 0) {
					while((mmThumbCurrentTop + tmpScroll) > 0 && tmpScroll > 0) {
						tmpScroll -=1;
						//document.getElementById("upArrow").style.display = 'none';
					}
				}

				// check the next iteration won't exceed mmThumbPixelsToScroll when not at container top
				if((mmThumbScrolled + tmpScroll) > mmThumbPixelsToScroll) {
					while((mmThumbScrolled + tmpScroll) > mmThumbPixelsToScroll && tmpScroll > 0) {
						tmpScroll -=1;
					}
				}

				mmThumbCurrentTop += tmpScroll;
				mmThumbScrolled += tmpScroll;
				mmThumbList.style.top = mmThumbCurrentTop + 'px';

			} else { mmThumbReEnableArrows(); }
		}
	}


	function mmThumbReEnableArrows() {

		clearInterval(mmThumbIntv);
		mmThumbIntv = null;
		mmThumbScrolled = 0;

		document.getElementById("mmShow_photo_thumb_up").onclick=function(){mmThumbscrollCheck('up', mmThumbScrollPixels);}
		document.getElementById("mmShow_photo_thumb_down").onclick=function(){mmThumbscrollCheck('down', mmThumbScrollPixels);}

	}



	function mmThumbscrollCheck(scrollDir,numPix){
	//if(mmPhotoPlayingDetect) { alert true; } else { alert false; }
		if(mmPhotoPlayingDetect) { return false; } else { mmThumbscroll(scrollDir, numPix); }

	}





	function resizeImageThumbs(xMaxSize, yMaxSize, xImgSize, yImgSize) {
		if(!xImgSize || !yImgSize) { return false; }
		// xMaxSize/yMaxSize - the largest horizontal and vertical sizes
		// xImgSize/yImgSize - the initial image horizontal and vertical sizes

		// set the image width to the max width, if that takes the height beyond the max height set the height to the max and the width the same ratio
		var diffXYout = new Object();
		var diffXY;
		diffXY = xMaxSize/xImgSize;

		if((yImgSize*diffXY) <= yMaxSize) {
			diffXYout.xImgSize = xMaxSize;
			diffXYout.yImgSize = (yImgSize*diffXY);

		} else {
			diffXY = yMaxSize/yImgSize;
			diffXYout.yImgSize = yMaxSize;
			diffXYout.xImgSize = (xImgSize*diffXY);
		}

		diffXYout.xOffSet = Math.floor((xMaxSize - diffXYout.xImgSize)/2);
		diffXYout.yOffSet = Math.floor((yMaxSize - diffXYout.yImgSize)/2);

		diffXYout.xImgSize = Math.floor(diffXYout.xImgSize);
		diffXYout.yImgSize = Math.floor(diffXYout.yImgSize);

		return diffXYout;
	}



	function resizeImg(imgElem, containerElem) {
		if(document.getElementById(containerElem)) {
			var sizesXY = resizeImageThumbs(410, 410, document.getElementById(imgElem).width, document.getElementById(imgElem).height);
			if(document.getElementById(imgElem).height > 0) {
				document.getElementById(containerElem).style.top = sizesXY.yOffSet + 'px';
			}
			if(document.getElementById(imgElem).width > 0) {
				document.getElementById(containerElem).style.left = sizesXY.xOffSet + 'px';
			}
		}
	}

	function mmThumbInitScroll() {
		document.getElementById("mmShow_photo_thumb_up").onclick=function(){mmThumbscrollCheck('up', mmThumbScrollPixels);}
		document.getElementById("mmShow_photo_thumb_down").onclick=function(){mmThumbscrollCheck('down', mmThumbScrollPixels);}

			//document.getElementById('mmShow_photos_prev').onclick=function(){mmShowPhotosControls('prev');}
		document.getElementById('mmShow_photos_pause').onclick=function(){mmShowPhotosControls('pause');}
		document.getElementById('mmShow_photos_play').onclick=function(){mmShowPhotosControls('play');}
			//document.getElementById('mmShow_photos_next').onclick=function(){mmShowPhotosControls('next');}
	}




	var mmPhotoPlayingDetect = false;
	var mmPhotoPauseDetect = false;
	var mmPhotosPlayIntv = null;
	var mmPhotosStopNextTime = false;

	var mmPhotoAllLoaded = false;

/* ###################################################################### *\
	Function: mmPlayOnLoadAll
	Check if elem is the last image to load and play if true
\* ###################################################################### */

	function mmPlayOnLoadAll(elemID) {

		var elemNum = elemID.id.split('mmShow_photos_src_')[1];

		if(mmPhotoAllLoaded) {
			document.getElementById('mmShow_photos_caption').innerHTML = (mmShowcaseObj.mediaPhotoObj[0].title);
			mmShowPhotosControls('play');
		} else {

			mmShowcaseObj.mediaPhotoObj[elemNum].loaded = true;


			var checkAllLoaded = true;
			var inc = 1;

			while(mmShowcaseObj.mediaPhotoObj[parseInt(inc, 10)]) {
				if(!mmShowcaseObj.mediaPhotoObj[parseInt(inc, 10)].loaded) {
					checkAllLoaded = false;
				}
				inc++;
			}



			if(checkAllLoaded) {
				document.getElementById('mmShow_photos_caption').innerHTML = (mmShowcaseObj.mediaPhotoObj[0].title);
				mmPhotoAllLoaded = true;
				mmShowPhotosControls('play');
			}
		}
	}

/* ###################################################################### *\
	Function: mmPlayAllError
	Handle errors in loading all images for slideshow - load a default
	instead and restart the load check process
\* ###################################################################### */

	function mmPlayAllError(elemID) {
		var elemNum = elemID.id.split('mmShow_photos_src_')[1];
		mmShowcaseObj.mediaPhotoObj[elemNum].fullSrc = '/images/assets/mm-error-full.gif';
		mmLoadAllFull();
	}


/* ###################################################################### *\
	Function: mmLoadAllFull
	Checks if each 410 image is preloaded, if not it starts the load
	process (and adds error handling)
\* ###################################################################### */

	function mmLoadAllFull() {
		var inc = 1;
		document.getElementById('mmShow_photos_caption').innerHTML = 'Loading all images, please wait...';

		while(mmShowcaseObj.mediaPhotoObj[parseInt(inc, 10)]) {
			if(!mmShowcaseObj.mediaPhotoObj[parseInt(inc, 10)].loaded) {
				// The order of the next three statements is important (IE6 problem)
				document.getElementById('mmShow_photos_src_'+parseInt(inc, 10)).onload = function(){ mmPlayOnLoadAll(this); }
				document.getElementById('mmShow_photos_src_'+parseInt(inc, 10)).onerror = function(){ mmPlayAllError(this); }
				document.getElementById('mmShow_photos_src_'+parseInt(inc, 10)).src = mmShowcaseObj.mediaPhotoObj[parseInt(inc, 10)].fullSrc;
				checkAllLoaded = false;
			}
			inc++;
		}
	}



	function mmShowPhotosControls(controlType) {

		switch (controlType) {

			case 'play':

				if(!mmPhotoAllLoaded) {

					mmLoadAllFull();

				} else {

					if(mmPhotoPlayingDetect) { return false; }
					mmPhotoPlayingDetect = true;

					var tmpSelNum = parseInt(((selectedMMPhotoID.id.split('mmShow_photos_full_')[1]) / 3), 10);
					var tmpTopOffset = parseInt(tmpSelNum, 10) * mmThumbListItemSize;

					while((tmpTopOffset + mmThumbDisplayedListSize) > document.getElementById('mmShow_photo_thumb_inner').offsetHeight && (tmpTopOffset > 0)) {
						tmpTopOffset -= 1;
					}

					document.getElementById('mmShow_photo_thumb_inner').style.top = -tmpTopOffset + 'px';
					mmThumbCurrentTop = -tmpTopOffset;
					mmPhotosPlayIntv = setInterval('mmShowPhotosControlsPlayer()', 3000);

				}
			break;
			case 'pause':
				if(!mmPhotoPlayingDetect) { return false; }
				mmPhotoPlayingDetect = false;
				mmPhotoPauseDetect = false;
				mmShowPhotosControlsPlayerStop();
			break;

		}
	}



	function mmShowPhotosControlsPlayerStop() {
		clearInterval(mmPhotosPlayIntv);
		mmPhotosPlayIntv = null;
		mmThumbPixelsToScroll = mmThumbListItemSize * scrollRate;
		document.getElementById('mmShow_photos_play').style.display ='block';
		document.getElementById('mmShow_photos_pause').style.display ='none';
	}

	function mmShowPhotosControlsPlayer() {
		mmThumbPixelsToScroll = mmThumbListItemSize * 1;

		// get selected image and increment by +1 until end reached
		var tmpFadeNum = selectedMMPhotoID.id.split('mmShow_photos_full_')[1];
		document.getElementById('mmShow_photos_play').style.display ='none';
		document.getElementById('mmShow_photos_pause').style.display ='block';

		if(mmPhotosStopNextTime) {
			mmPhotosStopNextTime = false;
			mmPhotoPlayingDetect = false;
			mmPhotoPauseDetect = false;
			mmShowPhotosControlsPlayerStop();
			return false;
		}

		if(document.getElementById('mmShow_photos_thumb_'+(parseInt(tmpFadeNum,10) + 1))) {
			switchPhotoOpacity('mmShow_photos_thumb_'+(parseInt(tmpFadeNum,10) + 1));
			if (((tmpFadeNum+1) % 3) == 0) { mmThumbscroll('down', mmThumbScrollPixels); }
		} else {
			switchPhotoOpacity('mmShow_photos_thumb_0');
			document.getElementById('mmShow_photo_thumb_inner').style.top = '0px'; // scroll to top
			mmThumbCurrentTop = 0;
			mmPhotosStopNextTime = true;
		}

		if(mmPhotoPauseDetect) {
			mmPhotoPlayingDetect = false;
			mmPhotoPauseDetect = false;
			mmShowPhotosControlsPlayerStop();
		}
	}

// ################################################################################
// ##  Open link in a new window without redirecting original window - add the
// ##  following onclick event to link:
// ##  onclick="openSelfNewWindow(this.href); return false;"
// ################################################################################

	function openSelfNewWindow(linkURL, winName, winAttrib) {
		if((winName && winName != '') && (winAttrib && winAttrib != '')) {
			window.open(linkURL, winName, winAttrib);
		} else if((winName && winName != '') && (!winAttrib || winAttrib == '')) {
			window.open(linkURL, winName);
		} else if((!winName || winName == '') && (winAttrib && winAttrib != '')) {
			window.open(linkURL, '', winAttrib);
		} else {
			window.open(linkURL);
		}
		return false;

		//Omniture VS tag for Media Tracking//
		if(typeof _JT!="undefined"){
			//_JT.SET(querystring name, corresponding value)
			_JT.SET("linkurl",linkURL);
			_JT.SET("winname",winName);
			_JT.SET("winAttrib",winAttrib);
			_JT.SEND("SwitchMedia");
		}

	}






			function fauxHover(){
			if (window.attachEvent && document.getElementById("sp_v02_menu")){ // quick check for IE
				var fhElem = document.getElementById("sp_v02_menu").getElementsByTagName("LI");
					for (var i=0; i<fhElem.length; i++) {
						fhElem[i].onmouseover=function() { this.className+=" fauxHover"; }
						fhElem[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" fauxHover\\b"), ""); }
					}
				}
			}





// ################################################################################
// ##
// ## Function: locationBasicPageBuilder
// ## Build javascript elements of generated pages
// ##
// ################################################################################


	function locationBasicPageBuilder(locLevel, themeType) {
		pageAssetName = (!document.getElementById('p_assetName').innerHTML || (document.getElementById('p_assetName').innerHTML == '') ? '' : document.getElementById('p_assetName').innerHTML);
		var url = location+'';

		fauxHover(); // attach events to make menu work in IE

		// build the multimedia module
		buildMediaModule(locLevel, themeType);



		if(document.getElementById('p_mmShow_video_test')) {
			document.getElementById('p_mmShow_video_test').innerHTML = '';
		}
	}


	function showHideNavPop(elemID, showHide) {
		if(document.getElementById(elemID)) {
			document.getElementById(elemID).style.display = (showHide == 'show' ? 'block' : 'none');
		}
	}




function show_video(video_url,title){
var video_area = document.getElementById('video_container');
video_area.innerHTML='<h3>'+ title +'</h3><div id="video_player"><embed src="'+ video_url +'"loop="1" width="441" height="371" autostart="true"></embed></div>';
}

function change_image(image,theme){
				var backgroundImageHandle = document.getElementById('p_homepage'+theme+'_contentContainer_top');
				backgroundImageHandle.style.backgroundImage='url('+image+')';
				return false;
		}




function popVividas(url)
{
	if(document.getElementById('Player').controls)
	{
		document.getElementById('Player').controls.stop();
	}
	else if(document.getElementById('Player').getElementsByTagName('embed')[0])
	{
		var playingVideoContents = document.getElementById('Player').innerHTML;
		playingVideoContents = playingVideoContents.replace('autostart="1"','autostart="0"');
		document.getElementById('Player').innerHTML = playingVideoContents;
	}
	urchinTracker('/urchin-ga/vividas-played');
	window.open(url,'vividasPopup','height=120,width=400,top=200,left=200');
}

function fixImagePNG(elemID)
{
   if(!document.getElementById(elemID)) {return false;}
   var img = document.getElementById(elemID);

   if( ! img.complete )
   {
      img.onload = fix_png;
   }
   else
   {
      fix_png.apply( img );
   }
}

function fix_png( )
{
    var img = this;
    var span = document.createElement( "span" );
    if( img.id)           span.id = img.id;
    if( img.className	) span.className	= img.className;
    if( img.onclick   	) span.onclick		= img.onclick;
    if( img.onmouseover	) span.onmouseover	= img.onmouseover;
    if( img.onmouseout	) span.onmouseout	= img.onmouseout;
    if( img.onmouseup	) span.onmouseup	= img.onmouseup;
    if( img.onmousedown	) span.onmousedown	= img.onmousedown;
    span.title 			= img.title ? img.title : img.alt;
    span.style.width	= img.width + "px";
    span.style.height	= img.height + "px";
    span.style.filter	= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='scale'";
    img.id				= null;
    img.parentNode.insertBefore( span , img );
    img.parentNode.removeChild( img );
}


function changeMenuClass(elemID) {

	//inactive class names
	var photoMenuClassName 		= 'showcasePhotosMenu';
	var videoMenuClassName 		= 'showcaseVideoMenu';
	var gmapMenuClassName 		= 'showcaseGmapMenu';
	var flickrMenuClassName 	= 'showcaseFlickrMenu';

	//first set classnames of showcase menu div's to inactive class name.
	var photoMenuDiv	= document.getElementById('p_mmShowcase_menu_photos');
	var videoMenuDiv	= document.getElementById('p_mmShowcase_menu_video');
	var gmapMenuDiv		= document.getElementById('p_mmShowcase_menu_gmap');
	var flickrMenuDiv	= document.getElementById('p_mmShowcase_menu_flickr');

	if(photoMenuDiv) 	photoMenuDiv.className 		= photoMenuClassName;
	if(videoMenuDiv)	videoMenuDiv.className 		= videoMenuClassName;
	if(gmapMenuDiv)		gmapMenuDiv.className 		= gmapMenuClassName;
	if(flickrMenuDiv)	flickrMenuDiv.className 	= flickrMenuClassName;

	//now get the id of the clicked elem and change class name to active
	var elem 		= document.getElementById(elemID.id);
	var activeDiv 	= document.getElementById(elem.id);

	if(activeDiv) {

		if (activeDiv.id == 'p_mmShowcase_menu_photos')			photoMenuDiv.className 		= photoMenuClassName + 'Active';
		else if(activeDiv.id == 'p_mmShowcase_menu_video')		videoMenuDiv.className 		= videoMenuClassName + 'Active';
		else if(activeDiv.id == 'p_mmShowcase_menu_gmap')		gmapMenuDiv.className 		= gmapMenuClassName + 'Active';
		else if(activeDiv.id == 'p_mmShowcase_menu_flickr')		flickrMenuDiv.className 	= flickrMenuClassName + 'Active';

	}

}
