function soundError(e) { }
var player = {
	callback: false,
	is_play: { status:false, file:'' },
	player_add_class: 'plaing',
	locations: { micro_player:"/f/1/global/MicroPlayer.swf", express:"/f/1/global/gallery/expressInstall.swf" },
	params: {
		width:1,
		height:1,
		version:"9.0.0",
		params:{ allowScriptAccess: "always", allowNetworking:"true" },
		flashvars:{}
	},
	init:function(locations, params) {
		this.locations =$.extend(this.locations, locations ? locations : {});
		this.params =$.extend(this.params, params ? params : {});
		this.id = 'micro_flash_player';
		var that = this;
		$("<div></div>").attr({ id:that.id }).appendTo("body");
		
		if(swfobject.hasFlashPlayerVersion("9.0.0")){
			swfobject.embedSWF(
				that.locations.micro_player,
				that.id,
				that.params.width,
				that.params.height,
				that.params.version,
				that.locations.express,
				that.params.flashvars,
				that.params.params,
				{id:that.id,name:that.id, style:"position:absolute;top:-10000px;left:-10000px;"},
				that.alert_status
			);
		} else {
			this.no_flash();
		}
	},
	no_flash:function(){
		$("html").addClass("no_flash");
	},
	start:function(file, handler, callback) { /* click start play */
		if (this.is_play.status) this.stop();
		this.is_play = { status:true, file:file };
		this.handler = $(handler).addClass(this.player_load_class);
		document.getElementById(this.id).playSound(file);
		!this.callback || this.callback(this, 'start');
	},
	end:function() { /* when music is stopped */
		this.is_play = { status:true, file:'' };
		this.handler.removeClass(this.player_add_class);
		!this.callback || this.callback(this, 'end');
	},
	stop:function() { /* click stop play */
		this.is_play = { status:true, file:'' };
		document.getElementById(this.id).stopSound();
		this.handler.removeClass(this.player_load_class).removeClass(this.player_add_class);
		!this.callback || this.callback(this, 'stop');
	},
	onLoadComplete:function(){
		this.handler.removeClass(this.player_load_class).addClass(this.player_add_class);
		!this.callback || this.callback(this, 'load');
	},
	alert_status:function(e) { /*alert(e.success ? "flash is appended" : "flash was not appented");*/ },
	error:function() { /*alert("Error with input/output");*/ },
	click:function(file, handler,callback){
		this.callback = callback || false;
		!this.is_play.status || this.is_play.file != file ? this.start(file, handler) : this.stop();
	}
}


$(function() {
	player.init();
});

function drummMicroPlayer(file, handler){
	player.click(file, handler, function(p, action){
		if(action=="start") {
			handler.innerHTML = handler.innerHTML.replace("Включить", "Выключить");
			$("ins", handler).before('<img class="micro-loader" width="16" height="16" style="vertical-align:middle;position:absolute; left:-20px;top:0;margin:0;padding:0;width:16px;height:16px;" src="/f/1/global/loader.gif" />');
			$("ins", handler).removeClass("selected")
		} else if(action=="load") {
			$("img.micro-loader", handler).remove();
			
		} else {
			handler.innerHTML = handler.innerHTML.replace("Выключить", "Включить");
			$("img.micro-loader", handler).remove();
			$("ins", handler).addClass("selected");
		}
	});
}
