
function prepare_media_panel() {
	if (!document.getElementById) return false;
	if (!document.getElementById('media_panel')) return false;
	
	var $media_panel = document.getElementById('media_panel');
	var $paragraph = document.createElement('p');
	$paragraph.setAttribute('id','media_panel-navigation');
	
	var $divs = $media_panel.getElementsByTagName('div');
	for (var $i=0; $i<$divs.length; $i++) {
		if ($divs[$i].className != 'section') continue;
		if ($i>0) var $divider = document.createTextNode(' | ');
		
		var $section_title = $divs[$i].getAttribute('title');
		var $section_id = $divs[$i].getAttribute('id');
		
		var $link = document.createElement('a');
		$link.setAttribute('title',$section_title+' I Like');
		$link.setAttribute('section_id',$section_id);
		$link.onclick = function() {
			var $parent_node = this.parentNode;
			var $links = $parent_node.getElementsByTagName('a');
			for (var $i=0; $i<$links.length; $i++) {
				$links[$i].className = '';
			}
			this.className = 'selected';
			
			$parent_node = $parent_node.parentNode;			
			var $divs = $parent_node.getElementsByTagName('div');
			for (var $i=0; $i<$divs.length; $i++) {
				if ($divs[$i].className != 'section') continue;
				if ($divs[$i].getAttribute('id') != this.getAttribute('section_id')) {
					$divs[$i].style.zIndex = '1';
					var $child_divs = $divs[$i].getElementsByTagName('div');
					for (var $j=0; $j<$child_divs.length; $j++) {
						$child_divs[$j].style.display = 'none';
						$child_divs[$j].style.zIndex = '1';
					}
				}
				else {
					$divs[$i].style.zIndex = '2';
					var $child_divs = $divs[$i].getElementsByTagName('div');
					for (var $j=0; $j<$child_divs.length; $j++) {
						$child_divs[$j].style.display = 'block';
						$child_divs[$j].style.zIndex = '3';
					}
				}
			}
		}
		
		var $text = document.createTextNode($section_title);
		$link.appendChild($text);
		
		// Photo section specific
		if ($section_id == 'mp-photo') {
			var $old_content = $divs[$i].getElementsByTagName('p')[0];
			var $parent_node = $old_content.parentNode;
			$parent_node.removeChild($old_content);
			$link.className = 'selected';
		}
		
		if ($divider) $paragraph.appendChild($divider);
		$paragraph.appendChild($link);
	}
	$media_panel.insertBefore($paragraph,$divs[0]);
}
addLoadEvent(prepare_media_panel);
