/*
 *	/js/scripts.js
 *
 * getTheHomePage()
 * mainMenuScript()
 * endOfEachPage()
 * formatTodayDate()
 * formatTomorrowDate()
 * displayTodayDate()
 * getTodaysGcalListing( thisFile, thisDiv )  
 * setMainPageQtips()
 * findTime( beginHH, beginMM, finishHH, finishMM )
 * bbCodes ( someCalStr )
 *
 */

$.ajaxSetup({ cache:false });

$(document).ready(function() {
	mainMenuScript();
/*
	probably works fine, but could be buggy
	
	$('ul.mainMenu a[href="#"]').each( function() {
		$(this).address(function() {  
			return $(this).attr('id');  
			});
		});	
	$.address.change( function(event) {
		var e = event.value.replace(/^\//, '');
		$('a[id=' + e + ']').click();
		});
*/

	setUp_triggerQtip();
	if ( typeof(calendarRequest) != 'undefined' ) {
		$('#calendar').click(); delete calendarRequest; document.title='Calendar: GLBT Resources for Northern Colorado'; return false;
		}
	if ( typeof(newsRequest) != 'undefined' ) {
		$('#moreNews').click(); document.title='News: GLBT Resources for Northern Colorado'; delete newsRequest; return false;
		}
	
	$('#home').click();
		
	}); 
/* --------------------------------------------------------- */
 
/*  main menu js  */
//	the red in the menus:e62b00 was changed to aa0000  on 1-12-2012
function mainMenuScript() {
	$('ul.mainMenu li.subM').hover(
			function() { $('ul.subMenu', this).show(); },      
			function() { $('ul.subMenu', this).hide(); }       
			);	
	$('ul.mainMenu a.subHeader').hover( 
			function() { $(this).css({ 'text-decoration':'none', 'cursor':'default' }); },
			function() { $(this).css({ 'text-decoration':'none' }); }
			);	
	$('ul.mainMenu a').not('.subHeader, .theWeather, #contact ').click( function() {
			$('ul.mainMenu a').css({ 'color':'#1111cc', 'cursor':'pointer' });
			$('ul.mainMenu a').not('.subHeader').hover( 
				function() { $(this).css({ 'text-decoration':'underline' }); },
				function() { $(this).css({ 'text-decoration':'none' }); }
				);
			$(this).css({ 'color':'#aa0000', 'cursor':'none' });
			$(this).hover( 
				function() { $(this).css({ 'text-decoration':'none' }); },
				function() { $(this).css({ 'text-decoration':'none' }); }
				);
			});
	$('ul.subMenu a').not('.theWeather').click( function() {
			$(this).closest('li.subM').children('a').css({ 'color':'#aa0000', 'cursor':'none' });
			$('ul.subMenu').trigger('mouseleave');
			});
	

	/*  set main menu links  */
	$('#home').css({ 'color':'#aa0000', 'cursor':'none' });
	$('#home').hover( 
				function() { $(this).css({ 'text-decoration':'none' }); },
				function() { $(this).css({ 'text-decoration':'none' }); }
				);
	$('#home').click( function() { getTheHomePage(); document.title='GLBT Resources for Northern Colorado'; return false; });
	// $('#home').click();
	$('#calendar').click( function() {
		$('#CONTENT').stop(true, true);
		$('#CONTENT').empty().load( '/php/calendar.php', function() {
			$('#loadingDiv').show();
			$.getScript("/js/fullcalendar.calvis.js");
			$('#loadingDiv').hide();
			endOfEachPage();
			document.title='Calendar: GLBT Resources for Northern Colorado';
			return false;
			});
		});
	$('#contact').qtip({ 
		content: {
			text:'<iframe id="qtipIframe" src="http://fortpride.org/php/contact.php" frameborder="0" marginheight="0" marginwidth="0" width="600" height="700" scrolling="no"></iframe>',
			title: { text:'Looking forward to your comments...', button:'Cancel/Close' }
			},
		position: { target: $('#wrapper-inner'), corner:'topMiddle', adjust: { y:30 } },
		style:{ name:'globalStyle', width: { max:1200 } },
        show: { when:'click', solo:true },
		hide: { fixed: false, when: { event: 'unfocus' } },
		api: {
			beforeShow: function() {
				$('#qtip-blanket').fadeIn(0).fadeTo(1,.6);
				},
			beforeHide: function() {
				$('#qtip-blanket').fadeOut(0);
				},
			onHide: function() {
				this.updateContent( '<iframe id="qtipIframe" src="http://fortpride.org/php/contact.php" frameborder="0" marginheight="0" marginwidth="0" width="600" height="700" scrolling="no"></iframe>' );
				}
			}
		});	

	// --------------------------------------template for all sub pages---------------------
	$('.subPage').click( function() {
		// passing the id of the page to php where its string will be in an array
		var thePage = $(this).attr('id');
		var theGroup = $(this).attr('group');
		var thePageURL = '/php/subPage.php' + '?params=' + encodeURIComponent(thePage);
		$('#CONTENT').stop(true, true);
		$('#CONTENT').load( thePageURL, function() { 
			endOfEachPage(); 

			if ( theGroup == 'aResource' ) { document.title='Information: GLBT Resources for Northern Colorado'; }
			else if ( theGroup == 'forFun' ) { document.title='Entertainment: GLBT Resources for Northern Colorado'; }
			else if ( thePage == 'moreNews' ) { document.title='News: GLBT Resources for Northern Colorado'; }
			else if ( thePage == 'fyi' ) { document.title='FYI: GLBT Resources for Northern Colorado'; }
			else { document.title='GLBT Resources for Northern Colorado'; }
			
			return false; });
		});
	// -------------------------------------------------------------------------------------		
	
	$('#header-links .bidi').each( function() {
		var phrase = $(this).html();
		phrase = phrase.split("").reverse().join("");
		var splitUp = phrase.split('|');
		var emailAddress = splitUp[0];
		var anchorText = splitUp[1];
		$(this).html('<a href="mailto:' + emailAddress + '">' + anchorText + '</a>');
		});
	$('[scrollTo="toTheBottom"]').click( function() { $.scrollTo( '100%', 1000, { axis:'y' } ); return false; });
	$('#weather').flash ({
			swf: '/shows/gWeather.swf', wmode:'opaque', width: 385, height: 125, hasVersion: 8 });
	}  // mainMenuScript()

