CH.ns(function() {with(CH) {
	Playlist = Class.create({
		initialize: function(options) {

			this.setOptions(options);
			
			this.so = new SWFObject("/moogaloop/moogaloop.jukebox.swf", "moogaloop", "947", "362", "8", "#000000");
			this.contplayforced = true;
			
			if(this.options.use_hash == true) {
				this.checkHash();
			}
			
			FastInit.addOnLoad(function() {
			new scrollwheel({playlist: this});
			}.bind(this));
		},
		
		checkHash: function() {
			var hashId = self.document.location.hash.substr(1);

			if(hashId != '' && this.options.current_id != hashId) {
				this.options.current_id = hashId;
				
				FastInit.addOnLoad(function() {
					this.loadColumn(hashId);
				}.bind(this));
			}
				
		},
		
		disablePopup: function () {
			$('scrolled_infobox').hide();
            
            createCookie('continuous_infobox_hide', true, 7);
		},
		
		flashVariable: function(key, val) {
			$('moogaloop').flash_variable(key, val);
		},

		hookupPlayer: function() {
			this.so.addParam("quality", "best");
			this.so.addParam("allowfullscreen", "true");
			this.so.addParam("allowScriptAccess", "always");
			this.so.addParam("wmode", "transparent");
			this.so.addVariable("clip_id", this.options.current_id);
			this.so.addVariable("autostart", "true");
			this.so.addVariable("fullscreen", "1");
			this.so.addVariable("cont_play", this.options.cont_play);
			this.so.addVariable("server", this.options.server);
			this.so.addVariable("context", this.options.context);
			this.so.addVariable("context_url", this.options.context_url);
			this.so.addVariable("is_playlist", this.options.is_playlist);
			this.so.addVariable("trigger_t", this.options.trigger_t);
			this.so.addVariable("trigger_v", this.options.trigger_v);
			this.so.write("flash_player");
		},
		
		loadColumn: function(clip_id) {
			if(this.showWaiting()) {
                new Req.ajax({
                    url: '/ajax/video/refresh_continuous_columns_center/',
                    options: {
                        parameters: 'video_id=' + clip_id + '&context=' + this.options.context + '&ad_zone=' + Vars.ad_zone + '&is_playlist=' + this.options.is_playlist,
						onlyLatestOfClass: 'load_column',
						onComplete: function() {
							if($('continuous_columns_center').childNodes.length <= 1) { // validate that some data made it in
								$('continuous_columns_center').update("<div style='text-align:center'><h3>Error</h3>We were unable to load data for this video.<br />Try reloading the page.</div>");
							} else {
								this.refresh_ads();
							}
						}.bind(this)
                    }
                });
                
                urchinTracker('videos/continuousplayer/item/' + clip_id);
				gTrack('video:' + clip_id + '/continuous');
            }
		},
		
		 refresh_ads: function(){
			var reload_units = new Array();
			reload_units = [['', 'SKIN'], ['billboardAd', '300x250'], ['', 'POSTROLL'], ['banner_header', '728x90'], ['banner_footer', '728x90_FOOTER'], ['', 'PLAYLIST_HEADER'], ['', 'OVERLAY']];
			ads.reload(reload_units);
        },
        
        selectPlaylistItem: function(clip_id) {
			this.loadColumn(clip_id);
			
			if(this.options.use_hash == true) {
                location.href = "#" + clip_id;
			}
		},
        
		showWaiting: function() {
            if($('continuous_columns_center')) {
               if($('continuous_columns_center').update("<div style='text-align:center'><img src='/artwork/jester_animated.gif' /><h3>Loading</h3></div>")) {
                   return true;
               }
		   }
        },
        
        toggleContinuous: function (onoff) {
			this.contplayforced = onoff;
			createCookie('continuous_autoplay', onoff, 7);
		},
		
        toggleCountdown: function (onoff) {
        	var info_box = $('scrolled_infobox');
        	
			if(this.contplayforced != false) {
				var pop_disabled = (readCookie('continuous_infobox_hide') != '' ? true : false);
				
				if(onoff) {
					info_box.fade({duration: 0.1});
				} else if(pop_disabled == 0) {
					info_box.appear({duration: 0.2});
				}
				
				$('moogaloop').toggle_countdown(onoff);
			} else {
				info_box.fade({duration: 0.1});
			}
		},
		
		setOptions: function (options) {
			this.options = {
				player: options.player
			};
			Object.extend(this.options, options || {});
		}
	});
}});