Event.observe(window, 'load', initPortal, false);

current_extra = null;
playing_intro_teaser = false;
var portalPlayer;
function playerReady(obj) {
  portalPlayerReady(obj)
}
function portalPlayerReady(obj) {
  portalPlayer = $(obj['id']);
	portalPlayer.addModelListener("STATE", "intro_teaser_state_tracker");
	
}
function initPortal () {
  //show the blog extras section
  $$('.extras_section').invoke("hide");
  current_extra = $('extras_blog');
  current_extra.show();
  style_attrs = {height: current_extra.getHeight() + "px"}
  current_extra.up().setStyle(style_attrs);
  current_extra.setStyle(style_attrs);
  if ($('intro_teaser_flashvars'))
  {
    show_preview($F('intro_teaser_container'),$F('intro_teaser_flashvars'))
    playing_intro_teaser = true;
  } else {
    show_preview('intro_description',$F('intro_flashvars'))
  }
}
function intro_teaser_state_tracker(obj)
{
  currentState = obj.newstate; 
  previousState = obj.oldstate; 
  if (playing_intro_teaser && 
    (currentState == "COMPLETED" || currentState == "IDLE") && 
    previousState == "PLAYING") {
      show_preview('intro_description',$F('intro_flashvars'));
  }
}
function setup_accordion(open_section)
{
  $$('.non_accordion_content').invoke("remove");
  //setup the accordion
  accordion = new Accordion('#accordion .accordion_toggle', '#accordion .accordion_content', {duration: 0.5, default_open: open_section});
}
function show_extras(section) {
  new_extra = $('extras_' +section);
  if (new_extra != current_extra)
  {
    new_height = Math.max(current_extra.getHeight(),new_extra.getHeight())
    current_extra.up().setStyle({height: new_height + "px"});
    new Effect.Fade(current_extra, { duration:1, from:1.0, to:0.0 });
    new Effect.Appear(new_extra, { duration:1, from:0.0, to:1.0 }); 
    current_extra.up().setStyle({height: new_extra.getHeight() + "px"});
    current_extra = new_extra;
  }
}
function show_preview (description_id,flashvars) {
  playing_intro_teaser = false;
  $$('.description_container').invoke('hide')
  $(description_id).show();
  var swf = new SWFObject("/player.swf","autostart_mpl","480","290","9");
  swf.addParam('allowscriptaccess','always');
  swf.addParam('allowfullscreen','true');
  swf.addParam('flashvars',flashvars);
  swf.write("flashcontent");
}