/*  load the homePage.php into #content  */
function getTheHomePage() {

	$('#CONTENT').stop(true, true).html("<div style='height:800px;'> <p style='margin-left:480px; padding-top:200px; color:#888; font:bold 10px Tahoma,Verdana,sans-serif; letter-spacing:1px;'> loading... </p></div>");

	$('#CONTENT').empty().load( '/php/home.php', function() {	
	
		$('#calendar2').click( function() { $('#calendar').click(); $.scrollTo( 0, 1000 ); return false; });
		$('#moreNews2').click( function() { $('#moreNews').click(); $.scrollTo( 0, 1000 ); return false; });
		$('#fyi2').click( function() { $('#fyi').click(); $.scrollTo( 0, 1000 ); return false; });
		$('#lambda2').click( function() { $('#fyi').click(); $.scrollTo( 0, 1000 ); return false; });
		$('.contact2').click( function() { $('#contact').click(); $.scrollTo( 0, 1000 ); return false; });

		$('#frontPageVideoContainer').flash ({ 
			swf: '/shows/frontPageVideo.swf', wmode: 'opaque', width: 282, height: 360, hasVersion: 9 });
		$('#headlinesShowContainer').flash ({ 
			swf: '/shows/frontPageSlides.swf', wmode: 'opaque', width: 604, height: 383, hasVersion: 9 });
		$('#itemImageLeaderLeft').flash ({
			swf: '/shows/inTheNews.swf', wmode:'opaque', width: 290, height: 120, hasVersion: 9 });
		$('#itemImageLeaderMiddle').flash ({
			swf: '/shows/localEvents.swf', wmode:'opaque', width: 290, height: 120, hasVersion: 9 });
		$('#itemImageLeaderRight').flash ({
			swf: '/shows/fyi.swf', wmode:'opaque', width: 290, height: 120, hasVersion: 9 });
		$('#scroller').flash ({
			swf: '/shows/news-scroller.swf', wmode:'opaque', width: 604, height: 24, hasVersion: 8 });
		$('#countdownTimerLocalEvents').flash ({
			swf: '/shows/countdown.swf', wmode:'opaque', width: 290, height: 90, hasVersion: 9 });
		$('#countdownTimerLocalEvents-2').flash ({
			swf: '/shows/countdown-2.swf', wmode:'opaque', width: 290, height: 110, hasVersion: 9 });
		$('#countdownTimerNews').flash ({
			swf: '/shows/countdown.swf', wmode:'opaque', width: 290, height: 90, hasVersion: 9 });

		
		if ( $('#jsSlideshow') ) {
				$('.containerSlideshow').wtRotator({
					width:582,
					height:327,
					button_width:15,
					button_height:15,
					button_margin:10,
					auto_start:true,
					delay:5000,
					play_once:false,
					transition:"fade",
					transition_speed:1000,
					auto_center:true,
					easing:"",
					cpanel_position:"outside",
					cpanel_align:"BC",
					timer_align:"top",
					display_thumbs:true,
					display_dbuttons:true,
					display_playbutton:true,
					display_numbers:true,
					display_timer:false,
					mouseover_pause:true,
					cpanel_mouseover:false,
					text_mouseover:false,
					text_effect:"right",
					text_sync:true,
					tooltip_type:"none",
					lock_tooltip:true,
					shuffle:false,
					block_size:50,
					vert_size:55,
					horz_size:50,
					block_delay:20,
					vstripe_delay:50,
					hstripe_delay:50			
				});
		}

		
		function loadNewsletterMenu() {
			var flashvars = {}; var params = {}; params.scale = "noscale"; params.salign = "tl"; params.wmode = "transparent"; var attributes = {};
			swfobject.embedSWF("/shows/newsletterMenu/3DCarouselMenuFX.swf", "CarouselDiv", "600", "200", "9.0.0", false, flashvars, params, attributes);	
			}
		loadNewsletterMenu();
		
		$('#belowHistoryFlash').flash ({
			swf: '/shows/belowHistory.swf', wmode:'opaque', width: 290, height: 330, hasVersion: 9 });
		$('#oxylusVerticalNewsTicker').flash ({
			swf: '/shows/verticalNewsTicker.swf', wmode:'opaque', width: 280, height: 200, hasVersion: 9 });
		$('#mediaPlayer').flash ({	
			swf: '/shows/frontPageStaticAlbum.swf', wmode:'opaque', width: 290, height: 247, hasVersion: 9 });
		$('#oxylusPlayerBelowSecondRow').flash ({	
			swf: '/shows/oxylusPlayer.swf', wmode:'opaque', width: 432, height: 243, hasVersion: 9,
			flashvars: { settingsXmlPath: '/shows/oxylusSettings.xml', contentXmlPath: '/shows/oxylusContent.xml' } });
		var iframeSrc = "<iframe id='iframe01' src='http://fortpride.org/php/twitterListing-1.html?r=123456' width='604' height='360' scrolling='no' align='left' frameborder='0' marginheight='0' marginwidth='0' style='padding:0px; margin:0px;'>No iframe support in your browser</iframe>";
		$('#holdsTwitterIframe').html( iframeSrc );
		
		
		$(window).unload( function() {
			$('#mediaPlayer').html('');		
			$('#belowSecondRow').html('');
			$('#belowLocalEventsMediaPlayer').html('');
			// prevents IE problem with function __flash__removeCallback(instance, name) { instance[name] = null; }
			});			
			
		$('#toggleTopRowButton').toggle( 
				function() {  $('.toggleTopRow').toggle(); $(this).attr( 'src','/images/layout/openIt.gif' );  },
				function() {  $('.toggleTopRow').toggle(); $(this).attr( 'src','/images/layout/closeIt.gif' );  } 
				);

		var dt = displayTodayDate();
		$('#calendarDate').text( dt );
		$('[fyiIcon]').each( function() { var strToINSERT = "/images/layout/" + $(this).attr('fyiIcon') + ".gif";
			$(this).css( 'background','url("' + strToINSERT + '") right top no-repeat'); });
		$('#lightbulb').click( function() {
			$('#frontPageVideoContainer').expose({ api:true, opacity:0.6,   /* was $('#frontPageVideoContainer').expose  */
				onBeforeLoad: function() { $('#lightbulb').hide(); },
				onBeforeClose: function() { $('#lightbulb').show(); }
				}).load();
				return false;
			});
		$('#toggleTopRowButton').fadeTo(1000,1).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);
		/*  load the json file, parse and update the div  */
		getTodaysGcalListing( '/php/getTodaysGcal.json', '#localEventsListing');
		/*  set the qtips for the FYI section  */
		setMainPageQtips();
		setEditorialQtips();
		endOfEachPage();
		// $('[scrollTo="toTheTop"]').click();
			
		});  // after loading content is accomplished	
	return false;
	}  // getTheHomePage()

