SW.local.flashVideoPlayer = {
    panel:null,
    propertyID:null,
    flashPlayerURL:null,
    selectedNav:null,
    videoArray:[],
    init:function(){
        SW.local.flashVideoPlayer.flashPlayerURL=this.flashPlayerURL;
        SW.local.flashVideoPlayer.propertyID=this.propertyID;

        var tiggers = yuiDom.getElementsByClassName("flashVideoLinkTigger",'a');
        var count=0;
        if (tiggers.length>0){
            tiggers.forEach(function(tigger){
                SW.local.flashVideoPlayer.videoArray[count++]=({videoURL :tigger.href,videoTitle:tigger.id});
                var config ={
                    videoURL:tigger.href,
                    videoName:tigger.id,
                    showNav:true
                }
                yuiEvent.addListener(tigger,"click",SW.local.flashVideoPlayer.loadPlayerBridge,config);
            });
        }
    },
    loadPlayer:function(mURL,selectedVideoTitle,showNav){
        var videoURL = mURL;
        if (!this.panel){
            var flashPlayerPanel = document.createElement("div");
            flashPlayerPanel.id = "flashPlayerPanel";

            this.panel = new YAHOO.widget.Panel(flashPlayerPanel,{
                close:false,
                visible:false,
                modal:true,
                underlay:"none",
                constraintoviewport:true,
                fixedcenter: true,
                zIndex:1030
            });
            this.panel.hideEvent.subscribe(function(){
                var flashMovieContainer = yuiDom.get("flashcontentMediaPlayer");
                flashMovieContainer.innerHTML = "";
            });
            var flashPlayerClose = yuiDom.get("closeMediaWindow");

            yuiEvent.addListener(flashPlayerClose,"click",function(){
                SW.local.flashVideoPlayer.panel.hide();
            });
            var playerPopupContainer = yuiDom.get("mediaPlayerContainer");

            this.panel.setBody(playerPopupContainer);
            this.panel.render(document.body);
            yuiDom.setStyle(playerPopupContainer,"display","block");
        }
        this.panel.show();
        this.playMovie(videoURL);
        if (showNav){
            this.writeVideoNav(selectedVideoTitle);
        }
    },
    writeVideoNav:function(selectedVideoTitle){
        var sectionTitles=document.getElementById("sectionTitles");
        sectionTitles.innerHTML ="";
        var sectionVideoArray = SW.local.flashVideoPlayer.videoArray;
        if  (sectionVideoArray.length > 0 ) {
            for(i=0; i < sectionVideoArray.length; i++){
                var sectionNavItemContainer= document.createElement("li");
                var sectionNavItem= document.createElement("a");
                sectionNavItemContainer.appendChild(sectionNavItem);
                sectionNavItem.href = sectionVideoArray[i].videoURL;
                sectionNavItem.id=sectionVideoArray[i].videoTitle;
                if (selectedVideoTitle == sectionVideoArray[i].videoTitle) {
                    SW.local.flashVideoPlayer.selectedNav = sectionNavItem;
                    yuiDom.addClass(sectionNavItem,"locked");
                }
                sectionNavItem.innerHTML=sectionVideoArray[i].videoTitle;
                sectionTitles.appendChild(sectionNavItemContainer);

                yuiEvent.addListener(sectionNavItem,"click",SW.local.flashVideoPlayer.playMovieBridge,{videoURL:sectionVideoArray[i].videoURL});
            }
        }
    },
    playMovie:function(videoURL){
        var swfObj = new SWFObject(SW.local.flashVideoPlayer.flashPlayerURL, "player", "336", "320", "8,0,0,0", "#ffffff");
        swfObj.addVariable("xContentPath",videoURL);
        swfObj.addParam("allowScriptAccess","sameDomain");
        swfObj.addParam("wmode","Opaque");
        swfObj.setAttribute("redirectUrl","");
        swfObj.write("flashcontentMediaPlayer");
    },
    playMovieBridge:function(e,params){
        yuiEvent.preventDefault(e);
        yuiDom.removeClass(SW.local.flashVideoPlayer.selectedNav,"locked");
        yuiDom.addClass(this,"locked");
        SW.local.flashVideoPlayer.selectedNav=this;
        SW.local.flashVideoPlayer.playMovie(params.videoURL);
    },
    loadPlayerBridge:function(e,config){
        yuiEvent.preventDefault(e);
        SW.local.flashVideoPlayer.loadPlayer(config.videoURL,config.videoName,config.showNav);
    }
};