/*
 * Javascript helper functions.
 * 
 * $Author: brucemyers $ 
 * $Date: 2008-03-12 19:15:48 -0400 (Wed, 12 Mar 2008) $ 
 */

 function toggleMarket(market_id) {
 	var market = 'market' + market_id
 	
 	if ($(market).visible()) {
 		$(market).hide()
 	} else {
 		$(market).show()
 		if ($(market).empty()) {
 			$(market).update("Loading...")
			new Ajax.Updater(market, 'market.php', { 
				parameters: { mktid: market_id, request: 'get_market' } 
			}); 
 		}
 	}
 }

 function toggleStation(station_id) {
 	var station = 'station' + station_id
 	
 	if ($(station).visible()) {
 		$(station).hide()
 	} else {
 		$(station).show()
 	}
 }
 
 function expandAllStations(dma_id) {
 	var startsWith = 'station_' + dma_id + '_'
 	var hideAll = true
 	var stations = $('market' + dma_id).descendants()
 	stations.each(function(e) {
 		if ($(e).id.startsWith(startsWith)) {
 			if (!e.visible()) {hideAll = false;  throw $break}
 		}
 	})
 	
 	stations.each(function(e) {
 		if ($(e).id.startsWith(startsWith)) {
 			if (hideAll) e.hide()
 			else e.show()
 		}
 	})
 }

 // Toggle grandparents color.
 function toggleGPColor(node, station_id, invisible_color, visible_color) {
 	ancestors = $(node).ancestors()
 	var station = 'station' + station_id
 	
 	if ($(station).visible()) {
 		ancestors[1].setStyle({ backgroundColor: visible_color })
 	} else {
 		ancestors[1].setStyle({ backgroundColor: invisible_color })
 	}
 }
 