function endOfEachPage() {
	$('#CONTENT SPAN.bidi').each( function() {
		var phrase = $(this).html();
		phrase = phrase.split("").reverse().join("");
		var splitUp = phrase.split('|');
		var emailAddress = splitUp[0];
		var anchorText = splitUp[1];
		$(this).html('<a href="mailto:' + emailAddress + '">' + anchorText + '</a>');
		});
	$('#CONTENT a[target!="_self"]:not([href^="mailto"])').live( "click", function() {   // live to take care of qtips
			$(this).attr({ target: "_blank" });
			});	
	$('.qtip-title a[target!="_self"]:not([href^="mailto"])').live( "click", function() { 
			$(this).attr({ target: "_blank" });
			});
	$('.qtip-content a[target!="_self"]:not([href^="mailto"])').live( "click", function() { 
			$(this).attr({ target: "_blank" });
			});
	$('[scrollTo="toTheTop"]').click( function() { $.scrollTo( 0, 1000 ); return false; });
	$('.scrollText').jTypeWriter({ sequential:false, onComplete:blinkText() });
	function blinkText() {
		$('.blinkText').fadeTo(3000,1).fadeOut(1000).fadeIn(1000).css({'opacity':'1'});
		}
	}  // endOfEachPage()
 
/* ---------------------------------------- more functions ------------------------------------------ */

 
/*  return a formatted string of Gcal listings FOR THIS DAY  */
//	singleevents=true&futureevents=true&orderby=starttime&sortorder=ascending&ctz=America/Denver&max-results=15&alt=json";
function getTodaysGcalListing( thisFile, thisDiv ) {
        var htmlString = '';
        $.ajax({
                url: thisFile,
                type: 'GET',
                cache: false,
                processData: false,
                dataType: 'json',
                success: function(jdata) {		
							var d = new Date();
							var yyyy = d.getFullYear();
							var mm = d.getMonth(); mm++; if (mm < 10 ) { mm = '' + mm;  mm = '0' + mm; }
							var dd = d.getDate(); if ( dd < 10 ) { dd = '' + dd;  dd= '0' + dd; }
							var theDate = yyyy + '-' + mm + '-' + dd;				
					if ( jdata.feed.entry ) {
							$( jdata.feed.entry ).each( function() {
									
									if ( this.gd$eventStatus['value'].indexOf( 'confirmed', 0 ) > 1 && this.gd$when != undefined ) {
										
										if ( this.gd$when[0]['startTime'].substring(0, 10) == theDate ) {
										
											htmlString += '<div class="itemBody"><img src="/images/layout/calendar-item.gif">&nbsp;';
											
											var beginTime = new Date();
												var iso = this.gd$when[0]['startTime'];
												if ( iso.length==10 ) { iso = iso + 'T00:00:00.000-07:00'; }
												beginTime = beginTime.setISO8601( iso );
												var beginTimeHH = beginTime.getHours();
												var beginTimeMM = beginTime.getMinutes();
											var finishTime = new Date();
												var iso = this.gd$when[0]['endTime'];
												if ( iso.length==10 ) { iso = iso + 'T00:00:00.000-07:00'; }
												finishTime = finishTime.setISO8601( iso );
												var finishTimeHH = finishTime.getHours();
												var finishTimeMM = finishTime.getMinutes();
											var displayTime = findTime( beginTimeHH, beginTimeMM, finishTimeHH, finishTimeMM );
												if ( displayTime == '1:00am ' ) { displayTime = ''; }    // not sure why I have to do this.
												htmlString += displayTime;
												
											var title = this.title['$t'];
												title = bbCodes ( title );
												htmlString += title;
											var content = this.content['$t'];
												content = bbCodes ( content );
												if ( content.length > 0 ) { htmlString +=  "&nbsp; &mdash; &nbsp;" + content; }
												
											htmlString += '</div>';
											
											}
											
										}
								
								});  // each
							$( thisDiv ).empty();
							$( thisDiv ).html( htmlString );
						}  // if 'entry' exists
                    }  // success fn
            });  // ajax call
	}  // getTodaysGcalListing()

