	var promoLoc =['/mirrorofthebuddha','/comics','/k2','/brainwave','/prince','/exhibitions'];
	
	//homepage splash image randomizer 
	if ( $('#hp-contents').length ==1){
		
		hpImgRandomizer(6); //from 0, in sequential order, rotate this many images
		//the following effectively funtions as a topnav switch between the homepage and all other pages.
		$('ul#globalTopNav, .sf-menu li a ul, .sf-menu li li a, #global-nav li a, #global-nav li, #topNavSearchBox').addClass('homepage');	
	} 
		
	//if img has title attr then display it beneath it
	if(  !$('#hp-contents').length) {
		imgPhotoCaption();
		//imgPhotoCredit();
	}
	
	//page anchor button generator	
	if( $('#content a[name]').length >=1) {
		anchorLinksNav(); 
	} else {
		$('#pageAnchors').addClass('display-none');
	}
	
	//Exhibitions pages
		
	//Bardo				(image name, set id)	
		flickrSlideShow('bardo','72157623534350384');
	//Mandala				(image name, set id)
		flickrSlideShow('mandala','72157622482527592');
	//Jain						(image name, set id)	
		flickrSlideShow('victorious_ones','72157622590961162');
	//Redbook				(image name, set id)	
		flickrSlideShow('red_book','72157622682214768');
	//Cosmos				(image name, set id)	
		flickrSlideShow('visions_cosmos','72157622926039721');
	//Tradition transformed	
		flickrSlideShow('tradition_transformed','72157625136553271');
	//Icons
		flickrSlideShow('embodying_holy','72157625123788317');
	//Legacy
		flickrSlideShow('nepalese_legacy','72157625040186465');
	//Photos of sikkim and Bhutan
		flickrSlideShow('british_life','72157625122459408');
	//Gateway
		flickrSlideShow('gateway','72157624997637177');
	//Gateway B Rotation
		flickrSlideShow('gateway_b_rotation','72157627868218601');
	//RTYWD
		flickrSlideShow('rtywd','72157624073561521');
	//In the Shadow of Everest
		flickrSlideShow('shadow_everest','72157623743094674');
	//Art of Nepal
		//flickrSlideShow('insert-image-name','72157619877634282');
	//The Dragons Gift
		flickrSlideShow('dragons_gift','72157606470879283');
	//Color and Light	
		flickrSlideShow('color_light','72157606470642863');
	//The Last Nomads
		flickrSlideShow('last_nomads','72157606466987646');
	//Grains of Emptiness	
		flickrSlideShow('grain','72157625515428550');
	//Patterns	
		flickrSlideShow('patterns_exhibit','72157626484171913');
	//Body Language
		flickrSlideShow('body_lang','72157626069321244');
	//Masterworks
		flickrSlideShow('masterworks','72157626499011838');
	//Naxi
		flickrSlideShow('qrc_naxi','72157626686570803');
	//Pilgrimage and Faith
		flickrSlideShow('pf','72157627193682458');
	//Human Currents
		flickrSlideShow('humancurrents','72157627325956777');
	//Once Upon Many Times
		flickrSlideShow('oumt','72157627992648390');
	//Mirror of the Buddha
		flickrSlideShow('mirror_buddha','72157628310350075');
	//Body Unbound
		flickrSlideShow('body_unbound','72157628310657787');	
	// herovillainyeti
		flickrSlideShow('herovillainyeti','72157629217664021');	


		if ($('img[src*=visit-group-reservations-550]').length >=1){
			bliptvModalViewer_720x510('visit-group-reservations-550','htBWgpSMYQA%2Em4v');		
		}
		
			
