

if(typeof(AC)=='undefined'){AC={};}

AC.FrontRow=Class.create();
Object.extend(Object.extend(AC.FrontRow.prototype,Event.Listener),{

sections:null,
currentSection:null,
currentMovie:null,
currentController:null,
displayPanel:null,
descriptionPanel:null,
options:null,
hasQuicktime:false,

initialize:function(movie,displayPanel,descriptionPanel,sections,options){

this.currentMovie=movie;
this.sections=sections;
this.displayPanel=displayPanel;
this.descriptionPanel=descriptionPanel;
this.options=options||{};

if(this.options.controller){
this.currentController=this.options.controller;
}

for(var i=0;i<this.sections.length;i++){
this.listenForEvent(this.sections[i],'activate',false,function(evt){
var section=evt.event_data.data;
this.show(section);
});

}

this.hasQuicktime=AC.Detector.isValidQTAvailable(this.options.requiredQT||"7");

},

showFirst:function(){
this.show(this.sections[0]);
},

show:function(section){


if(section==this.currentSection&&this.isPlaying()){
return;
}

var showDescription=function(description){

if(typeof(description)=='string'){
this.descriptionPanel.innerHTML=description;
}else{
this.descriptionPanel.innerHTML='';
this.descriptionPanel.appendChild(description.cloneNode(true));
}
}.bind(this);

var showMovie=function(movieUrl){

this.currentController.SetURL(movieUrl);



if(section!=this.currentSection){
this.currentSection.deactivate();
}

}.bind(this);

var showStaticContent=function(content){

if(this.currentSection){
this.currentSection.deactivate();
}

this.displayPanel.innerHTML='';

if(content){
this.displayPanel.appendChild(content.cloneNode(true));
}

}.bind(this);


section.activate();

if(typeof(this.options.beforeStartMovie)=='function'){
this.options.beforeStartMovie(section);
}

showDescription(section.description);

if(this.hasQuicktime&&section.movieUrl!=null){

if(!this.currentSection){
this.displayPanel.appendChild(this.currentMovie);

if(!this.currentController){
this.currentController=new AC.QuicktimeController(this.currentMovie);
}

}else{
showMovie(section.movieUrl);
}

}else{
showStaticContent(section.options.staticContent);
}

this.currentSection=section;

if(typeof(this.options.onStartMovie)=='function'){
this.options.onStartMovie(this.currentSection);
}
},

isPlaying:function(){
return this.currentController.isPlaying();
}

});


AC.FrontRowSection=Class.create();
Object.extend(Object.extend(AC.FrontRowSection.prototype,Event.Publisher),{

trigger:null,
title:null,
movieUrl:null,
description:null,
options:null,


initialize:function(trigger,title,movieUrl,description,options){

this.trigger=trigger;
this.title=title;
this.movieUrl=movieUrl;
this.description=description;
this.options=options||{};

Event.observe(this.trigger,'mouseover',function(){
Element.addClassName(this.trigger,'hover');
}.bind(this),false);

Event.observe(this.trigger,'mouseout',function(){
Element.removeClassName(this.trigger,'hover');
}.bind(this),false);

Event.observe(this.trigger,'click',function(evt){
this.dispatchEvent('activate',this);
Event.stop(evt);
}.bind(this),false)

},


activate:function(){
Element.addClassName(this.trigger,'active');
},


deactivate:function(){
Element.removeClassName(this.trigger,'active');
}

});