/*  set up qTips for the main page #content  */
function setMainPageQtips() {
$('#fyi_pflag').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Parents, Families and Friends of Lesbians and Gays', CONTENTTEXT:'Visit our local chapter of the <a href="http://pflag.org">national PFLAG organization</a> promoting "the health and well-being of gay, lesbian, bisexual and transgender persons, their families and friends through: support, to cope with an adverse society; education, to enlighten an ill-informed public; and advocacy, to end discrimination and to secure equal civil rights.  Parents, Families and Friends of Lesbians and Gays provides opportunity for dialogue about sexual orientation and gender identity, and acts to create a society that is healthy and respectful of human diversity."' });
$('#fyi_resource_brochure').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Community Resources brochure', CONTENTTEXT:'a summary of GLBTQ organizations that serve as resources to our community in northern Colorado.  Feel free to print and distribute the flyer.' });
$('#fyi_bcb').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Back Country Bettys', CONTENTTEXT:'"serving the women of northern Colorado and southern Wyoming," BCB has been a central portal for lesbians and women accepting of lesbian lifestyles since 1977.' });
$('#fyi_ff').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Fortunate Families', CONTENTTEXT:'is a national organization of "Catholic families advocating respect and justice for their gay and lesbian children." Without local support for these families, the monthly newsletter makes encouraging reading.' });
$('#fyi_oglbt').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Older Gay Lesbian Bisexual and Transgender Group', CONTENTTEXT:'meets for social meals once a month at varying times and places, graciously hosted by Katie Steiber who can be reached at <nobr>224-6029</nobr> or at <a href="mailto:kstieber@fcgov.com">kstieber@fcgov.com</a>' });
$('#fyi_lambda').data( 'info', { ICON:'icon-pdf', TITLETEXT:'The GLBT Community Center of Northern Colorado = Lambda Community Center', CONTENTTEXT:'is our community\'s resource for support groups, youth acitivities, and our annual "Pride in the Park" each summer.  For more information about Northern Colorado programs, please call the Northern Colorado Site Coordinator Heather at 970-221-3247. The Center\'s hours at 212 S. Mason Street, Fort Collins, continue M-Th 11am-7pm and Friday 9am-5pm.' });
$('#fyi_ncap').data( 'info', { ICON:'icon-pdf', TITLETEXT:'The Northern Colorado AIDS Project', CONTENTTEXT:'<b>NCAP</b> offers appointments for anonymous HIV testing, educational outreach, individual counseling, and support and referrals for clients, their partners, and family & friends.  400 Remington St <nobr>484-4469</nobr>.  HIV testing with 10min results.  Hep C testing.  HIV/AIDS connection to care and other services.  Free STI screenings (gonorrhea, syphilis, chlamydia) 1st Wed of the month <nobr>10:30-4pm</nobr>.  The <u>Greeley</u> <a href="http://ncaids.org\">NCAP</a> office is no longer at the Weld County Health Dept.</a>  Visit them at 914 11th Ave, Greeley.  <nobr>970-580-4498</nobr>.  Free HIV and Hepatitis C testing is available every Friday from <nobr>10am-4pm</nobr> by appointment only.  Also <a href="http://www.facebook.com/pages/NCAP-Northern-Colorado-AIDS-Project/274461138607?sk=wall">Facebook</a>.' });
$('#fyi_lambdaYoungAdult').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Young Adult Group at Lambda', CONTENTTEXT:'is for people over 18 who consider themselves young adults, typically 18-30ish.  Everyone is welcome, so bring a friend or just show up.  We see new people all the time, and there are a lot of drop-in folks who come in when they can.  We rotate between social events, outings, movies, discussion, and educational meetings on Thursdays.  For more information email <a href="mailto:lindsay@lambdacenter.org">lindsay@lambdacenter.org</a>.' });
$('#fyi_lambdaEclectic').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Eclectic at Lambda', CONTENTTEXT:'offers education and support for the Transgender community. Meets the 2nd Tuesday of each month from 6:30 - 8:30 for support nights and meets the 4th Tuesday of every month for social activities. Times and meeting places on social nights may change depending on the week.  For more information email Maria at <a href="mailto:mmontano81@gmail.com">mmontano81@gmail.com</a> or Duff at <a href="mailto:duffnoris@gmail.com">duffnoris@gmail.com</a>.' });
$('#fyi_queerReads').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Queer Reads!', CONTENTTEXT:'book group for the GLBTIQ community and allies, sponsored by Fortitude and Lambda Community Center.  For more information contact <a href="mailto:info@ncaids.org">info@ncaids.org</a> or <a href="mailto:lindsay@lambdacenter.org">lindsay@lambdacenter.org</a>.  Or call 970-221-3247' });
$('#fyi_glbtss').data( 'info', { ICON:'icon-pdf', TITLETEXT:'CSU\'s Resource Center', CONTENTTEXT:'on the first floor of the Lory Student Center Rm 174 is committed to providing support services, programs and a safe gathering space for GLBT people, other sexual minorities, and allies of the Colorado State University community.  GLBTSS is now the GLBT Resource Center, GLBTRC.' });
$('#fyi_greeley').data( 'info', { ICON:'icon-pdf', TITLETEXT:'UNC and Greeley\'s GLBT organization', CONTENTTEXT:'For events and activities in the Greeley area, contact the University of Northern Colorado\'s Gay, Lesbian, Bisexual, Transgender and Allies Student Activities Office.  Call Jael Esquibel <nobr>970-351-2906</nobr> or email <a href="mailto:jael.esquibel@unco.edu">jael.esquibel@unco.edu</a>.  Visit their <a href=\"http://www.unco.edu/glbta\">website at www.unco.edu/glbta</a>.' });
$('#fyi_fortitude').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Fortitude', CONTENTTEXT:'The mission of Fortitude is to prevent the spread & stigma of HIV by building a strong community of gay, bisexual, queer &amp; questioning men and promoting equality &amp; justice in Northern Colorado.  Visit their website at <a href="http://ncfortitude.org">ncfortitude.org</a>.' });
$('#fyi_oglbtCity').data( 'info', { ICON:'icon-pdf', TITLETEXT:'City of Fort Collins services for the senior community', CONTENTTEXT:'"<a href=\"http://www.fcgov.com/pathways/\">Enrich</a>" (formerly <i>Pathways</i>) provides a guide to recreation programs and services offered through the City of Fort Collins for people 50 or over.  Click on this link or visit <a href="http://www.fcgov.com/recreation/catalogs/pathways-48.pdf">fcgov.com</a> to download the sizeable pdf document."' });
$('#browserOptions').data( 'info', { ICON:'icon-doc', TITLETEXT:'Recommended and supported browsers:', CONTENTTEXT:'Click <a href="/php/x_info.php">here</a> for detailed browser information.' });

	$('.fyiQtip').each( function() {
		var ID = '#' + $(this).attr('id');
		var ICON = $(ID).data('info').ICON;
		var CONTENTTEXT = $(ID).data('info').CONTENTTEXT;
		var TITLETEXT = $(ID).data('info').TITLETEXT;
		var strToINSERT = '/images/layout/' + ICON + '.gif';
		$(ID).css( 'background','url("' + strToINSERT + '") right top no-repeat');
		$(ID).qtip({
			content: { text: CONTENTTEXT, title: { text: TITLETEXT } },
			position: { corner: { target:'rightMiddle', tooltip:'leftMiddle' } },
			style:{ name:'globalStyle' },
			show: { solo:true },
			hide: { fixed:true }
			});
		});		

		var textString = "<ul class='subPageUL'><li>There are more GLBT persons in the World than there are residents in the United States population of only $population_US. <li>Population statistics are based on U.S. Census Bureau clocks for the <a href='http://www.census.gov/population/www/popclockus.html'>U.S.</a> and the <a href='http://www.census.gov/ipc/www/popclockworld.html'>World</a>. <li>Colorado estimates are from the <a href='http://www.cdphe.state.co.us/scripts/htmsql.exe/cohid/populationPub.hsql'>Colorado Health Info Dataset</a>. <li>GLBT estimates use the conservative <a href='http://www.plu.sg/main/facts_05.htm'>5% portion</a> of adults who self-identify as gay or lesbian.  We update this estimate hourly.</ul>";
		$('#censusInfo').qtip({
			content: { text: textString, title: { text: 'Estimates from census data' } },
			position: { corner: { target:'topMiddle', tooltip:'bottomMiddle' } },
			style:{ border:{ width:2, radius:2 }, 
					tip:{ corner:'bottomMiddle', size: { x:7, y:3 } }, 
					name:'globalStyle' },
			show: { when:'mouseover', solo:true },
			hide: { fixed:true }
			});		
			
		$('#dempseys').qtip({
			content: { text: "<b>Thursday 5:30pm-9pm</b><br>a night out for all of us &mdash; everyone is welcome<br>160 W. Oak Street &mdash; full kitchen and bar", title: { text: '"FoCo Night Out" at Dempsey\'s' } },
			position: { corner: { target:'bottomRight', tooltip:'topMiddle' }, adjust: { x:-50, y:-20 } },
			style:{ textAlign: 'center',
					title: { textAlign: 'center' },
					border:{ width:2, radius:2 }, 
					width: 320,
					tip:{ corner:'topMiddle', size: { x:7, y:15 } }, 
					name:'globalStyle' },
			show: { ready: true, solo: true }
			});		
			
		
	}  //setMainPageQtips()

