Event.observe(window, "load", function() {
	
	// Add <div class="hr"> to each hr
	$$('hr').each(function(i) {
		i.wrap('div').addClassName('hr');
	});
	
	// Wrap #side htmlcomponents with div#photo
	//$$('#side .XEComponentHTML').each(function(i) {
	//	i.wrap('div').addClassName('photo');
	//});
	
	// Add class names to tag-cloud
	var count = 0;
	$$('#tag-cloud li').each(function(i) {
		i.addClassName('tag' + count++ % 10);
	});
	
	$$('.OzExSpeechBubbleComponent').each(function(i, n) {
		if (i.down('img')) {
			var img = i.down('img');
			i.setStyle( { background: 'url(' + img.src + ') no-repeat 0 11px' } );
			img.remove();
		}
	});
	
	// Username/password functionality
	$$('#username, #password').each(function(i) {
		if (!i.value) i.addClassName(i.readAttribute('id'));
		i.observe('focus', clearBackground);
		i.observe('blur', setBackground);
	});
	function clearBackground(event) {
		input = Event.element(event);
		input.removeClassName(input.readAttribute('id'));
	}
	function setBackground(event) {
		input = Event.element(event);
		if (!input.value) {
			input.addClassName(input.readAttribute('id'));
		}
	}
	
  $$('.help').each(function(i) {
    var html = '<div class="top"></div><div class="body">' + i.title + (i.href ? ' <a href="'+i.href+'">More info</a>.' : '') + '</div><div class="bottom"></div>';
  	new Control.Modal(i, {
      hover: true, position: 'relative', fade: true, offsetLeft: -31, offsetBottom: 0, contents: html
    });
    i.setAttribute('title', null);
  });

	// Setup lightwindow on flickr galleries
	$$(".FlickrComponent").each(function(i) {
		galleryName = i.down('h2').innerHTML;
		i.getElementsBySelector('a').each(function(i) {
			i.rel = "Gallery[" + galleryName + "]";
			i.className = "lightwindow";
		});
	});
	lightwindowInit();
	
	// Wiki popup
	$$('.WikiComponent a[title^="Edit "]').each(function(i) {
		i.onclick = function() {
			myLightWindow.activateWindow({
				type: 'external',
				href: i.href, 
				title: i.title,
				width: 800,
				height: 500,
				overlay: {
				    opacity: 0.3,
				    image: 'images/black.png',
				    presetImage: 'images/black-30.png'
				}
			});
			return false; 
	  }; 
	});
	
	// Social bookmarks
	$$('#bookmarks li a').each(function(i) {
    var template = new Template(i.href);
    i.href= template.evaluate({title: document.title, url: document.documentURI, keywords: ""});
    i.onclick = function() {
			myLightWindow.activateWindow({
				type: 'external',
				href: i.href, 
				title: i.title,
				width: 620,
				height: 420,
				overlay: {
				    opacity: 0.3,
				    image: 'images/black.png',
				    presetImage: 'images/black-30.png'
				}
			});
			return false; 
	  }; 
  });
  
  // Add flickr reflections
  $$('#fullwidth .FlickrComponent img').each(function(i) {
  	Reflection.add(i, { height: 3/4, opacity: 1/4 });
  });
  
});

function updateparent() {
new Ajax.Updater($$('.wikiContent').first(), document.getElementById('updateurl').innerHTML, { });
}
