//media archive
function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var e = document.getElementById(whichLayer)
e.style.display = e.style.display == "block" ? "none":"block";
}
}
//wimpy player
function wimpyPopPlayer(theFile,id,stuff) {
  window.open(theFile,id,stuff);
}

//flash stuff
var currentItem;

function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};


function loadFile(swf,obj) { 
  thisMovie(swf).loadFile(obj); 
  
};

	function getUpdate(typ,pr1,pr2,pid) {
		if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
	};

	function getItemData(idx) {		
		if(thisMovie("header_flash")){
		var obj = thisMovie("header_flash").itemData(idx);
			if(obj['link']){
				document.getElementById("from_flash").innerHTML = '<a href="'+obj["link"]+'"><div class="click_frame"></div></a>';
			}else{
				document.getElementById("from_flash").innerHTML = '<div class="click_frame"></div>'; 
			}
		}
		if(thisMovie("sermon_video")){
		var obj = thisMovie("sermon_video").itemData(idx);
		document.getElementById("sermontitle").innerHTML = obj["title"];
		document.getElementById("sermondescript").innerHTML = obj["link"];  
		}
		
	};

	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};
	
function toggle_visibility(id) {
     var e = document.getElementById(id);
     if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
	

/**
 * Converts an xs:date or xs:dateTime formatted string into the local timezone
 * and outputs a human-readable form of this date or date/time.
 *
 * @param {string} gCalTime is the xs:date or xs:dateTime formatted string
 * @return {string} is the human-readable date or date/time string
 */
function formatGCalTime(gCalTime) { 
  // text for regex matches
  var remtxt = gCalTime;

  function consume(retxt) {
    var match = remtxt.match(new RegExp('^' + retxt));
    if (match) {
      remtxt = remtxt.substring(match[0].length);
      return match[0];
    }
    return '';
  }

  // minutes of correction between gCalTime and GMT
  var totalCorrMins = 0;

  var year = consume('\\d{4}');
  consume('-?');
  var month = consume('\\d{2}');
  consume('-?');
  var dateMonth = consume('\\d{2}');
  var timeOrNot = consume('T');
	
	var month_str=new Array(12);
				month_str[0]="January";
				month_str[1]="February";
				month_str[2]="March";
				month_str[3]="April";
				month_str[4]="May";
				month_str[5]="June";
				month_str[6]="July";
				month_str[7]="August";
				month_str[8]="September";
				month_str[9]="October";
				month_str[10]="November";
				month_str[11]="December";
	

  // if a DATE-TIME was matched in the regex 
  if (timeOrNot == 'T') {
    var hours = consume('\\d{2}');
    consume(':?');
    var mins = consume('\\d{2}');
    consume('(:\\d{2})?(\\.\\d{3})?');
    var zuluOrNot = consume('Z');

    // if time from server is not already in GMT, calculate offset
    if (zuluOrNot != 'Z') {
      var corrPlusMinus = consume('[\\+\\-]');
      if (corrPlusMinus != '') {
        var corrHours = consume('\\d{2}');
        consume(':?');
        var corrMins = consume('\\d{2}');
        totalCorrMins = (corrPlusMinus=='-' ? 1 : -1) * 
            (Number(corrHours) * 60 + 
	    (corrMins=='' ? 0 : Number(corrMins)));
      }
    } 

    // get time since epoch and apply correction, if necessary
    // relies upon Date object to convert the GMT time to the local
    // timezone
    var originalDateEpoch = Date.UTC(year, month - 1, dateMonth, hours, mins);
    var gmtDateEpoch = originalDateEpoch + totalCorrMins * 1000 * 60;
    var ld = new Date(gmtDateEpoch);


    // date is originally in YYYY-MM-DD format
    // time is originally in a 24-hour format
    // this converts it to MM/DD hh:mm (AM|PM) 
    dateString = (month_str[ld.getMonth()]) + ' ' + ld.getDate() + ', ' + 
        ((ld.getHours()>12)?(ld.getHours()-12):(ld.getHours()===0?12:
	ld.getHours())) + ':' + ((ld.getMinutes()<10)?('0' + 
	ld.getMinutes()):(ld.getMinutes())) + ' ' + 
	((ld.getHours()>=12)?'PM':'AM');
  } else {
    // if only a DATE was matched
    dateString =  month_str[parseInt(month, 10)-1] + ' ' + parseInt(dateMonth, 10);
  }
  return dateString;
}
	
	