	
	var player = {
		
		plugin: {},
		obj: {},
		current: 0,
		autoplay: false,
		playlist: [],
		state: 0,
		
		load: function() {
			
			$("#tvplayer_container").html("<div id='tvplayer'>&nbsp;</div>");
			
			$("tr.player-item").removeClass("player-current");
			$("tr#player-item-" + this.current).addClass("player-current");
			
			var arr = this.plugin.load(player.playlist[player.current]);
			
			swfobject.embedSWF(arr.src, "tvplayer", w, h, "9.0.0", "/core/contrib/swfobject/expressInstall.swf", arr.vars, {
				allowScriptAccess:	"always",
				wmode:							"transparent",
				quality:						"best",
				allowFullScreen:		"true",
				width:							w,
				height:							h
			}, null, function(e){
				
				player.obj = window.document.getElementById(e.id);
				
			});
			
		},
		
		jump: function(to) {
			
			this.current = to;
			this.load();
			
		},
		advance: function(to) {
			
			to = to > 0 ? 1 : -1;
			
			this.current = (this.playlist[this.current + to]) ? this.current + to : (to > 0 ? 0 : this.playlist.length - 1);
			
			this.load();
			
		},
		prev: function() { this.advance(-1); },
		next: function() { this.advance(1); },
		
		init: function() {
			
			this.load();
			
			$("a.button-play").click(function(){	player.plugin.play(); return false; });
			$("a.button-stop").click(function(){	player.plugin.stop(); return false; });
			$("a.button-pause").click(function(){ player.plugin.pause(); return false; });
			$("a.button-prev").click(function(){	player.prev(); return false; });
			$("a.button-next").click(function(){	player.next(); return false; });
			
			$("tr.player-item a").click(function(){
				
				var id = $(this).closest("tr.player-item").attr("id").replace(/[^0-9]/ig, "");
				player.jump(id);
				
				return false;
				
			});
			
		},
		
		stateChange: function(state) {
			
			this.state = state;
			
			if (this.state) {
				
				$("a.button-play").hide();
				$("a.button-pause").css("display", "block");
				
			} else {
				
				$("a.button-play").css("display", "block");
				$("a.button-pause").hide();
				
			}
			
		},
		
		ready: function() {
			
			if (this.state || this.autoplay) setTimeout("player.plugin.play()", 300);
			
		}
		
	}
	
	$(document).ready(function(){
		
		player.init();
		
	});

