	//homepage splash image randomizer 
	if ( $('#hp-contents').length ==1){
		hpImgRandomizer();
		//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');
	}

$(function() {
	
	if  ( jQuery.support.cssFloat != true ){
		/*ie 6 transparency fix*/
		$('#sub-nav, #bread-crumb-box, #globalTopNav').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://deimos3.apple.com\']').length !=0 || 
		$('a[href*=\'https://www.ovationtix.com\']').length !=0 || 
		$('a[href*=\'http://blip.tv/\']').length !=0 ){
			displayButton();
		} 
 
	//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();
	});
		
	
});	
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();
	 		//console.log(imgWidth);
	 		$('img[title='+imgCaption+']').after('<div class="image-caption" style="float:left;width:'+imgWidth+'px !important">'+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(){
	bgImageTotal=5;
 	randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
 	imgPath=('/images/homepage/splash-'+randomNumber+'.jpg');
 	$('div#hp-contents').html('<img src="'+imgPath+'" style="margin-top:-2px;z-index:-99"  width="960" height="640" />');
}
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\']')
		.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')
		.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(){ 

	$('.wide-content-left a.video-icon').addClass('position-relative').css({'width':'150px','display':'block'});
	$('.wide-content-left a.video-icon').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) {
	$('img[src*=\''+id+'.jpg\']')
		.addClass('pointer')
		.wrap("<a onmouseover=\'viewImg(\"600px\",\"600px\");\' href=\'http://www.flickr.com/slideShow/index.gne?group_id=&user_id=26173086@N08&set_id="+setId+"\' class=\'view-image\'></a>")
		.after('<p style="text-align:center">Click to view slideshow. </p>');
		//console.log('id = '+id);
 }
function viewImg(vwidth, vheight){
		var loadInIframeModal = function(hash){
			var $trigger = $(hash.t);
			var $modal = $(hash.w);
			var myUrl = $trigger.attr('href');
			var myTitle= $trigger.attr('title');
			var $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
			});
		//$('.jqmWindow').css({'left':'30%'});
}

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>');
		console.log('id = '+id);
 }
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});
				//add 22px to the height to accomodate the close button
				$('.b_jqmWindow').css('height', function(){ return $(this).height() + 22 +'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({'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
			});
}