$(function() {
	if(document.all && !window.opera && window.XMLHttpRequest){
		$('div#supersize').offset({ top: 0, left: 0 }).supersize();
	} else {
	//the following 'supersize' method is what creates the fullscreen background image
		$("div#supersize").supersize();
	}
	
	
	if  ( jQuery.support.cssFloat != true ){
		/*ie 6 transparency fix*/
		$('#sub-nav, #bread-crumb-box, #globalTopNav, #bottom').supersleight({shim: '/images/x.gif'});
		$('.button').corner();
	}
	
	//global topnav
	$('.sf-menu').superfish({ 	// initialize Superfish flyout horizontal global top-nav 
				pathClass:  'current',
				pathLevels:    1,     
				delay:       1000,                            	// one second delay on mouseout 
			  //animation:   {opacity:'show'},  		// fade-in 
				speed:       'fast',                           // faster animation speed 
				autoArrows:  false,                        // disable generation of arrow mark-up 
				dropShadows: false,                      // disable drop shadows 
				onHide: function(){ $(this).addClass('current') }
			}).find("#globalTopNav li").addClass('current');
	
	if( $('#container a[href*=\'http://www.flickr.com/photos/\']').length !=0 || 
		$('#container a[href*=\'http://itunes.apple.com/WebObjects/\']').length !=0 || 	
		$('#container a[href*=\'http://itunes.apple.com/itunes-u/\']').length !=0 || 	
		$('#container a[href*=\'http://deimos3.apple.com\']').length !=0 || 
		$('a[href*=\'https://www.ovationtix.com\']').length !=0 || 
		$('a[href*=\'http://blip.tv/\']').length !=0 ){
			displayButton();
		} else{
			//nothing
		}
 
	//Multimedia video icons
		displayVideoIconButton();
			
	//sitemap page scrolling function
		sitemapScroll();
			
	//loads and displays the enews iframe		
	$('#enews-subscribe, #enews li a:first').bind('click', function(event){ 
		event.preventDefault();
		BlockUILoadingMesagge();
		$('#enewsWrapper').slideToggle('slow');
		enewsModal();
	});
		
	
});	

//sitewide stretchy bgImg 
(function($){
	//Resize image on ready or resize
	$.fn.supersize = function() {   
		//Invoke the resizenow() function on document ready
		$(document).ready(function() {
			$('#supersize').resizenow(); 
			
		});
		//Invoke the resizenow() function on browser resize
		$(window).bind("resize", function() {
			$('#supersize').resizenow(); 
		});
	};
	//Adjust image size
	$.fn.resizenow = function() {
		//Define starting width and height values for the original image
		var startwidth = 1100;  
		var startheight = 1400;
		//Define image ratio
		var ratio = startheight/startwidth;
		//Gather browser dimensions
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		//Resize image to proper ratio
		if ((browserheight/browserwidth) > ratio) {
			$(this).height(browserheight);
			$(this).width(browserheight / ratio);
			$(this).children().height(browserheight);
			$(this).children().width(browserheight / ratio);
			/*
				alert('width = '+browserwidth);
				alert('height = ' +browserheight);
			*/
		} else {
			$(this).width(browserwidth);
			$(this).height(browserwidth * ratio);
			$(this).children().width(browserwidth);
			$(this).children().height(browserwidth * ratio);
			/*
				alert('width = '+browserwidth);
				alert('height = ' +browserheight);
			*/
		}
		//Make sure the image stays center in the window
		$(this).children().css('left', (browserwidth - $(this).width())/2);
		$(this).children().css('top', (browserheight - $(this).height())/2);
	};
})(jQuery);
function BlockUILoadingMesagge(){
	//the following method utilizes, nay REQUIRES!, the /js/jquery/jquery.blockUI.js plugin
	$.blockUI({ 
		message: '<h1>Loading...<img src="/images/loading.gif"><h1>', 
		css: { 
		border: 'none', 
		padding: '15px', 
		backgroundColor: '#fff', 
		'-webkit-border-radius': '10px', 
		'-moz-border-radius': '10px', 
		opacity: .7, 
		color: '#000'}
		
	}); 
	setTimeout($.unblockUI, 1500); 
}
function searchToggle(){
	$('#topNavSearchBox').toggle();
}
function anchorLinksNav(){
	var anchors = $('#content a[name][name!=top]');
	$.each(anchors,function(i){
		var aName = $(anchors[i]).attr('name');
		if (anchors.length >1){
			var links = '<a href="#'+aName+'">'+aName+'</a>\x20<span class="anchorSlash">/\x20</span>'
		} else {
			var links = '<a href="#'+aName+'">'+aName+'</a>\x20'
		}
		$(links).appendTo('#pageAnchors');
	});
	$('#pageAnchors').css({'margin':'0px 0px 20px 40px'});
	
}
function imgPhotoCaption(){
	if ( !!$('img[title^="caption"]').length){
		var imgs =  $('img[title^="caption"]');
		$(imgs).each( function(i){
	 		
	 		var imgCaption = $(imgs[i]).attr('title'), 
	 		$caption = imgCaption, 
	 		captionTxt = $caption.replace('caption',''), 
	 		imgWidth = $(this).width();
	 		
	 		$('img[title=\"'+imgCaption+'\"]').after('<div class="image-caption" style="float:left;width:'+imgWidth+'px !important;margin:0 0 5px 0">'+captionTxt+'</div>');
		});	
	}
}
function imgPhotoCredit (){
	if ( !!$('img[alt^="Photograph by"]').length){
		var imgs =  $('img[alt^="Photograph by"]');
		$(imgs).each( function(c){
			var imgCredit = $(imgs[c]).attr('alt');
			$('img[alt=\"'+imgCredit+'\"][alt!=close]').after('<div class="image-credit">&nbsp;'+imgCredit+'</div>');
		});
	}
}