function setEditorialQtips() {
	$('.editorialPage').each( function() {
				var TITLETEXT = $(this).attr('titleString');
				var BYLINE = $(this).attr('byline');
				var FORMATTED_DATE = $(this).attr('formatted_date');
				var CONTENTTEXT = $(this).attr('textString');
				var PARSEDTITLE = TITLETEXT + '<br><div class="indent40">' + BYLINE + '<br>' + FORMATTED_DATE + '<div>';
		$(this).qtip({
			content: { text:CONTENTTEXT, title: { text:PARSEDTITLE, button:'X' } },
			position: { target: $('#wrapper-inner'), corner:'topMiddle', adjust: { y:30 } },
			style:{ name:'globalSerifStyle', width:600 },
			show: { when:'click', solo:true },
			hide: { fixed: false, when: { event: 'unfocus' } },
			api: {
				beforeShow: function() { $('#qtip-blanket').fadeIn(0); },
				onShow: function() { $('[scrollTo="toTheTop"]').click(); },
				beforeHide: function() { $('#qtip-blanket').fadeOut(0); }
				}
			});
		});
}  // setEditorialQtips()

/*
*/

function setUp_triggerQtip() {
	var TITLETEXT = 'Sorry';
	var CONTENTTEXT = 'Unable to retrieve the page.<br>Please try again later.';
	$('#triggerQtip').qtip({
		content:{ title:{ text:TITLETEXT, button: 'x' }, text:CONTENTTEXT },
		position: { target: $(document.body), corner: 'center' },
		show: { when: 'click', solo: true },
		hide: false,
        style:{ name:'globalStyle', border:{ color:'#000000' }, tip:false },		
		api: { beforeShow: function() { $('#qtip-blanket').fadeIn(1); },
				beforeHide: function() { $('#qtip-blanket').fadeOut(1); }
			}
		});
	}
	
