// Called when "UseAdvancedJS" metadata set on a content block
// requires jQuery and jTools

$(document).ready( function() {
	initAdvanced();

});
/*
function prepareVideoLinks(){
	if(!getElementsByClassName(document, 'a', 'openFlashVideo')) return;
	var links = getElementsByClassName(document, 'a', 'openFlashVideo');
	for (var i=0; i<links.length; i++){
		links[i].onclick = function(){
			playRtmpVideo(this.getAttribute('rel'), "videoLink", true);
			return false;
		}
	}
}
*/
function prepareVideoLinks(){
	
	if (!$('.openFlashVideo')){
		return;
	}
	var $flashVideoLinks = $('.openFlashVideo');

	$flashVideoLinks.each(function(index){
	
		function clickHandler(){
		
			playRtmpVideo($(this).attr('rel'), "videoLink"+index, true);
		}
		
		$(this).click(clickHandler);
	});

}

function initAdvanced() {
	//highslide
		prepareVideoLinks();
		
	//Tabs
	$("ul.jqToolsTabs").tabs("div.jqToolsPanes > div");

	//ProgressiveDisclosure
	setLearnMore();
	
	//Fades
	fadeInOut('fadeEvents', 0, 'in');
	
	//Accordions
	$("#jqToolsAccordion").tabs("#jqToolsAccordion div.jqToolsPane", {
		tabs: 'h2'
	});

	return true;
}

function setLearnMore(){
	$('.jqShowMore').bind('click', function(){
		var showDiv = $(this).next('.jqShowHide');
		showDiv.show();
		$(this).hide();
		return false;
	});
	
	$('.jqHideMore').bind('click', function(){
		var parent = $(this).closest('.jqShowHide');
		parent.hide();
		var learnMore = $(this).closest('.jqShowHide').prev('.jqShowMore');
		learnMore.show();
		return false;
	
	});
}

function showLocatorTable(region) 
{	
	$("div.div_locator,table").hide();
	$("#" + region.value+"Table").show();			
}