function hpImgRandomizer(imgNum){
	var $hp_contents = $('#hp-contents'), 
		bgImageTotal= imgNum, 
		randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1, 
		imgPath=('/images/homepage/splash-'+randomNumber+'.jpg'),
		promoAnchor =  promoLoc[randomNumber-1];
		
		$('<img/>',{
			"src":imgPath,
			"width":"960",
			"height":"640",
			"id":"hp_splash"
 		}).appendTo($hp_contents);

 		$('#hp_promo')
		.bind('click', function(event){
			document.location = promoAnchor;
		})
		.hover(
			function () {
				$(this).addClass("promo_hover");
		  },
		  	function () {
				$(this).removeClass("promo_hover");
		  });
}
function youTubeModalWin(url, vWidth, vHeight){
	var closeButton 						= function () { containerDiv.removeChild(lightDiv);	containerDiv.removeChild(fadeDiv);}
	var fadeDiv  							= document.createElement('div');
	var containerDiv 						= document.getElementById('container');
	var lightDiv 							= document.createElement('div');	
		lightDiv.id							= 'light';
		lightDiv.className 					= 'modal_light_content';
		lightDiv.style.display				= 'block';
		lightDiv.onclick 					= closeButton;
		lightDiv.style.width				= vWidth;
		lightDiv.style.height				= vHeight;
		lightDiv.style.left					= '12%';
		lightDiv.style.padding				= '20px';
		lightDiv.innerHTML	='<object width="640" height="505"><param name="movie" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object><br />';
		lightDiv.innerHTML +='<div align="right" style="z-index:1050"><a href="#" onclick="closeButton"><img src="http://www.rmanyc.org/images/closelabel.gif" width="66" height="22" border="0" alt="close" id="closeBttn" /></a></div>';
		fadeDiv.id='fade';
		fadeDiv.className='modal_blackBg';
		fadeDiv.style.display='block';
		fadeDiv.style.backgroundColor='#222';
		fadeDiv.style.textAlign='center';
		fadeDiv.onclick = closeButton;
		containerDiv.appendChild(fadeDiv);
		containerDiv.appendChild(lightDiv); 
		window.scrollTop = 0;
}
function youtubeModalViewer(id) {
	//$('#test')
	$('img[src*=\''+id+'.png\']')
		.css({'cursor':'pointer'} )
		.wrap("<a onclick=\'youTubeModalWin(\"http://www.youtube.com/v/17jymDn0W6U&hl=en_US&fs=1&rel=0&hd=1\",\"640px\",\"510px\");\' href=\'#\' class=\'view-image\'></a>")
		.after('<p style="text-align:center">Click to view video.<img src="/images/video-icon.gif"  alt="video" border="0" style="width:25px;height:25px;border:0px solid"/> </p>');
		//console.log('id = '+id);
 }
function toggleSitemap(){
	$('#sitemap').slideToggle('slow');
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+";)";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	
}
function initImage() {
	imageId = 'thephoto';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}
function initPhotoImage() {
	imageId = 'cardtray';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,90);
}
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
 }
