﻿	
function showMediaTab(name) {
	
	var selectedIndex = -1;
	
	// go through all
	for (var i=0; i<mediaTabList.length; i++) {
	
		if (mediaTabList[i] == name)
			selectedIndex = i;
		
		// un highlight tab
		$(mediaTabList[i] + 'Tab').className = '';
		
		// special padding on the first one
		if (i==0 && i!= selectedIndex)
			$(mediaTabList[i] + 'Tab').className = 'unselectedFirst';
		

		// hide div
		$(mediaTabList[i] + 'List').style.display = 'none';
	}
	
	
	if (selectedIndex > -1) {
	
		$(mediaTabList[selectedIndex] + 'Tab').className = 'selectedTabItem';//'selected'+number+'TabAnchor';
		
		if (selectedIndex > 0) {
			$(mediaTabList[selectedIndex] + 'Tab').className = 'selectedTabItem selectedTabItem'+ (selectedIndex+1);
		}
		
		$(mediaTabList[selectedIndex] + 'List').style.display = '';
		
		$('ListingScrollArea').scrollTop = 0;
	}
}



document.observe('contentloaded',function() {	
	// hook up events to tabs
	if (typeof(mediaTabList) == 'undefined' || mediaTabList == null)
		return;
		
		return;
	
	for (var i=0; i<mediaTabList.length; i++) {
		//alert('setting up' + tabLink);
		var tabLink = $(mediaTabList[i] + 'Tab');	
		tabLink.area = tabLink.href.substring(tabLink.href.indexOf('#')+1);	
		tabLink.href = 'javascript:void(0);';
		tabLink.onclick = function() { 
			//alert('test');
			showMediaTab(this.area);
			this.blur();
		};
	}
	
	// find the previously selected tab
	var url = document.location.href;
	if (url.indexOf('#') != -1) {
		var section = url.substring(url.indexOf('#')+1);
		
		if (section != '')
			showMediaTab(section);
	}
});