$.fn.qtip.styles.globalStyle = { // Last part is the name of the style
	width:{max:300}, padding:'14px', color:'#222222', textAlign: 'left', backgroundColor:'#ffffff', lineHeight:'150%',
	'font-size':'11px', 'font-family':'Verdana,Tahoma,Helvetica,Arial,sans-serif', 
	border:{ width:2, radius:2, color:'#444444' }, name:'light',
	tip: { corner:'leftMiddle', size: { x:10, y:5 } },
	title:{ color:'#000000', paddingLeft:'5', 'font-size':'11px', 'font-family':'Verdana,Tahoma,Helvetica,Arial,sans-serif', fontWeight:'bold' } 
	}

$.fn.qtip.styles.globalSerifStyle = { // Last part is the name of the style
	width:{max:300}, padding:'14px', color:'#222222', textAlign: 'left', backgroundColor:'#ffffff', lineHeight:'150%',
	'font-size':'14px', 'font-family':'Georiga,"Times New Roman",serif', 
	border:{ width:2, radius:2, color:'#444444' }, name:'light',
	tip: { corner:'leftMiddle', size: { x:10, y:5 } },
	title:{ color:'#000000', paddingLeft:'5', 'font-size':'12px', 'font-family':'Verdana,Tahoma,Helvetica,Arial,sans-serif', fontWeight:'bold' } 
	}

	
/* ----------------- for use by the jqueryRotator ------------------------ */	
	
function jqueryRotatorFn_290x120() {
				$(".container_290x120").wtRotator({
					width:290,
					height:120,
					button_width:10,
					button_height:10,
					button_margin:5,
					auto_start:true,
					delay:4000,
					play_once:false,
					transition:"random",
					transition_speed:300,
					auto_center:false,
					easing:"",
					cpanel_position:"outside",
					cpanel_align:"BC",
					timer_align:"top",
					display_thumbs:true,
					display_dbuttons:true,
					display_playbutton:false,
					display_numbers:false,
					display_timer:false,
					mouseover_pause:true,
					cpanel_mouseover:false,
					text_mouseover:false,
					text_effect:"fade",
					text_sync:false,
					tooltip_type:"none",
					lock_tooltip:true,
					shuffle:true,
					block_size:75,
					vert_size:55,
					horz_size:50,
					block_delay:25,
					vstripe_delay:75,
					hstripe_delay:180			
				});
			}	// jqueryRotatorFn_290x120
	
	
/* ----------------- these are functions for use by fullcalendar.calvis-core.js ------------------------ */

