var verticalAccordion;

addEvent(window, 'DOMContentLoaded', function(){
   load_accordions();
   watch_prompts();
});

function watch_prompts()
{
   $$('div.search_prompt').each(function(x){
      $(x).observe('mouseover', function(e) { Event.findElement(e, 'div').addClassName('rolledover'); });
   });
   $$('div.search_prompt').each(function(x){
      $(x).observe('mouseout', function(e) { Event.findElement(e, 'div').removeClassName('rolledover'); });
   });
   $$('div.search_prompt').each(function(x){
      $(x).observe('click', function(e) { handle_search(e); });
   });
}

function handle_search(e)
{
   offender = Event.findElement(e, 'div');
   victim = offender.next();
   var search_term;
   $(offender).classNames().each(function(name) { if (/search_for_(.*)/i.test(name)) search_term = RegExp.$1; });
   new Ajax.Updater(victim, '/training/videos', {
      parameters: { term: search_term }
   });
}

function load_accordions()
{
   ['column1', 'column2', 'column3'].each(function(col){ new accordion(col, {
      resizeSpeed: 9,
      classNames : {
         toggle : 'search_prompt',
         toggleActive : 'search_prompt_active',
         content : 'search_result'
      },
      direction: 'vertical',
      defaultSize: { height : null,  width : null }
   }); });
}

// Given a key, replace the content of the div 'video_player' with the new video 
function loadVideo(myKey) {
	var myVidDiv = document.getElementById('video_player');
	var myEmailLinkDiv = document.getElementById('email_to_a_friend');
	
	myVidDiv.innerHTML = '<embed allowScriptAccess="always" src="http://video.sparqtraining.com/api3/sparq.swf?cf=small&key='+myKey+'" width="330" height="280"></embed>';
	myEmailLinkDiv.innerHTML = '<a href="/training/email?key='+myKey+'">Send this video to a friend</a>';
}
