

var fs_qt = function() {

    var Event = YAHOO.util.Event;

    var playerUtil = {
    
        getQuicktimeHTML : function(cfg){
            cfg = cfg || {};
            return QT_GenerateOBJECTText_XHTML(
                cfg.url||'',
                cfg.width||'100%',
                cfg.height||'100%',
                '',
                'Scale',cfg.Scale||'Aspect', 
                'EnableJavaScript',cfg.EnableJavaScript||'true',
                'postdomevents',cfg.postdomevents||'true', 
                'controller',cfg.controller||'false',
                'starttime',cfg.starttime||0,
                'autoplay',cfg.autoplay||'true', 
                'bgcolor',cfg.bgcolor||'#000000', 
                'emb#NAME',cfg.embNAME||'', 
                'obj#id',cfg.objid||'', 
                'emb#id',cfg.embid||'');
        },
        
        formatTime : function(secs,framerate,showFrames,showDecimal){
        	// secs is the full number of seconds to be shown in timecode format
    		secs += 0;
    		var timeStr = "";
    		var hours = Math.floor(secs / 3600);
    		secs -= hours * 3600 ; 
    		var minutes = Math.floor(secs / 60);
    		secs -= minutes * 60 ; 
    		var seconds = Math.floor(secs);
    		if (hours < 10){hours = "0" + hours;}
    		if (minutes < 10){minutes = "0" + minutes;}
    		if (seconds < 10){seconds = "0" + seconds;}
    		if (hours != "00"){timeStr += hours + ":";}
    		timeStr += minutes + ":" + seconds;
    		if (showFrames){
    			var frames = Math.floor((secs - seconds) * framerate);
    			if (frames < 10){frames = "0" + frames;}		
    			timeStr += ":" + frames;
    		} else if (showDecimal) {
    			var decimal = Math.floor((secs - seconds) * 100);
    			if (decimal < 10){decimal = "0" + decimal;}		
    			timeStr += "." + decimal;
    		}
    		return timeStr;	
        },
        
		yuiSlider : function(p){
		    //p = {bgEl:ELEMENT,thumb:ELEMENT,width:INT,changeFunc:FUNCTION,endFunc:FUNCTION}
			var sliderObj = {};
			var params = {};
			params.width = p.width || 480;
			sliderObj = YAHOO.widget.Slider.getHorizSlider(p.bgEl, p.thumb, 0, params.width);
			sliderObj.animate = false;
			sliderObj.subscribe("change", p.changeFunc, this, true); 
			sliderObj.subscribe("slideStart", p.startFunc, this, true);
			sliderObj.subscribe("slideEnd", p.endFunc, this, true);
			return sliderObj;
		},
		
        isIE : function(){
        	// quick and dirty IE check
            var ua = navigator.userAgent.toLowerCase();
        	var msie = /msie/.test(ua) && !/opera/.test(ua);
            return msie;
        }
        
    };
    
    //////////////////////////////// BEGIN BASE PLAYER
    
    var basePlayer = function(p,my){
    
        var that = {};
        
        my = my || {};
        
        that.status = {};
        
        that.params = p;
        that.container = p.container || 'mediaContainer';
        
        that.mediaHeight = function(){
        	return p.mediaHeight || 360;
        }
        
        that.mediaWidth = function(){
        	return p.mediaWidth || 640;
        }
        
        that.scaleMode = p.scaleMode || 'fixed';
        that.name = p.name || 'rand'+Math.floor(Math.random()*10000);
        that.url = p.url || 'default.mov';
        that.theme = p.theme || {};
        that.starttime = p.starttime || '00:00:00';
        that.destroy = function(){
            that.context.targetContainer.el.innerHTML = "";
            that = "";
        };

        that.context = {
        	vertReserve : 0,
            targetContainer : {
                el : document.getElementById(that.container) || document.body,
                width: '',
                height: '',
                setHeight : function(h){
                	this.height = h;
                    this.el.style.height = (typeof(h) == 'number') ? h + 'px' : h;
                },
                setWidth : function(w){
                	this.width = w;
                    this.el.style.width = (typeof(w) == 'number') ? w + 'px' : w;
                }
            },
            fullscreenResize : {
                action : function(){
                	// @todo : insure crossbrowser support of innerWidth/Height
			        that.movie.container.setHeight(window.innerHeight - that.context.vertReserve);
			        that.movie.container.setWidth(window.innerWidth);
                },
                startListener : function(){
                    Event.on(window, "resize", this.action, this, true);
                    this.action();
                }
            },
            init : function(){
            	//console.log(this.targetContainer);
            	//if (typeof(this.targetContainer.style.height) != 'undefined'){
            	//	console.log(this.targetContainer.style.height);
            	//}
                //this.targetContainer.setHeight('100%');
                
				if (that.scaleMode == 'fullscreen'){
					this.targetContainer.setHeight('100%');
			        this.targetContainer.setWidth('100%');
                	this.targetContainer.el.style.background = that.theme.bgColor;
                    if (!playerUtil.isIE()){
                        this.fullscreenResize.startListener();
                    }
				} else {
                	this.targetContainer.setWidth(that.mediaWidth());
                	this.targetContainer.setHeight('auto');
					//this.targetContainer.setHeight(that.mediaHeight);
				}
            }
        }; 
        

        that.movie = {
            pause : function(){
                this.status.jsHook.Stop();
            },
            play : function(){
                this.status.jsHook.Play();
            },
            config : {
                url:        that.url,
                starttime:  that.starttime,
                bgcolor:    that.theme.bgColor,
                embname:    that.name,
                objid:      that.name+'objid',
                embid:      that.name+'embid',
                controller: 'true'
            },
            status : {
				defaultCtrlrHeight : 16,
            	playing: false,
    			timeScale:'',
    			duration:'',
    			movieSize:'',
    			currentFrame : '',
    			loadedFrame : '',
    			percentPlayed : '',
    			frameRate : 24,
    			timeStamp : '00:00',
    			jsHook : {},
    			updateTrackData : function(){
    				this.timeScale = parseInt(this.jsHook.GetTimeScale());
    				this.duration = parseInt(this.jsHook.GetDuration());
    				this.movieSize = parseInt(this.jsHook.GetMovieSize());	
    			},
    			updateProgress : function(){
					this.currentFrame = parseInt(this.jsHook.GetTime());
					this.percentPlayed = (this.currentFrame / this.duration);
    			},
    			setPercentage : function(percent){
            		var newTime = Math.floor(percent * this.duration);
		            if (newTime <= this.loadedFrame){
		            	this.jsHook.SetTime(newTime);
		            	this.updateProgress();
		            }
    			},
    			getPercentage : function(){
					this.currentFrame = parseInt(this.jsHook.GetTime());
					this.percentPlayed = (this.currentFrame / this.duration);
					return this.percentPlayed;
    			},
    			getTimestamp : function(){
					this.timeStamp = playerUtil.formatTime((this.currentFrame / this.timeScale), this.frameRate, that.theme.timeShowFrames, that.theme.timeShowDecimal);
					return this.timeStamp;
    			},
    			getPercentLoaded : function(){
    				this.duration = this.jsHook.GetDuration();
					this.loadedFrame = parseInt(this.jsHook.GetMaxTimeLoaded());
					this.percentLoaded = (this.loadedFrame / this.duration);
					return this.percentLoaded;
    			}
            },
            container : {
				el : document.createElement('div'),
				setHeight : function(h){
				    this.el.style.height = (typeof(h) == 'number') ? h + 'px' : h;
				},
				setWidth : function(w){
				    this.el.style.width = (typeof(w) == 'number') ? w + 'px' : w;
				},
				setInnerHTML : function(s){
					this.el.innerHTML = s;
				},
                setTopPadding : function(m){
                    this.el.style.paddingTop = (typeof(m) == 'number') ? m + 'px' : m;
                }
			},
            init : function(target){
            	// @todo : set baseplayer fullscreen vs static settings
                var qtHTML = playerUtil.getQuicktimeHTML(this.config);
                this.container.setHeight(that.mediaHeight() + this.status.defaultCtrlrHeight);
                if (playerUtil.isIE()){
                    this.container.setTopPadding(50);
                }
                this.container.setWidth(that.context.targetContainer.width);
                this.container.setInnerHTML(qtHTML);
                that.context.targetContainer.el.appendChild(this.container.el);
                this.status.jsHook = document.getElementById(that.name + 'embid') || document.getElementById(that.name + 'objid');
            }
        };
        // @todo : modify base player movie init to use the context for size control and illiminate the need to redefine the init function
        //         within the theme player
        
        that.init = function(){
        	that.movie.init();
            that.context.init();
        };

        return that;
    };

    //////////////////////////////// END BASE PLAYER
    //////////////////////////////// BEGIN THEME PLAYER
    
    var themedPlayer = function(p,my){
    
        var that = basePlayer(p,my);
        
        my = my || {};
        
        that.context.vertReserve = 2 * that.theme.height;
        
		that.ctrlr = {
			pauseState : function(){
				this.elements.playPause.showPlay();
			},
			playState : function(){
				this.elements.playPause.showPause();
			},
			setLoaded : function(percent){
				this.elements.loaded.setWidth(Math.floor(percent * this.elements.slider.width));
			},
			setProgress : function(percent,timestamp){
				//console.log(percent);
                var progressX = Math.floor(percent * (this.elements.slider.width - parseInt(that.theme.sliderHandleWidth)));
				this.elements.progress.setWidth(progressX + (parseInt(that.theme.sliderHandleWidth) / 2));
				this.progressSlider.setValue(progressX);
				if (that.theme.showTime && timestamp){
					this.elements.time.setInnerHTML(timestamp);
				}
			},
			elements : {
				setTheme : function(theme){
		            
		            if (!theme.showPlay){
		                theme.playWidth = 0;
		                theme.playMarginLeft = 0;
		                theme.playMarginRight = 0;
		            }
		            if (!theme.showTime){
		                theme.timeWidth = 0;
		                theme.timeMarginLeft = 0;
		                theme.timeMarginRight = 0;
		            }
		            if (!theme.showMinimize){
		                theme.minimizeWidth = 0;
		                theme.minimizeMarginLeft = 0;
		                theme.minimizeMarginRight = 0;
		            }
		            if (!theme.showJogSlider){
		                theme.jogSliderWidth = 0;
		                theme.jogSliderMarginLeft = 0;
		                theme.jogSliderMarginRight = 0;
		            }       
		            if (theme.width == 'auto'){
		                theme.width = that.context.targetContainer.width;
		            }
		            
		            theme.sliderWidth = parseInt(
		                theme.width 
		                - theme.playWidth
		                - theme.playMarginLeft 
		                - theme.playMarginRight
		                - theme.timeWidth 
		                - theme.timeMarginLeft 
		                - theme.timeMarginRight 
		                - theme.minimizeWidth
		                - theme.minimizeMarginLeft
		                - theme.minimizeMarginRight 
		                - theme.jogSliderWidth
		                - theme.jogSliderMarginLeft
		                - theme.jogSliderMarginRight
		                );
		                                
		            theme.sliderProgressWidth = 
		                theme.sliderWidth
		                - parseInt(
		                    theme.sliderTrackMarginLeft
		                    + theme.sliderTrackMarginRight
		                    );
	
					this.wrapper.set(theme);
					this.controller.set(theme);
					this.controllerL.set(theme);
					this.controllerR.set(theme);
					this.playPause.set(theme);
					this.timeContainer.set(theme);
					this.time.set(theme);
					this.minimize.set(theme);
					this.sliderContainer.set(theme);
					this.sliderContainerR.set(theme);
					this.slider.set(theme);
					this.loaded.set(theme);
					this.loadedR.set(theme);
					this.progress.set(theme);
					this.playHead.set(theme);
					
				},
				assemble : function(){
		            this.timeContainer.el.appendChild(this.time.el);   
		            this.loaded.el.appendChild(this.loadedR.el);
		            this.slider.el.appendChild(this.loaded.el);
		            this.slider.el.appendChild(this.progress.el);
		            this.slider.el.appendChild(this.playHead.el);
		            this.sliderContainer.el.appendChild(this.sliderContainerR.el);
		            this.sliderContainer.el.appendChild(this.slider.el);
		            this.controller.el.appendChild(this.controllerR.el);
		            this.controller.el.appendChild(this.controllerL.el);
		            this.controller.el.appendChild(this.playPause.el);
		            this.controller.el.appendChild(this.sliderContainer.el);
		            this.controller.el.appendChild(this.timeContainer.el);
		            this.controller.el.appendChild(this.minimize.el);
		            this.wrapper.el.appendChild(this.controller.el);
				},
				wrapper : {
					el : document.createElement('div'),
					set : function(theme){
						var contextWidth = (typeof(that.context.targetContainer.width) == 'number') ? that.context.targetContainer.width + 'px' : that.context.targetContainer.width;
			            this.el.style.width = contextWidth;
			            this.el.style.height = theme.height +'px';
			            //this.el.style.position = 'absolute';
			            //this.el.style.bottom = '0px';
			            this.el.style.textAlign = 'center';
			            this.el.style.background = theme.bgColor;
					}
				},
				controller : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.width = theme.width  +'px';
			            this.el.style.height = theme.height +'px';
			            this.el.style.position = 'relative';
			            this.el.style.margin = '0 auto';
			            this.el.style.marginTop = theme.marginTop + 'px';
					}
				},
				controllerL : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.width = Math.floor(theme.width / 2 + 1) + 'px'; 
			            this.el.style.height = theme.height +'px';
			            this.el.style.background = theme.background;
			            this.el.style.backgroundPosition = 'left top';
			            this.el.style.position = 'absolute';
			            this.el.style.left = '0px';
					}
				},
				controllerR : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.width = Math.floor(theme.width / 2 + 1) + 'px'; 
			            this.el.style.height = theme.height +'px';
			            this.el.style.background = theme.background;
			            this.el.style.backgroundPosition = 'right top';
			            this.el.style.position = 'absolute';
			            this.el.style.right = '0px';
					}
				},
				playPause : {
					el : document.createElement('div'),
					click : function(){
					   that.movie.playPauseToggle();
				    },
				    showPause : function(){},
				    showPlay : function(){},
				    mouseover : function(){},
				    mouseout : function(){},
					set : function(theme){
			            this.el.style.cssFloat = 'left';
			            this.el.style.cursor = 'pointer';
			            this.el.style.position = 'relative';
			            this.el.style.width = theme.playWidth + 'px';
			            this.el.style.height = theme.playHeight + 'px';
			            this.el.style.top = Math.floor((theme.height - theme.playHeight) / 2) + 'px';
			            this.el.style.marginLeft = theme.playMarginLeft + 'px';
			            this.el.style.marginRight = theme.playMarginRight + 'px';
			            this.el.style.background = theme.playBackground;
			            this.showPause = function(){this.el.style.background = theme.playPauseBackground;};
			            this.showPlay = function(){this.el.style.background = theme.playBackground;};
			            if (that.params.theme.playHover){
                            this.mouseover = function(){this.el.style.backgroundPosition = '0px -' + theme.playHeight + 'px';};
                            this.mouseout = function(){this.el.style.backgroundPosition = '0px 0px';};
	            			Event.on(this.el,"mouseover", this.mouseover, this, true);
	            			Event.on(this.el,"mouseout", this.mouseout, this, true);
						}
						Event.on(this.el,"click", this.click,this,true);
					}
				},
				timeContainer : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.position = 'relative';
			            this.el.style.cssFloat = 'right';
			            this.el.style.background = theme.timeBackground;
			            this.el.style.top = Math.floor((theme.height - theme.timeHeight) / 2) + 'px';
			            this.el.style.right = (theme.minimizeWidth + theme.minimizeLeftMargin + theme.rightSpacerWidth) + 'px';
			            this.el.style.height = theme.timeHeight + 'px';
			            this.el.style.width = theme.timeWidth + 'px';
			            this.el.style.marginRight = theme.timeMarginRight + 'px';
			            this.el.style.color = theme.timeColor;
			            this.el.style.cursor = 'default';
			            this.el.style.fontFamily = theme.timeFontFace;
			            this.el.style.textAlign = 'center';
			            this.el.style.fontSize = theme.timeFontSize + 'px';
			            this.el.style.overflow = 'hidden';
					}
				},
				time : {
					el : document.createElement('span'),
					setInnerHTML : function(h){
						this.el.innerHTML = h;
					},
					set : function(theme){
			            this.el.style.position = 'relative';
			            this.el.style.top = Math.floor((theme.timeHeight - theme.timeFontSize) / 2 - 1) + 'px';
			            this.el.style.display = 'block';
			            this.el.innerHTML = '<span style="opacity:.5;">00:00</span>';
					}
				},
				minimize : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.position = 'absolute';
			            this.el.style.right = theme.rightSpacerWidth + 'px';
			            this.el.style.top = Math.floor((theme.height - theme.minimizeHeight) / 2) + 'px';
			            this.el.style.background = theme.minimizeBackground;
			            this.el.style.height = theme.minimizeHeight + 'px';
			            this.el.style.width = theme.minimizeWidth + 'px';
			            this.el.style.cursor = 'pointer';
					}
				},
				sliderContainer : {
					el : document.createElement('div'),
					width : '',
					set : function(theme){
						this.width = theme.sliderWidth;
			            this.el.style.width = theme.sliderWidth + 'px'; 
			            this.el.style.position = 'relative';
			            this.el.style.cssFloat = 'left';
			            this.el.style.height = theme.sliderHeight + 'px';
			            this.el.style.top = Math.floor((theme.height - theme.sliderHeight) / 2) + 'px';
			            this.el.style.background = theme.sliderBackground;
					}
				},
				sliderContainerR : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.width = Math.floor(theme.sliderWidth / 2 + 1) + 'px'; 
			            this.el.style.position = 'absolute';
			            this.el.style.right = '0px';
			            this.el.style.height = theme.sliderHeight + 'px';
			            this.el.style.background = theme.sliderBackground;
			            this.el.style.backgroundPosition = 'right top';
					}
				},
				slider : {
					el : document.createElement('div'),
					width : '',
					set : function(theme){
						this.width = parseInt(theme.sliderProgressWidth);
			            this.el.style.width = theme.sliderProgressWidth + 'px'; 
			            this.el.style.position = 'relative';
			            this.el.style.left = theme.sliderTrackMarginLeft + 'px';
			            this.el.style.height = theme.sliderHeight + 'px';
			            this.el.style.top = Math.floor((theme.sliderTrayHeight - theme.sliderTrackHeight) / 2) + 'px';
			            //this.el.style.background = theme.sliderBackground;
					}
				},
				loaded : {
					el : document.createElement('div'),
					width : '',
					setWidth : function(w){
						this.width = w;
						this.el.style.width = w + 'px';
					},
					set : function(theme){
			            this.el.style.position = 'absolute';
			            this.el.style.height = theme.sliderLoadedHeight + 'px';
			            this.el.style.width = '10px';
			            this.el.style.top = Math.floor((theme.sliderHeight - theme.sliderLoadedHeight) / 2) + 'px'; 
			            this.el.style.background = theme.sliderLoadedBackground;
			            this.el.style.overflow = 'hidden';
					}
				},
				loadedR : {
					el : document.createElement('div'),
					set : function(theme){
			            this.el.style.position = 'absolute';
			            this.el.style.height = theme.sliderLoadedHeight + 'px';
			            this.el.style.width = Math.floor(theme.sliderWidth / 2) + 'px';
			            this.el.style.left = Math.floor(theme.sliderWidth / 2 + 1) - (theme.sliderTrackMarginLeft + theme.sliderTrackMarginRight) + 'px'; 
			            this.el.style.top = '0px';
			            this.el.style.background = theme.sliderLoadedBackground;
			            this.el.style.backgroundPosition = ' right top';
					}
				},
				progress : {
					el : document.createElement('div'),
					width : '',
					setWidth : function(w){
						this.width = w;
						this.el.style.width = w + 'px';
					},
					set : function(theme){
						this.width = Math.floor(theme.sliderHandleWidth / 2);
			            this.el.style.position = 'absolute';
			            this.el.style.height = theme.sliderPlayedHeight + 'px';
			            this.el.style.width = Math.floor(theme.sliderHandleWidth / 2) + 'px';
			            this.el.style.top = Math.floor((theme.sliderHeight - theme.sliderPlayedHeight) / 2) + 'px';
			            this.el.style.background = theme.sliderPlayedBackground;
					}
				},
				playHead : {
					el : document.createElement('div'),
					width : '',
					clickOn : function(){},
					clickOff : function(){},
					set : function(theme){
						this.width = parseInt(theme.sliderHandleWidth);
			            this.el.style.position = 'absolute';
			            this.el.style.cursor = 'pointer';
			            this.el.style.top = Math.floor((theme.sliderHeight - theme.sliderHandleHeight) / 2) + 'px';
			            this.el.style.left = '0px';
			            this.el.style.width = theme.sliderHandleWidth + 'px';
			            this.el.style.height = theme.sliderHandleHeight + 'px';
			            this.el.style.background = theme.sliderHandleBackground;
			            if (that.params.theme.sliderHandleClickstate){
                            this.clickOn = function(){this.el.style.backgroundPosition = '0px -' + theme.sliderHandleHeight + 'px';};
                            this.clickOff = function(){this.el.style.backgroundPosition = '0px 0px';};
                        } else {
                            this.clickOn = function(){};
                            this.clickOff = function(){};
                        }
					}
				}
			},			
			progressSlider : {
                _sliding : false,
                _restart : false,
                _percent : 0,
				_ctrl : {}, 
				setValue : function(num){
				    if (!this._sliding){
                        this._ctrl.setValue(num, true, false, true);
                    }
                },              
				init : function(elements){
				    // CREATE THE YUI SLIDER OBJECT
					this._ctrl = playerUtil.yuiSlider({
				    	bgEl : elements.slider.el,
				    	thumb : elements.playHead.el,
				    	width : elements.slider.width - elements.playHead.width,
				    	changeFunc : function(newValue){
				    		that.ctrlr.progressSlider._percent = newValue / (elements.slider.width - elements.playHead.width);	
                    		that.movie.setPercentage(that.ctrlr.progressSlider._percent);
				    	},
				    	startFunc : function(){
                            if(that.movie.status.playing){
                            	that.ctrlr.progressSlider._restart = true;
                            	that.movie.pause();
                            } else {
                            	that.ctrlr.progressSlider._restart = false;
                            }
                            elements.playHead.clickOn();
                            that.ctrlr.progressSlider._sliding = true;
				    	},
				    	endFunc : function(){
				    		var loaded = that.movie.status.getPercentLoaded();
				    		var played = that.movie.status.getPercentage();
				    		if (that.ctrlr.progressSlider._percent > loaded){
				    			that.movie.setPercentage(loaded);
				    			that.ctrlr.progressSlider._restart = false;
				    		}
                            if(that.ctrlr.progressSlider._restart && played != 1){
                            	that.movie.play();
                            }
                            elements.playHead.clickOff();
                            that.ctrlr.progressSlider._sliding = false;
				    	}	
				    });
				}
			},

			init : function(){
	            this.elements.setTheme(that.params.theme);
	            this.elements.assemble();
	            that.context.targetContainer.el.appendChild(this.elements.wrapper.el);
	            this.progressSlider.init(this.elements);
			}
		};
		

        // adding config difference, theme variations, and dom interaction to the inherited movie object capabilities
        
        // do not use the standard qt controller
        that.movie.config.controller = 'false';
        that.movie.status.defaultCtrlrHeight = 0;
        
        // add a playPauseToggle function to the movie
        that.movie.playPauseToggle = function(){
        	if (this.status.playing){
        		this.pause();
        	} else {
        		this.play();
        	}
        };
        
        // configure the movies container based on the theme settings
        that.movie.container.setTheme = function(theme){
            this.el.style.background = theme.bgColor;
            this.el.style.textAlign = "center";
        };
        
        // add the checking object, which handles the setInterval progress updates while the movie is playing
		that.movie.checking = {
			_interval : {},
			_action : function(){
				that.ctrlr.setProgress(that.movie.status.getPercentage(),that.movie.status.getTimestamp());
			},
			start : function(){
				this._interval = setInterval(function(){that.movie.checking._action();}, that.params.theme.scrubberRefreshRate||200, this);
			},
			stop : function(){
				clearInterval(this._interval);
			}
		};
        
        // add the DOM event interactions to the movie object
        that.movie.dom = {
            source : {},
            events : {
                qt_begin : function (e) {},
                qt_error : function (e) {},
                qt_waiting : function (e) {},
                qt_stalled : function (e) {},
                qt_volumechange : function (e) {},
                qt_loadedmetadata : function (e) {},
                qt_canplaythrough : function (e) {},
                qt_durationchange : function (e) {},
                qt_loadedfirstframe : function (e) {},
                qt_ended : function (e) {
                    that.movie.setPercentage(1);
                    p.onEnd = p.onEnd || function(){};
                    p.onEnd();
                },
                qt_progress : function (e) {
                    that.ctrlr.setLoaded(that.movie.status.getPercentLoaded());
                },
                qt_timechanged : function (e) {
                	that.ctrlr.setProgress(that.movie.status.getPercentage(),that.movie.status.getTimestamp());
                },
                qt_load : function (e) {
                    that.ctrlr.setLoaded(that.movie.status.getPercentLoaded());
                },
                qt_canplay : function (e) {
                    that.movie.status.updateTrackData();
                },
                qt_play : function (e) {
                    that.movie.status.updateTrackData();  // double check to ensure the track data exists !important
                    that.movie.checking.start();
                    that.ctrlr.playState();
                    that.movie.status.playing = true;
                    // reset the track to the full start-stop points if a custom start time was used.
                    that.movie.status.jsHook.SetStartTime(0);  
                },
                qt_pause : function (e) {
                    that.movie.status.playing = false;
                    that.movie.checking.stop();
                    that.ctrlr.pauseState();
                }
            },
            setListeners : function(){
                Event.on(this.source,"qt_begin", this.events.qt_begin,this,true); 
                Event.on(this.source,"qt_loadedfirstframe", this.events.qt_loadedfirstframe,this,true); 
                Event.on(this.source,"qt_canplaythrough", this.events.qt_canplaythrough,this,true); 
                Event.on(this.source,"qt_durationchange", this.events.qt_durationchange,this,true); 
                Event.on(this.source,"qt_error", this.events.qt_error,this,true); 
                Event.on(this.source,"qt_waiting", this.events.qt_waiting,this,true); 
                Event.on(this.source,"qt_stalled", this.events.qt_stalled,this,true); 
                Event.on(this.source,"qt_volumechange", this.events.qt_volumechange,this,true); 
                Event.on(this.source,"qt_ended", this.events.qt_ended,this,true); 
                Event.on(this.source,"qt_progress", this.events.qt_progress,this,true); 
                Event.on(this.source,"qt_timechanged", this.events.qt_timechanged,this,true); 
                Event.on(this.source,"qt_load", this.events.qt_load,this,true); 
                Event.on(this.source,"qt_canplay", this.events.qt_canplay,this,true); 
                Event.on(this.source,"qt_play", this.events.qt_play,this,true); 
                Event.on(this.source,"qt_pause", this.events.qt_pause,this,true);
                Event.on(this.source,"qt_loadedmetadata", this.events.qt_loadedmetadata,this,true);
            },
            init : function(){
                this.source = that.movie.container.el.firstChild;
                this.setListeners();
            }
        };
        
        // set the movie progress to a percentage completed..
        that.movie.setPercentage = function(percent){
            this.status.setPercentage(percent);
            that.ctrlr.setProgress(percent,this.status.getTimestamp());
        };
        
        // overwrite the movie init function to enable the newly added features
        that.movie.init = function(){
            var qtHTML = playerUtil.getQuicktimeHTML(this.config);
            if (that.scaleMode == 'fullscreen'){
                this.container.el.style.paddingTop = that.theme.height + 'px';
            } else {
                this.container.setHeight(that.mediaHeight());
                this.container.setWidth(that.mediaWidth());
            }
            this.container.setInnerHTML(qtHTML);
            this.container.setTheme(that.theme);
            this.dom.init();
            that.context.targetContainer.el.appendChild(this.container.el);
            this.status.jsHook = document.getElementById(that.name + 'embid') || document.getElementById(that.name + 'objid');
        };
    
        // overwrite the player init function to enable the new ctrlr object
        that.init = function(){
            that.context.init();
            that.movie.init();
        	that.ctrlr.init();
        };

        return that;
    };
    
    //////////////////////////////// END THEME PLAYER

    return {
        createPlayer : function(params){
        	var player = {};
            if (params.theme.useLegacyController || playerUtil.isIE()){
            	player = basePlayer(params);
            } else {
                player = themedPlayer(params);
            }
            player.init();
            return player;
        }
    };

}();