function initRolloverImage(number) {
	imageId = new Array;
	//image = document.getElementById(number);
	image = document.getElementById(number);
	setOpacity(image, 10);
	image.style.visibility = "visible";
	fadeIn(number,70);
} 
function modalWin(url, vWidth, vHeight){
	var closeButton 						= function () { containerDiv.removeChild(lightDiv);	containerDiv.removeChild(fadeDiv);}
	var fadeDiv  							= document.createElement('div');
	var containerDiv 						= document.getElementById('container');
	var lightDiv 								= document.createElement('div');	
		lightDiv.id							= 'light';
		lightDiv.className 				= 'modal_light_content';
		lightDiv.style.display				='block';
		//lightDiv.style.marginTop		='0px';
		//lightDiv.style.marginBottom	='0px';
		//lightDiv.style.marginRight		='auto';
		//lightDiv.style.marginLeft		='auto';
		lightDiv.onclick 					= closeButton;
		lightDiv.style.width					=vWidth;
		lightDiv.style.height				=vHeight;
		lightDiv.style.left					='12%';
		lightDiv.style.padding				='20px';
		// sometimes innerHTML just makes life easier
		lightDiv.innerHTML	='<iframe frameborder="0" src ="'+url+'" style="height:'+vHeight+';width:'+vWidth+';z-index:1010;"></iframe><br />';
		lightDiv.innerHTML +='<div align="right" style="z-index:1050"><a href="#" onclick="closeButton"><img src="http://www.rmanyc.org/images/closelabel.gif" width="66" height="22" border="0" alt="close" id="closeBttn" /></a></div>';
		fadeDiv.id='fade';
		fadeDiv.className='modal_blackBg';
		fadeDiv.style.display='block';
		fadeDiv.style.backgroundColor='#222';
		fadeDiv.style.textAlign='center';
		fadeDiv.onclick = closeButton;
		containerDiv.appendChild(fadeDiv);
		containerDiv.appendChild(lightDiv); 
		window.scrollTop = 0;
}
function displayButton(){ 
	//slideshow button 
	$('#container a[href*=\'http://www.flickr.com/photos/\']')
		.addClass('noUnderline slideshowHover')
		.attr('target', '_new')
		.prepend('<img src="/images/play-arrow.gif" width="9" height="13"  class="playArrow" />')
		.wrapInner('<span class="flickrBtn button"></span>')
		.append('<br />');
		
	//podcast button
	$('#container a[href*=\'http://deimos3.apple.com\'], #container a[href*=\'http://itunes.apple.com/WebObjects/\'], #container a[href*=\'http://itunes.apple.com/itunes-u/\']')
		.not('.video-icon')
		.addClass('noUnderline slideshowHover')
		.attr('target', '_new')
		.prepend('<img src="/images/play-arrow.gif" width="9" height="13"  class="playArrow" />')
		.wrapInner('<span class="itunesUbtn button"></span>')
		.append('<br />');
		
	//blip button
	$('#container  a[href*=\'http://blip.tv/\']')
		.not('.video-icon, .no-icon')
		.addClass('noUnderline slideshowHover')
		.attr('target', '_new')
		.prepend('<img src="/images/play-arrow.gif" width="9" height="13"  class="playArrow" />')
		.wrapInner('<span class="blipBtn button"></span>')
		.append('<br />');
	
	//ovation ticket button
	$('a[href*=\'https://www.ovationtix.com\']')
		.addClass('noUnderline ovationHover')
		.wrapInner('<span class="ovationTixBtn button"></span>');
}
function displayVideoIconButton(){ 
	if  ( jQuery.support.cssFloat != false ){
		$('.wide-content-left a.video-icon').addClass('position-relative').css({'width':'150px','display':'block'}).append('<span class="videoIcon"></span>');
	}
	
}
function sitemapScroll(){
		$('a[href=\'#bottom\']').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
			var targetOffset = $target.offset().top - 30;
			$('html,body').animate({scrollTop: targetOffset}, 1000);
			return false;
			}
		}
	});
	}
function enewsModal(){
	//Create the iframe which loads the enews URL and append it to #enews 
	if( !$('#enewsWrapper iframe').length){
		$('<iframe />',{
			frameBorder:'0',
			src:'https://app.e2ma.net/app/view:Join/signupId:8363',
			id:'modalWin',
			css:{
				width:'800px',
				height:'800px',
				background:'none repeat scroll 0% 0% rgb(255, 255, 255)'
			}
		}).appendTo('#enewsWrapper');
	}

	//Create the close/cancel button and append it to #enews	and position it below to the enews form submit button
	if( !$('#enewsWrapper #enewsClose').length){
		$('<a />', {  
				id:'enewsClose',
			click: function(){ $('#enewsWrapper').slideToggle('slow'); },
			css: {
				position:'relative',
				top:'-50px',
				right:'435px',
				fontSize:'11px',
				cursor:'pointer',
				textDecoration:'underline'
			},
			text:'Cancel/Close'
		}).appendTo('#enewsWrapper');
	}
}
/* ---------------------------------------------------------------------------------------------------------  */	
/* the following functions:flickrSlideShow, enewsModal, and bliptvModalViewer requires the jqModal library to function properly */
/* ---------------------------------------------------------------------------------------------------------  */
function flickrSlideShow(id, setId) {
	if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
		$('img[src*=\''+id+'_installation_slideshow.jpg\']')
			.addClass('pointer position-relative')
			.wrap("<a target=\'_blank\' href=\'http://www.flickr.com/slideShow/index.gne?group_id=&user_id=26173086@N08&set_id="+setId+"\' onmouseover='viewImg(\"640px\",\"640px\");' class=\'view-image\' style=\'width:auto; float:left\'></a>")
			.after('<span class="ie7slideshowIcon"></span>');
			//alert('ie7!');
		} else {
		$('img[src*=\''+id+'_installation_slideshow.jpg\']')
			.addClass('pointer position-relative')
			.wrap("<a target=\'_blank\' href=\'http://www.flickr.com/slideShow/index.gne?group_id=&user_id=26173086@N08&set_id="+setId+"\' onmouseover='viewImg(\"640px\",\"640px\");' class=\'view-image\' style=\'width:auto; float:left\'></a>")
			.after('<span class="slideshowIcon"></span>');
		}
		
	$('img[src*=\''+id+'_installation_slideshow.jpg\']').closest('h3').next().wrap("<a target=\'_blank\' href=\'http://www.flickr.com/slideShow/index.gne?group_id=&user_id=26173086@N08&set_id="+setId+"\' onmouseover='viewImg(\"640px\",\"640px\");' class=\'view-image\'></a>");
	
	// hide icon in IE
	// if  ( jQuery.support.cssFloat != true ){
	//	$('.slideshowIcon').css('display','none');
	//} 
 }