/*	returns a formatted start-end time string for the Gcal and the front page daily Gcal  */
function findTime( beginHH, beginMM, finishHH, finishMM ) {   // receiving 4 integers
	var beginString = ''; var finishString = ''; var returnString = ''; 
	var beginAM = 'am'; var finishAM = 'am'; var spacer = ' ';
	// check for an untimed, day-long entry  FAILS and returns 11:00pm ?!
	if ( beginHH + beginMM + finishHH + finishMM == 0 ) { 
		returnString=''; 
		return returnString; 
		}
		
	// adjust for military time
	if ( beginHH>12 ) { beginHH = beginHH - 12; beginAM='pm'; }
	if ( finishHH>12 ) { finishHH = finishHH - 12; finishAM='pm'; }
	// format to strings
	if ( beginHH==0 && beginMM==0 ) { 
			beginString='mn'; 
			}
		else if (beginHH==12 && beginMM==0 ) {
			beginString='noon';
			}
		else { 
			beginHH = beginHH.toString(); beginMM = beginMM.toString();
			while ( beginMM.length < 2 ) { beginMM = '0' + beginMM; }
			beginString = beginHH + ':' + beginMM + beginAM;
			}
	if ( finishHH==0 && finishMM==0 ) { 
			finishString='midnight'; 
			}
		else if (finishHH==12 && finishMM==0 ) {
			finishString='noon';
			}
		else { 
			finishHH = finishHH.toString(); finishMM = finishMM.toString();
			while ( finishMM.length < 2 ) { finishMM = '0' + finishMM; }
			finishString = finishHH + ':' + finishMM + finishAM;
			}
	// concatenate strings
	if ( beginString == finishString ) {
			returnString = beginString + spacer;
			return returnString;
			}
		else {
			returnString = beginString + '-' + finishString + spacer;
			return returnString;
			}
    }  // findTime()

/*  create the Regexs before using  */
var bbRegexArray = [ 
    { reg : /\[b\](.*?)\[\/b\]/gi,  repl: "<b>$1</b>" },
    { reg : /\[i\](.*?)\[\/i\]/gi,  repl: "<i>$1</i>" },
    { reg : /\[u\](.*?)\[\/u\]/gi,  repl: "<u>$1</u>" },
	{ reg : /\[br\]/gi,  			repl: "<br>" },
	{ reg : /\[nobr\](.*?)\[\/nobr\]/gi,  			repl: "<nobr>$1</nobr>" },
    { reg : /\[color=(.*?)\](.*?)\[\/color\]/gi,    repl: "<span style='color: $1'>$2</span>" },
                
    { reg : /\[img=(.*?)\]/gi,                      repl: "<img src='$1'>" },
    { reg : /\[a=(.*?)\](.*?)\[\/a\]/gi, 	        repl: "<a href='$1'>$2</a>" },  // removed target=_blank
    { reg : /\[mailto=(.*?)\](.*?)\[\/mailto\]/gi,  repl: "<a href='mailto:$1'>$2</a>" },
    { reg : /\[li\](.*?)\[\/li\]/gi,  				repl: "<li class='cal'>$1</li>" },
                
    { reg : /\[(lambda|lambda community center)\]/gi,       repl : "<a href='http://lambdacenter.org'>$1</a>" },
    { reg : /\[(lambda center)\]/gi,       					repl : "<a href='http://lambdacenter.org'>$1</a>" },
    { reg : /\[(fox bar)\]/gi,       					repl : "<a href='http://foxbarfc.com'>$1</a>" },
    { reg : /\[(pflag)\]/gi,                     repl : "<a href='http://pflatftc.org'>$1</a>" },
    { reg : /\[(glbtss|glbtrc)\]/gi,             repl : "<a href='http://glbtss.colostate.edu'>$1</a>" },
    { reg : /\[(unc glbta)\]/gi,                 repl : "<a href='http://www.unco.edu/glbta'>$1</a>" },
    { reg : /\[(ncap|Northern Colorado AIDS Project)\]/gi,                      repl : "<a href='http://ncaids.org'>$1</a>" },
    { reg : /\[(Out on the Town)\]/gi,           repl : "<a href='http://lgbtfriends.meetup.com/193/'>$1</a>" },
    { reg : /\[(10percent.com)\]/gi,             repl : "<a href='http://10percent.com/index.cfm?refid=YH20906'>$1</a>" },
    { reg : /\[(Choice City Shots)\]/gi,         repl : "<a href='http://www.choicecityshots.com'>$1</a>" },
    { reg : /\[(StPaul|Saint Paul)\]/gi,         repl : "<a href='http://www.stpauls-fc.org/'>$1</a>" },
    { reg : /\[(Namaqua Unitarian)\]/gi,         repl : "<a href='http://www.namaquauu.org/'>$1</a>" },
    { reg : /\[(FUC|Foothills Unitarian)\]/gi,   repl : "<a href='http://www.foothillsuu.org/'>$1</a>" },
	{ reg : /\[(Fortunate Familes)\]/gi,   repl : "<a href='http://www.fortunatefamilies.org/'>$1</a>" },
    { reg : /\[(Lyric Cinema Cafe)\]/gi,         repl : "<a href='http://lyriccinemacafe.com'>$1</a>" },
    { reg : /\[(PCC|Plymouth Congregational Church)\]/gi,   repl : "<a href='http://www.plymouthucc.org/'>$1</a>" },
    { reg : /\[(Manhood|Fortitude)\]/gi,         repl : "<a href='http://www.facebook.com/pages/NCAP-Northern-Colorado-AIDS-Project/274461138607'>$1</a>" },
    { reg : /\[(MCC|Family in Christ)\]/gi,      repl : "<a href='http://www.fortnet.org/mccfic'>$1</a>" },
    { reg : /\[(Lutheran Campus Ministry)\]/gi,  repl : "<a href='http://www.lcm.colostate.edu/'>$1</a>" },
    { reg : /\[(The Tap Room)\]/gi,  	  	    repl : "<a href='http://taproomfortcollins.com/'>$1</a>" },
    { reg : /\[(Liberal Ladies Lunch)\]/gi,     repl : "<a href='http://www.meetup.com/Liberal-Ladies-Lunch'>$1</a>" },
    { reg : /\[(Avogadro's|Avo's)\]/gi,     repl : "<a href='http://www.avogadros.com/'>$1</a>" },
	{ reg : /\[(Northern Harmony Chorale)\]/gi,     repl : "<a href='http://www.harmonychorale.org'>$1</a>" },
    { reg : /\[(bcb)\]/gi,     				repl : "<a href='http://fortpride.org/pages/bcb-newsletter.pdf'>$1</a>" },
    { reg : /\[(OGLBT)\]/gi,                     repl : "<a href='http://fortpride.org/pages/oglbt-newsletter.doc'>$1</a>" },
    { reg : /\[(SOGLBT)\]/gi,                     repl : "<a href='http://www.facebook.com/group.php?gid=114347588596064'>$1</a>" }
    // { reg : /()/i,                         repl : "<a href='http://'>$1</a>" },
];  

