function showPhotos() {
  document.getElementById('photos').style.width = '100%';
  document.getElementById('photos').style.cssFloat = 'none';
  document.getElementById('photos').style.marginLeft = '0px';
  document.getElementById('photos').style.marginRight = '10px';
  document.getElementById('photos').style.borderLeft = '0px';
  document.getElementById('photos').style.borderTop = '1px solid #c00';
  document.getElementById('photos').style.borderBottom = '1px solid #c00';
  document.getElementById('photos').style.padding = '10px';
  document.getElementById('more_photos').style.display = 'block';

  d = document.getElementById('photos_switch').firstChild;
  if (d) { d.parentNode.removeChild(d); }
  var div = document.createElement('div');

  var a = document.createElement('a');
  a.setAttribute('href', 'javascript:hidePhotos();');
  a.appendChild(document.createTextNode('Fewer Photos'));
  div.appendChild(a);
  document.getElementById('photos_switch').appendChild(div);
}

function hidePhotos() {
  document.getElementById('photos').style.width = '150px';
  document.getElementById('photos').style.cssFloat = 'right';
  document.getElementById('photos').style.borderLeft = '1px solid #c00';
  document.getElementById('photos').style.borderTop = '0px';
  document.getElementById('photos').style.borderBottom = '0px';
  document.getElementById('photos').style.padding = '0px';
  document.getElementById('photos').style.paddingLeft = '10px';
  document.getElementById('photos').style.marginLeft = '10px';
  document.getElementById('photos').style.marginRight = '10px';
  document.getElementById('more_photos').style.display = 'none';

  d = document.getElementById('photos_switch').firstChild;
  if (d) { d.parentNode.removeChild(d); }
  var div = document.createElement('div');

  var a = document.createElement('a');
  a.setAttribute('href', 'javascript:showPhotos();');
  a.appendChild(document.createTextNode('More Photos'));
  div.appendChild(a);
  document.getElementById('photos_switch').appendChild(div);
}

function setActiveStyleSheet(title) {
 var i, a, main;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
   if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
     a.disabled = true;
     if(a.getAttribute("title") == title) a.disabled = false;
   }
 }
}

function hide_element(id) {
Effect.Fade(id, { duration: 0.1 });
}

function show_element(id) {
Effect.Appear(id, { duration: 0.1 }) ;
}

function toggle_element(id) {
Effect.toggle(id,'blind', { duration: 0.1 });
}

function first_visit_today(){
	if (readCookie('donate')) {
		return false;  // seen it today!
	}
	document.cookie = "test=cookiesEnabled";
	var pos = document.cookie.indexOf( "test=" );
	if( pos == -1 )	{ 
		return false; // we can't set cookies, so don't be annoying!
	}
	return true;
}

function show_popup(){
	if (first_visit_today()) {
		createCookie('donate','seen it', 1);  // only do this once per day
		$('popup_bg').setOpacity(0.7);
		$('popup').show();
		resizePopupBg('popup_bg');
		$('popup_bg').observe('click', function(){
			hide_popup(); // clicking the bg closes the popup
		});
		$('popup').scrollTo(); // jump to top of page
		$('pop_donate_button').observe('click',function(){
			hide_popup();
			document.location.pathname = '/donate/ye08-splash';
		});
		$('pop_cancel_button').observe('click',function(){
			hide_popup();
		});	
		$('swfplayer') && $('swfplayer').hide();		
	}
}
function hide_popup(){
	$('popup').hide();
	$('swfplayer') && $('swfplayer').show();
}

function resizePopupBg(div){
	// resize the background
	body_size    = $('site_wrapper').getDimensions();
	width  = [ document.viewport.getWidth(),  body_size.width ].max();
	height = [ document.viewport.getHeight(), body_size.height].max();
	$(div).setStyle('width: '  + width  + 'px');
	$(div).setStyle('height: ' + height + 'px');
}

// Cookie management, via http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}