window.addEvent("domready", function(){

	var VideoFeed = "standard";
	if ($('videoFeed') != null)
	{
		var VideoFeed = $('videoFeed').value;
	}
	
	if (VideoFeed == "none")
	{
		return;
	}
			
	function purge(d){
		var a = d.attributes, i, l, n;
		if(a){
			l = a.length;
			for(i = 0; i < l; i += 1){
				n = a[i].name;
				if(typeof d[n] === 'function') {					
					d[n] = null;
				}
			}
		}
		a = d.childNodes;
		if(a){
			l = a.length;
			for (i = 0; i < l; i += 1){
				purge(d.childNodes[i]);
			}
		}
	}	
				
	
	(function(){
		
		var _v=new Class({
			initialize: function(swf, element, width, height, v, backgroundColor, construct){
				this.name=element;
				this.backgroundColor=backgroundColor;
				var version = v || '8';
				this.so=new SWFObject(swf, this.name, width, height, version, backgroundColor);
				//Base Variables
				this.addVariable("objName", this.name);
				//Base Parameters
				this.addParam("class", 'qvc_video');
				this.addParam("scale", "noscale");
				this.addParam("salign", "tl");
				this.addParam("wmode", "transparent");
				//
				construct(this);
			},
			write:function(element, videoWidth, videoHeight, vars, params){	
				
				purge(element);
				try{purge($(this.name+'_holder'));}catch(e){}
				
				this.addVariable("totalHeight", videoHeight);
				this.addVariable("videoWidth", videoWidth);
				
				for(var i=0; i<vars.length; i++){
					this.addVariable(vars[i][0], vars[i][1]);
				}
				
				for(i=0; i<params.length; i++){
					this.addParam(params[i][0], params[i][1]);
				}
				
				var holder=new Element('div',{
						'styles':{'backgroundColor':this.backgroundColor},
						'id':this.name+'_holder'
				});
				
				holder.pause=function(){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).stopVideo();
				};
				
				holder.stopVideo=holder.pause;
			
				holder.play=function(){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).stopVideo();
				};			
			
				holder.changeContent=function(url, isPlaying, shouldMute, imageName){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).changeContent(url, isPlaying, shouldMute, imageName);
				};
			
				holder.changeContentWithTime=function(url, isPlaying, shouldMute, freezeTime){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).changeContent(url, isPlaying, shouldMute, freezeTime);
				};
			
				holder.changeContentWithSegments=function(url, isPlaying, shouldMute, imageName, previewTime, segmentStart, segmentEnd){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).changeContentWithSegments(url, isPlaying, shouldMute, imageName, previewTime, segmentStart, segmentEnd);
				};
			
				holder.removeFromDOM=function(){
					purge(this);
					this.innerHTML='';
					this.parentNode.empty();
				};
				
				holder.contract=function(){
					var videoName=this.getElements('*')[0].id;
					thisMovie(videoName).contract();
				};
				
				purge(element);
				
				element.innerHTML='';
				
				holder.injectInside(element);
				//
				this.so.write(holder);
				//no flash
				if((holder.innerHTML == '') || (holder.innerHTML == '<!-- No Flash Installed -->') || (holder.innerHTML.indexOf('\n') > -1)){
					var noFlash = new Element('div',{'id':'noflash','class':'noflash'}).setHTML('<div>Flash 8 or higher is required to view QVC videos.<br /><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash?rewrite=no" title="Download Flash Player" target="_blank">Download</a> the latest version of Flash.</div>').injectInside(element);
				}
				
				if(document.getElementById(this.name) != null){
					if(!window.ie){
						document.getElementById(this.name).setProperties({
							'width':videoWidth,
							'height':videoHeight
						});
					}else{
						document.getElementById(this.name).setAttribute('width', videoWidth);
						document.getElementById(this.name).setAttribute('height', videoHeight);
					}
				}
				
				function thisMovie(movieName) {
				    if (window.ie) {
				        return window[movieName];
				    }
				    else {
				        return document[movieName];
				    }
				}
				
			},

			addVariable:function(name, value){
				this.so.addVariable(name, value);
			},
			addParam:function(name, value){
				this.so.addParam(name, value);
			}

		});
		
		function dispatchEvent(eventName, eventObj){
			function handleEvent(eventName, video, execute, c, a){
				var args = a || [];
				var callback=c || function(){return true};
				var execute=execute || true;
				switch(eventName){
					case 'expandButtonPress':
						callback = expandButtonPress || callback;
						break;
					case 'start':
						callback = onStartEvent || callback;
						break;
					case 'finished':
						callback = onFinishEvent || callback;								
						break;					
					default:
						callback=callback;
						break;
				}
				
				if(execute){callback()};
			}

			handleEvent(eventName, $(eventObj.objName));
			
			if(!window['video']['executeEvent']){
				window['video']['executeEvent']=handleEvent;
			}
		}
		
		window['video']={};
		window['video']['_v']=_v;
		_v=null;
		
		window['dispatchEvent']=dispatchEvent;
		dispatchEvent=null;

	})();
	
	window.onunload = function(){
		window.onerror = function(){
    		return true;
    	};
    	
    	$ES('.qvc_video').each(function(item, index){
			if(!window.ie){
				item.remove();
			};
		});
	}
	
});