function SoundPlayer(){

    var SOUND_NAME_PREFIX = '/4duk';

    var preMuteVolume = null;
    var playingArchive = false;

    var randSoundsMovie = null;
    var noRandSounds = 0;

    var proxy = "4duk.ru";

    var player = null;
    var playersId = null;

    var playerWindow = null;

    var isPlayingStream = false;
    var isPlayingStuff = false;
    
    var isPlayerUseable = true;
    
   

	// ------------------------------------------------------------------------------------------------------------------------
	// 										random sounds part (actual /flash/4duk.swf)
	// ------------------------------------------------------------------------------------------------------------------------
    this.setRandomSoundsMovie = function(objectId, noOfSounds){
        randSoundsMovie = getMovie(objectId);
        if(!randSoundsMovie){
            isPlayerUseable = false;
//            throw new Error("Can not find random sounds movie with id: " + objectId + "\nMake sure there exists an object with this id!");
        }
        if(noOfSounds < 1){
            throw new Error("You must specify how many sounds are in random sounds movie, must be more than 0. You said there are: " + noOfSounds + " sounds in this movie");
        }
        noRandSounds = noOfSounds;
    }

    this.playSoundRandom = function() {
        if (isPlayerUseable) {
	        var soundNumber = Math.round(Math.random() * noRandSounds) + 1;
    	    this.playSoundNo(soundNumber);
    	    }
    }

    this.playSoundNo = function(soundNumber) {
        if (isPlayerUseable) {
	        var movie = randSoundsMovie;
    	    if(movie == null) {
        	    throw new Error("Call SoundPlayer.setRandomSoundsMovie() first! ");
            	return;
	        }
	        var soundName = SOUND_NAME_PREFIX + soundNumber;
	        movie.TPlay(soundName);
	    }
	}
	// ------------------------------------------------------------------------------------------------------------------------
	// 										stream part (actual /flash/online.swf)
	// ------------------------------------------------------------------------------------------------------------------------

    this.setFlashPlayer = function(playerId){
        //player = getMovie(playerId);
        //playersId = playerId;
        //if( player == undefined || player == null ){
        //    throw new Error("Can not find flash player with id: " + playerId + "\nMake sure there exists an object with this id!");
        //}
    }

    this.playStream = function() {
        if (isPlayerUseable) {
	        // if was muted by stop method
	        if(preMuteVolume != null) { this.unmute(); }
	        //player.playStream();

	        isPlayingStream = true;
		}
    }

    this.itemToPlayId = 0;

    this.playArchive = function(id) {
        if (isPlayerUseable) {

	    	if(id == null || id == 'undefined'){
	        	id = this.itemToPlayId;
	      } else {
	        	this.itemToPlayId = id;
	      }

	      isPlayingStream = false;
	      isPlayingStuff = true;

		}
    }

    this.stop = function(){
        isPlayingStream = false;
        isPlayingStuff = false;
    }

    this.isPlaying = function(){
    		return isPlayingStream || isPlayingStuff;
    }

    this.isPlayingStream = function(){
        return isPlayingStream;
    }

    this.isPlayingArchive = function(){
        return this.isPlaying() && !isPlayingStream;
    }

    this.getPlayingArchiveId = function(){
    	return this.itemToPlayId;
    }

    this.setVolume = function(newVolume){
        //player.setVolume(newVolume);
    }

    this.getVolume = function(){
        //player.getVolume();
    }

    this.mute = function(){
        //preMuteVolume = player.getVolume();
        //player.setVolume(0);
    }

    this.unmute = function(){
    	//if(preMuteVolume != null){	// indicates that player was muted before
    	//	player.setVolume(preMuteVolume);
    	//}
    	//preMuteVolume = null;
    }

    this.isMuted = function(){
    	return preMuteVolume != null;
    }

    this.pause = function(){
        //if(player.isPlaying()) player.stopSound();
    }

    this.resume = function(){
        //try{
        //    player.startSound();
        //} catch (e) {
        //    if(DEBUG){ console.debug("PLAYER: was not able to restart sound"); }
       // }
    }

    function getMovie(id) {
        if(document[id]) {
            return document[id];
        } else {
            return window[id];
        }
    }
    
    this.isUseable = function() {
    	return isPlayerUseable;
    }

    function checkPlayerExists(){
        if(player == null || !player) {
            alert("Call SoundPlayer.setFlashPlayer() first, and make sure you set correct id!");
            return;
        }
    }
}