// Created by Dave-o

var filmHelper={

    init:function(imageStartId, trailerStartId)
    {
        $('#alertmeInfoCollapser').click(function() {
          simpleCollapser.collapse($(this), $('#alertmeInfo'));
          return false;
        });
        
        simpleCollapser.initCollapserWithPreview('reviewsCC', 'Collapse', 'Read full review');
        
        if($('#extrasLink').length)
        {
            $('#extrasLink').click(function() {
              simpleTabber.switch_tabs($('#filmextraTab'));
              return false;
            });
        }        
        if($('#filmextraTab').length)
        {
            $('#filmextraTab').click( 
            function() { 
                if($('#imagesCollapser').length)
                {
                    $('#imagesCollapser').unbind('click');
                    simpleCollapser.show($('#imagesCollapser'), $('#imagesCoverFlow'));
                    $('#imagesCollapser').click(function() {
                      simpleCollapser.collapse($(this), $('#imagesCoverFlow'));
                      return false;
                    });
                }
                if($('#trailersCollapser').length)
                {
                    $('#trailersCollapser').unbind('click');
                    simpleCollapser.show($('#trailersCollapser'), $('#trailersCoverFlow'));
                    $('#trailersCollapser').click(function() {
                      simpleCollapser.collapse($(this), $('#trailersCoverFlow'));
                      return false;
                    });
                }
                if($('#synopsesCollapser').length)
                {
                    $('#synopsesCollapser').unbind('click');
                    simpleCollapser.show($('#synopsesCollapser'), $('#extraSynopses'));
                    $('#synopsesCollapser').click(function() {
                      simpleCollapser.collapse($(this), $('#extraSynopses'));
                      return false;
                    });
                }
                if($('#imagesCoverFlow').length && $('#imagesCoverFlow_images').length == 0)
                {
                    var imagesFlow = new ImageFlow();
                    imagesFlow.init({
                                      ImageFlowID:'imagesCoverFlow',
                                      reflections: false,
                                      preloadImages: false,
                                      reflectionP: 0,
                                      slider: true,
                                      buttons: true,
                                      captions: false,
                                      scrollbarP: 0.8,
                                      startID: imageStartId,
                                      imagesM: 1.3,
                                      imageCursor: 'pointer',
                                    onClick: function() 
                                            { return hs.expand(this,
                                                  { src: this.getAttribute('longdesc'),
                                                  outlineType: 'rounded-white',
                                                  fadeInOut: true,
                                                  captionText: this.getAttribute('alt') } ); } });

                }
                if($('#trailersCoverFlow').length && $('#trailersCoverFlow_images').length == 0)
                {
                    var trailersFlow = new ImageFlow();
                    trailersFlow.init({
                                      ImageFlowID:'trailersCoverFlow',
                                      reflections: false,
                                      preloadImages: false,
                                      reflectionP: 0,
                                      slider: true,
                                      buttons: true,
                                      captions: false,
                                      scrollbarP: 0.8,
                                      startID: trailerStartId,
                                      imagesM: 1.6,
                                      imageCursor: 'pointer',
                                      onClick: function() { filmHelper.changeTrailer(this.getAttribute('alt'), this.getAttribute('longdesc')); }
                    });
                }
            });
        }
    },

    changeTrailer:function (filmId, trailerId){ 
        window.location.hash = "header";
        var flashvars = {
            trailerid: trailerId,
            xmlPath:"/faf/cms_assets/film_trailer_xmls/"+filmId+".xml"
        }
        var params = {
            allowFullScreen: "true",
            allowScriptAccess: "always",
            wmode: "transparent"
        };
        var attributes = {
            id:"videoPlayer",
            name:"videoPlayer"
        }; 
        swfobject.embedSWF("/faf/assets/flash/bb_f_player6.swf", "videoPlayer", "370", "245", "9.0.115", "", flashvars, params, attributes);
        swfmacmousewheel.registerObject(attributes.id);
    }
}