// Setup variables for objects
var categoryList;
var videoTranscript;
var contentData;
var actionTabs;

// How do we handle the action items when very first clicked (its like a 3 stage accordion)
var actionItems = {
	resetCaller: function(id) {
		actionItems.reset({'id': id});
	},
	
  reset: function(event) {
		
    id = (event.id) ? event.id : $(event.currentTarget).id;
		
    // Kill the observers
    // Event.stopObserving('action_contact', 'click', actionItems.boundReset);
    // Event.stopObserving('action_call', 'click', actionItems.boundReset);
    // Event.stopObserving('action_email', 'click', actionItems.boundReset);
    // Event.stopObserving('action_contact_headers', 'click', actionItems.boundReset);
    // Event.stopObserving('action_call_headers', 'click', actionItems.boundReset);
    // Event.stopObserving('action_email_headers', 'click', actionItems.boundReset);

    var containers = [];

		
        // if (id != 'action_contact' && id != 'action_contact_headers') {
        //   containers.push(
        //     new Effect.Morph('action_contact_content', {sync: true, style: {width: '0px'}})
        //   );
        // } 
        // if (id != 'action_call' && id != 'action_call_headers') {
        //   containers.push(
        //     new Effect.Morph('action_call_content', {sync: true, style: {width: '0px'}})
        //   );
        // } 
        // if (id != 'action_email' && id != 'action_email_headers') {
        //   containers.push(
        //     new Effect.Morph('action_email_content', {sync: true, style: {width: '0px'}})
        //   );          
        // }
    
    
    // new Effect.Parallel(containers, {
    //  duration: 0.5,
    //  afterFinish: function() {
    //    actionTabs.scaleFrom = 0;
    //  }
    // });
		
		
	
  }
};

// Load everything we need for the Video System
var videoSystem = {
  initialize: function() {
    //
    // Seup Scrollbars
    //
    Event.observe('content_transcripts_title', 'click', videoSystem.hideScrollbars);

    //
    // Setup Accordions
    //
    contentData = new Accordion('content_container_data', {toggleWithPrevious: true});
    //    
    // actionTabs = new Accordion('action_container', {
    //                      classNames : {
    //                        toggle : 'horizontal_accordion_toggle',
    //                        toggleActive : 'horizontal_accordion_toggle_active',
    //                        content : 'horizontal_accordion_content'
    //                      },
    //                      defaultSize : {
    //                        width : 598
    //                      },
    //                      direction : 'horizontal'
    //                    });
    // 
    // actionTabs.scaleFrom = 33.83; /* (203/600)*100 */
    // 
    $('content_list_content').setStyle({
      height: '233px',
      display: 'block'
    });
    
    contentData.showAccordion = $('content_list_content');
    // 
    // //
    // // Setup initial stage of accordions'
    // //      
    actionItems.boundReset = actionItems.reset.bindAsEventListener(actionItems);
    // 
    // Event.observe('action_contact', 'click', actionItems.boundReset);
    // Event.observe('action_call', 'click', actionItems.boundReset);
    // Event.observe('action_email', 'click', actionItems.boundReset);
    //    
    // var actionStyle = {
    //   width: '200px',
    //   display: 'block'
    // }
    // 
    // $('action_contact_content').setStyle(actionStyle);
    // $('action_call_content').setStyle(actionStyle);
    // $('action_email_content').setStyle(actionStyle);
    //    
    // //
    // // Make the headers of the contents of the accordion open the accordion
    // //
    // 
    // Event.observe('action_contact', 'click', function() {actionItems.resetCaller('action_contact');});
    // Event.observe('action_call', 'click', function() {actionItems.resetCaller('action_call');});
    // Event.observe('action_email', 'click', function() {actionItems.resetCaller('action_email');});
    // 
    // Event.observe('action_contact_headers', 'click', actionTabs.activate.bind(actionTabs, $('action_contact')));
    // Event.observe('action_call_headers', 'click', actionTabs.activate.bind(actionTabs, $('action_call')));
    // Event.observe('action_email_headers', 'click', actionTabs.activate.bind(actionTabs, $('action_email')));
    // 
    // Event.observe('action_contact_headers', 'click', function() {actionItems.resetCaller('action_contact');});
    // Event.observe('action_call_headers', 'click', function() {actionItems.resetCaller('action_call');});
    // Event.observe('action_email_headers', 'click', function() {actionItems.resetCaller('action_email');});
		
    //Event.observe('close', 'click', function() { alert('I should close lightWindow!'); }, false);

	},
	
	selectFirstCategory: function() {
		elm = $$('#category_list li a').first();
		elm.addClassName('selected');
		this.activeCategory = elm.id.replace(/category_/,'');
	},
	
	selectFirstVideo: function() {
		elm = $$('a.video_listing').first();
		elm.addClassName('selected');
		this.activeVideo = elm.id.replace(/video_/,'');
	},
	
	videoListRefresh: function() {
		vid = this.activeVideo;
		$$('a.video_listing').each(function(elm) {
			Event.observe(elm, 'click', function() {videoSystem.setActiveVideo(this);}.bind(elm) );
			testid = "video_" + vid;
			if (testid == elm.id) {
				elm.addClassName('selected');
			}
		});
	},
	
	loadingContactForm: function() {
		$('contact_wrapper').innerHTML = '<div class="loading_spinner"><img src="/video/images/player/form_loading.gif" alt="loading" /></div>'
	},
	
	loadingEmailToAFriend: function() {
		$('email_friend_wrapper').innerHTML = '<div class="loading_spinner"><img src="/video/images/player/form_loading.gif" alt="loading" /></div>'
	},
	
	setActiveVideo: function(video_id) {
		this.activeVideo = video_id;
		$$('a.video_listing').each(function(elm) {
			elm.removeClassName('selected');
		});
		
		tmp = $('video_' + video_id);
		if (tmp) {
			tmp.addClassName('selected');
		}
	},
	
	setActiveCategory: function(category_id) {
		this.activeCategory = category_id;
		$$('#category_list li a').each(function(elm) {
			elm.removeClassName('selected');
		});
		
		$('category_'+category_id).addClassName('selected');
    new Effect.Scroll($('content_container_list_video'), { y: 0 });
	},
	
	hideScrollbars: function() {
	  if (!videoSystem.transcriptOpen) {
      window.setTimeout("$('content_transcript').addClassName('open')", 450);
	    videoSystem.transcriptOpen = true;
	  } else {
		  $('content_transcript').removeClassName('open');
	    videoSystem.transcriptOpen = false;
	  }
	  
	}
};

// Setup the observer
Event.observe(window, 'load', videoSystem.initialize, false);


// Event.observe(window, 'load', EII.FormHandler.setup);

function debug(msg) {
	alert(msg);
}