/*  converts bracketed codes in Gcal to html tags  */
function bbCodes ( someCalStr ) {
	for ( var i=0; i<bbRegexArray.length; i++ ) {
        someCalStr = someCalStr.replace( bbRegexArray[i].reg, bbRegexArray[i].repl );
    	}
	return someCalStr;
	}  // bbCodes()

/*  pair of functions to limit the data returned for the frontpage Gcal list  */
function formatTodayDate() {
	var todayDate = new Date();
	var yyyy = todayDate.getFullYear().toString();
	var mm = ( todayDate.getMonth() + 1 ).toString();
		if ( mm.length==1 ) { mm = '0' + mm; }
	var dd = todayDate.getDate().toString();
		if ( dd.length==1 ) { dd = '0' + dd; }
	return yyyy + mm + dd;
	}  formatTodayDate()
function formatTomorrowDate() {
	var tomorrowDate = new Date();
	tomorrowDate.setDate( tomorrowDate.getDate + 1);
	var yyyy = tomorrowDate.getFullYear().toString();
	var mm = ( tomorrowDate.getMonth() + 1 ).toString();
		if ( mm.length==1 ) { mm = '0' + mm; }
	var dd = tomorrowDate.getDate().toString();
		if ( dd.length==1 ) { dd = '0' + dd; }
	return yyyy + mm + dd;
	}  // formatTomorrowDate()
function displayTodayDate() {			// date is MDT because of the serverbeach TZ setting
	var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
	    'October', 'November', 'December'];
	var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
	var d = new Date();
	var td = new Date();
	var dow = td.getDay();
	var mth = td.getMonth();
	var dat = td.getDate().toString();
	dow = '' + DAYS[ dow ];
	mth = '' + MONTHS[ mth ];
	var dateString = dow + ', ' + mth + ' ' + dat ;
	return dateString;
	}  // displayTodayDate()
/*  JavaScript ISO8601/RFC3339 Date Parser
 *  http://dansnetwork.com/2008/11/01/javascript-iso8601rfc3339-date-parser/
 */
Date.prototype.setISO8601 = function(dString){

    var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;

    if (dString.toString().match(new RegExp(regexp))) {
        var d = dString.match(new RegExp(regexp));
        var offset = 0;
        this.setUTCDate(1);
        this.setUTCFullYear(parseInt(d[1],10));
        this.setUTCMonth(parseInt(d[3],10) - 1);
        this.setUTCDate(parseInt(d[5],10));
        this.setUTCHours(parseInt(d[7],10));
        this.setUTCMinutes(parseInt(d[9],10));
        this.setUTCSeconds(parseInt(d[11],10));
        if (d[12])
            this.setUTCMilliseconds(parseFloat(d[12]) * 1000);
        else
            this.setUTCMilliseconds(0);
        if (d[13] != 'Z') {
            offset = (d[15] * 60) + parseInt(d[17],10);
            offset *= ((d[14] == '-') ? -1 : 1);
            this.setTime(this.getTime() - offset * 60 * 1000);
            }
        }
    else {
        this.setTime(Date.parse(dString));
        }
    return this;
    };
/* ----------------- END of functions for use by fullcalendar.calvis-core.js ------------------------ */


	
	
	
	
	
/* __________________________________________________________________________________________________ */

