var Playlist = Class({

	initialize: function(options,parent) {
		this.target = $(options.target);
		this.effects = options.effects.split(" ");
		this.source = options.source;
		
		this.onDeploy = options.onDeploy || false;
		if (this.onDeploy !== false)
			this.filecount = options.filecount;
			
		this.mode = options.mode || "playlist";
		this.autostart = options.autostart || "true";
		this.dimensions = options.dimensions || "640x480";
		this.dimensions = this.dimensions.split("x");
		this.hidecontrols = (options.hidecontrols == 'true' ? true : false);
		this.preview = options.preview || "http://static.brazzers.com/img/player-ready.jpg";
		this.effect = 0;
		this.parent = parent;
	},
	
	deploy: function(override_source) {
		if (override_source) this.source = override_source;
		this.effects.each(function(effect){
			this.parent.job(["this.feature_managers['playlist']",'effect_'+effect],['playlist']);
		},this);
		if (this.onDeploy !== false)
			this.onDeploy(this.source,this.filecount);
		this.parent.job('halt');
		this.parent.job(["this.feature_managers['playlist']",'recall'],['playlist']);
	},
	
	effect_dim: function() {
		this.target.setOpacity(0);
	},
	
	effect_scroll: function() {
		var scroller = new Fx.Scroll(window,{
			duration: 500,
			wait: false
		});
		scroller.toElement($(this.target));
	},
	
	effect_display: function() {
		this.target.setStyle("display","block");
	},
	
	effect_grow: function() {
		this.target.effects({wait:false,duration:1000}).start({
			"margin-top": 20,
			"min-height": 540,
			"opacity": 1
		});
	},
	
	effect_show: function() {
		var cBarExtra = 20;
		var plExtra = 78;
		
		if (this.mode == "playlist") cBarExtra += plExtra;
		
		var width = this.dimensions[0];
		var height = parseInt(this.dimensions[1]) + (!this.hidecontrols ? parseInt(cBarExtra) : 0 );

		//var video = 'base64:'+Base64.encode(this.source);
		//var video = this.source.replace('&','&amp;').replace('?','&#144');
		var video = this.source;
		var info_arr = this.source.split(".");
		var type = info_arr.pop();
		var filename = info_arr.pop().split("/").pop();
		
		var browserversion = navigator.appVersion;
		var is_mac = ((browserversion.toLowerCase().indexOf("mac") != -1) ? true : false);
		
		if (type != "wmv")
		{
			var s1 = new SWFObject("player/flvplayer.swf","pornplayer",width,height,"7");
			s1.addParam("allowfullscreen","true");
			s1.addParam("allowscriptaccess","always");
			s1.addParam("allownetworkaccess","always");
			s1.addVariable("displayheight",this.dimensions[1]);
			s1.addVariable("width",width);
			s1.addVariable("height",height);
			s1.addVariable("file",video);
			if(filename != "interview")
			{
				s1.addVariable("streamscript","lighttpd");
			}
			s1.addVariable("image",this.preview);
			s1.addVariable("enablejs",true);
			s1.addVariable("showdownload",false);
			s1.addVariable("link",false);
			//s1.addVariable("thumbsinplaylist",true);
			s1.addVariable("linkfromdisplay",false);
			s1.addVariable("usekeys",true);
			s1.addVariable("repeat","list");
			s1.addVariable("autostart",this.autostart);
			s1.addVariable("backcolor", "0xFFFFFF");
			s1.addVariable("frontcolor","0x000000");
			s1.addVariable("lightcolor","0xFFFFFF");
			s1.write(this.target);
		}
		if (type == "wmv")
		{
			height += 30;
			if (is_mac)
			{
			
				this.target.setHTML('<embed type="application/x-mplayer2" src="'+video+'" name="MediaPlayer" width="'+width+'" height="'+height+'" showStatusBar="true" scale="ASPECT"></embed>');
			
			}
			else
			{
			
				if (window.ie7)
				{
					this.target.setHTML('<object classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject" width="'+width+'" height="'+height+'" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..."><param name="url" value="'+video+'"><param name="autostart" value="'+this.autostart+'"><param name="ShowStatusBar" value="true"><param name="volume" value="100"></object>');
				}
				else
				{
					this.target.setHTML('<object width="'+width+'" height="'+height+'" type="application/x-mplayer2" ><param name="fileName" value="'+video+'"><param name="autostart" value="'+((this.autostart == 'false') ? 0 : 1)+'"><param name="ShowStatusBar" value="1"><param name="volume" value="0"></object>');
				}
				
			}
		}
	},
	
	recall: function() {
		this.target.setHTML('');
	}

});