function viewImg(vwidth, vheight){
		var loadInIframeModal = function(hash){
			var $trigger = $(hash.t),
				$modal = $(hash.w),
				myUrl = $trigger.attr('href'),
				myTitle= $trigger.attr('title'),
				$modalContent = $("iframe", $modal);
			
			$modalContent.html('').attr('src', myUrl);
			$('#jqmTitleText').text(myTitle);
			//added this query to unhide the actual modalWindow class!
			$('.jqmWindow').show().css({'width':vwidth, 'height':vheight});
			//add 22px to the height to accomodate the close button
			$('.jqmWindow').css('height', function(){ return $(this).height() + 22 +'px';});
			$('.jqmWindow > iframe').css({'width':vwidth, 'height':vheight})
			$modal.jqmShow();
		}
		$('#modalWindow').jqm({
				modal: true,
				trigger: 'a.view-image',
				target: '#modalWin',
				onShow:  loadInIframeModal
			});
}
function bliptvModalViewer(id, setId) {
	$('img[src*=\''+id+'.jpg\']')
		.css({'cursor':'pointer'} )
		.wrap("<a onmouseover=\'viewBliptvVideo(\"600px\",\"600px\");\' href=\'http://blip.tv/play/"+setId+"\' class=\'view-image\'></a>")
		.after('<p style="text-align:center">Click to view video. </p>');
 }
function bliptvModalViewer_720x510(id, setId) {
	$('img[src*=\''+id+'.jpg\'], img[src*=\''+id+'.png\']')
		.css({'cursor':'pointer', 'padding-top':'22px'} )
		.wrap("<a onmouseover=\'viewBliptvVideo(\"720px\",\"510px\");\' href=\'http://blip.tv/play/"+setId+"\' class=\'view-image video-icon\'></a>")
		.after('<p>Click to view video. </p>')
		.after('Having trouble viewing, see it on <a href="http://www.blip.tv/file/4505060">Blip.tv</a>');
	displayVideoIconButton();
		
 }
function viewBliptvVideo(vwidth, vheight){
		var loadInEmbedModal = function(hash){
			var $trigger = $(hash.t);
			var $modal = $(hash.w);
			var myUrl = $trigger.attr('href');
			var myTitle= $trigger.attr('title');
			//browser sniffing hack :\ if IE, then load url into iframe else load url into embed
			//if (browser.indexOf('MSIE') != -1) {
			if ( jQuery.support.cssFloat != -1 ){
				var $modalContent = $("iframe", $modal);
			} else {
				var $modalContent = $("embed", $modal);
			}
				$modalContent.html('').attr('src', myUrl);
				//$('#jqmTitleText').text(myTitle);
				//added this query to unhide the actual modalWindow class!
				$('.b_jqmWindow').show().css({'width':vwidth, 'height':vheight, 'overflow':'hidden'});
				//add 22px to the height to accomodate the close button
				$('.b_jqmWindow').css('height', function(){ return $(this).height() + 32 +'px';});
				
				//browser sniffing hack :\ if IE, then load url into iframe else load url into embed
				//if (browser.indexOf('MSIE') != -1) {
				if ( jQuery.support.cssFloat != -1 ){
					$('.b_jqmWindow > iframe').css({'overflow':'hidden', 'width':vwidth, 'height':vheight})
					} else{
						$('.b_jqmWindow > embed').css({'width':vwidth, 'height':vheight})
					}
				$modal.jqmShow();
		}
		$('#bliptvModalWindow').jqm({
				modal: true,
				trigger: 'a.view-image',
				target: '#bliptvWin',
				onShow:  loadInEmbedModal
			});
}

