/*
 *	/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  */
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':'#006eb3', 'cursor':'pointer' });
			$('ul.mainMenu a').not('.subHeader').hover( 
				function() { $(this).css({ 'text-decoration':'underline' }); },
				function() { $(this).css({ 'text-decoration':'none' }); }
				);
			$(this).css({ 'color':'#e62b00', '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':'#e62b00', 'cursor':'none' });
			$('ul.subMenu').trigger('mouseleave');
			});
	

	/*  set main menu links  */
	$('#home').css({ 'color':'#e62b00', '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; });
		$('.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 });
		$('#countdownTimerNews').flash ({
			swf: '/shows/countdown.swf', wmode:'opaque', width: 290, height: 90, hasVersion: 9 });
		$('#belowHistory').flash ({
			swf: '/shows/belowHistory.swf', wmode:'opaque', width: 290, height: 330, hasVersion: 9 });
		$('#mediaPlayer').flash ({	
			swf: '/shows/frontPageStaticAlbum.swf', wmode:'opaque', width: 290, height: 210, hasVersion: 9 });
			
			
/*			
		$('#mediaPlayer').flash ({
			swf: '/shows/mediaPlayer.swf', width: 290, height: 237, wmode: 'opaque', hasVersion: 9, id: 'mP', name: 'mP',
			params: { allowscriptaccess: 'always', allowfullscreen: 'true' },
			flashvars: { playlistfile: '/shows/mediaPlayer/mediaPlayer.xml', backcolor: 'bababa', frontcolor: '005488', screencolor: 'dddddd' }
			});
		$(window).unload( function() {
			$('#mediaPlayer').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 );
												htmlString += displayTime;
												
											var title = this.title['$t'];
												title = bbCodes ( title );
												htmlString += title + "<br>";
											var content = this.content['$t'];
												content = bbCodes ( content );
												htmlString += 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_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 mailto:"kstieber@fcgov.com">kstieber@fcgov.com</a>' });
$('#fyi_lambda').data( 'info', { ICON:'icon-pdf', TITLETEXT:'Lambda Community Center', CONTENTTEXT:'is our community\'s resource for support groups, youth acitivities, and our annual "Pride in the Park" each summer.  Don\'t hesitate to contact their executive director Andy Stoll at <nobr>221-3247</nobr> or <a href="andy@lambdacenter.org">andy@lambdacenter.org</a>.' });
$('#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.' });
$('#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 }
			});		
		
	}  //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:'globalStyle', 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:'#444444', textAlign: 'left', backgroundColor:'#ffffff', lineHeight:'150%',
	'font-size':'11px', 'font-family':'Tahoma,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':'Tahoma,sans-serif', fontWeight:'bold' } 
	}

/* ----------------- 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 : /\[(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 : /\[(FUC|Foothills Unitarian)\]/gi,   repl : "<a href='http://www.foothillsuu.org/'>$1</a>" },
    { reg : /\[(Namaqua Unitarian)\]/gi,         repl : "<a href='http://www.namaquauu.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 : /\[(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 : /()/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 ------------------------ */


	
	
	
	
	
/* __________________________________________________________________________________________________ */
