/*

PROGRAMMER: All the functions for the Theater animations. 
 
*/
var Theater=function(item){
        if($('college-photo') && $('theater-player-button')){
                     $('college-photo')
                    .set('html',
                        '<div id="slide-image" title="'+this.caption+' ('+this.href+')" ><img src="'+this.imgsrc+'" id="slide-img" /></div><div id="slide-content"><p><span id="slider" title="Slide '+this.slidenumber+' of '+this.slidecount+' total slides.">('+this.slidenumber+'/'+this.slidecount+')</span> '+this.caption+'</p></div>'
                    ).set('height','100%'); if(!this.href) slideHref='#'; else slideHref=this.href;
                            $('college-photo').setStyle('height','auto');
                            $('college-photo').addEvent('click',function(){
                                window.location.href=slideHref;
                            });
                                
                            
                                if(!Browser.Engine.presto) $('college-photo')
                                    .addEvent('mouseenter',function(){
                                            $('slide-content')
                                                    .setStyles({
                                                        'background-color':'#882345',
                                                        'opacity':0.999
                                                    });
                                    }).addEvent('mouseleave',function(){
                                            $('slide-content')
                                                .setStyles({
                                                    'background-color':'#000',
                                                    'opacity':0.7
                                                });
                                    });
                            

                    if(slideHref!='#')
                        $('college-photo').setStyle('cursor','pointer');
                            else $('college-photo').setStyle('cursor','normal');
                    
                   
                        $('college-photo')
                            .setStyle('opacity',0)
                            .setStyle('background','#000')
                            .fade('in',{duration:'long'});
                    
                    
                                var ThistoPass=this;
                                subT=$('college-photo').getStyle('height').toInt()-this.imgheight.toInt();
                                    window.addEvent('resize',function(){
                                        TheaterChangeContentPos(ThistoPass,subT);
                                    });
                                        TheaterChangeContentPos(this,subT);
                                        if(!Browser.Engine.presto) $('slide-content').setStyles({
                                            'opacity':0.7
                                        });
                                        
                    if(this.slidecount==this.slidenumber && this.slidecount!=1)
                    $('theater-player-button')
                    .set('html','<a href="javascript:PlayTheater();" title="Play all slides over again.">Start Over</a>')
                        .setStyles({
                            'display':'block',
                            'opacity': 0.7,
                            'top':43
                        }); else $('theater-player-button').setStyles({
                            'display':'none'
                        });
        }
}

function TheaterChangeContentPos(a,subT){
    if(!Browser.Engine.presto){
        $('slide-content').setStyles({
            'margin-top':-$('slide-content').getStyle('height').toInt()
        });
    }
}

function setupTheater(){
    PlayTheater();
}

function PlayTheater(){
    var wpCaptionClass='.wp-caption';
    var imgTheaterSlideClass='slide';
    var animateTimeoutSession=12000;
    CycleTheater(wpCaptionClass,imgTheaterSlideClass,animateTimeoutSession);
}

function CycleTheater(wpCaptionClass,imgTheaterSlideClass,animateTimeoutSession){      
    //var wpCaptionClass='.wp-caption';
    //var imgTheaterSlideClass='slide';
    //var animateTimeoutSession=15000;
    var Slides=[];
    var slideCount=0;
    var animateSlide=false;
    i=0;
    var slideHref, slideImgSrc, slideImgHeight, slideCaption = 0;
            $$(wpCaptionClass).each(function(item){
                $$('#'+item.getProperty('id')+' a').each(function(item){
                    slideHref=item.getProperty('href');
                });
                $$('#'+item.getProperty('id')+' img').each(function(item){
                    slideImgSrc=item.getProperty('src');
                    slideImgHeight=item.getStyle('height');
                    if(item.hasClass(imgTheaterSlideClass))
                        animateSlide=true;
                        else animateSlide = false;
                });
                $$('#'+item.getProperty('id')+' p').each(function(item){
                    slideCaption=item.get('html');
                });
                if(animateSlide){ Slides[i++] = {
                    'caption':slideCaption,
                    'href':slideHref,
                    'imgsrc':slideImgSrc,
                    'imgheight':slideImgHeight,
                    'slidenumber':i
                }; item.setStyle('display','none');}
            });
            
            animateTimeout=0; //To begin with, at zero
            Slides.each(function(item,index){
                item.slidecount=i;
                TheaterPlayer=Theater.delay(animateTimeout,item);
                animateTimeout=animateTimeout+animateTimeoutSession;
            });
}


function getTheaterVideos(){
    $$('.video-slide').each(function(item){
        $('college-photo').setStyle('height','auto');
        if($('college-photo')){
            $('college-photo').set('html',item.get('html'));
            $('college-photo').setStyle('padding',10);
            item.destroy();
                /*Vwidth='100%';
                Vheight=300;*/
                $$('div#college-photo object').each(function(item){
                    /*try{
                        item.setStyles({
                            'width':Vwidth,
                            'height':Vheight
                        });
                    }catch(e){}*/
                });
                /*$$('div#college-photo object embed').each(function(item){
                   item.setStyles({'width':Vwidth,'height':Vheight});
                });*/
            
        }
    });
    
    
}