soundManager.useConsole = true;
soundManager.debugMode = false;
soundManager.useHighPerformance = false;
soundManager.url = '/img/js/sm2/';
soundManager.flashVersion = 9;


Draugiem.musicPlayer2 = function( par ){
	this.id = ++ Draugiem.musicPlayer2.id;
	Draugiem.musicPlayer2.createdPlayers.push( this );
	var $musicPlayer2 = this;
	this._ = {
		id:Draugiem.musicPlayer2.id,
		volume:100 //( empty( Draugiem.Cookie.read( 'musicPlayerVolume' ) ) ? 50 : Number( Draugiem.Cookie.read( 'musicPlayerVolume' ) ) )
	};
	this._.node = mkE( { 
		tag:'div',
		className:'musicPlayer2',
		prop:{
			onmousedown:function(){ return false; },
			onselectstart:function(){ return false; },
			oncontextmenu:function(){ return false; },
			style:{
				MozUserSelect:'none'
			}
		},
		els:[
			this._.button = mkE( {
				tag:'div',
				className:'button',
				prop:{
					onclick:function(){
						if( ! $musicPlayer2.sm ) return false;
						if( $musicPlayer2.sm.playState == 0 ){
							Draugiem.musicPlayer2.stopAll();
							$musicPlayer2.sm.play();
							addClassName( $musicPlayer2._.button, 'pause' );
						} else {
							if( $musicPlayer2.sm.paused ){
								Draugiem.musicPlayer2.pauseAll();
								$musicPlayer2.sm.play();
								addClassName( $musicPlayer2._.button, 'pause' );
							} else {
								$musicPlayer2.sm.pause();
								removeClassName( $musicPlayer2._.button, 'pause' );
							}
						}
					} // onclick
				}
			} ),
			this._.rightCont = mkE( {
				tag:'div',
				className:'rightCont',
				els:[
					this._.loading = mkE( {
						tag:'div',
						className:'loading',
						prop:{
							onclick:function( e ){
								if( ! e ) e = event;
								if( e && e.layerX ){																					
									var x = e.layerX;
								} else {																					
									var x = e.x - this.offsetLeft;
								}
								$musicPlayer2.sm.setPosition( Math.floor( x / this.parentNode.offsetWidth * $musicPlayer2.sm.duration ) );
							}
						}
					} ),
					this._.curPosW = mkE( {
						tag:'div',
						className:'curPosW',
						prop:{
							onclick:function( e ){
								if( ! e ) e = event;
								if( e && e.layerX ){																					
									var x = e.layerX;
								} else {																					
									var x = e.x - this.offsetLeft;
								}
								$musicPlayer2.sm.setPosition( Math.floor( x / this.parentNode.offsetWidth * $musicPlayer2.sm.duration ) );
							}
						}
					} ),
					this._.curPos = mkE( { 
						tag:'div',
						className:'curPos',
						prop:{
							onmousedown:function(){
								Draugiem.moveNode.enable( this, function( x, y ){
									if( ! $musicPlayer2.sm || ! $musicPlayer2.sm.duration ) return false;
									if( x < 0 || x > this.parentNode.offsetWidth - this.offsetWidth ) return false;									
									this.style.left = x + 'px';
								} );
							},
							onMoveEnd:function( x ){
								$musicPlayer2.sm.setPosition( Math.floor( x / ( this.parentNode.offsetWidth - this.offsetWidth ) * $musicPlayer2.sm.duration ) );
							}
						}
					} )					
				]
			} ) 
		]
	} );
	this.loadSound( par );
};
Draugiem.musicPlayer2.id = 0;
Draugiem.musicPlayer2.createdPlayers = [];
Draugiem.musicPlayer2.ready = false;
Draugiem.musicPlayer2.setReady = function( v ){
	Draugiem.musicPlayer2.ready = v;
};

Draugiem.musicPlayer2.prototype.append = function( node ){
	if( typeof node == 'object' ){
		node.appendChild( this._.node );
		return this;
	}
	var newNode;
	if( typeof node == 'string' && ( newNode = document.getElementById( node ) ) ){
		newNode.appendChild( this._.node );
		return this;
	}
	return false;
};

Draugiem.musicPlayer2.prototype.loadSound = function( par ){
	var $musicPlayer2 = this;
	if( ! soundManager.enabled ){
		setTimeout( function(){
			$musicPlayer2.loadSound( par );
		}, 500 );
		return;
	}
	var method = 'createVideo';
	if( par.url.substr( par.url.length - 3, 3 ) == 'mp3' ) method = 'createSound';
	this.sm = soundManager[ method ]( {
		id:'musicPlayer2_' + String( this.id ),
		autoLoad:false,
		url:par.url,
		volume:this._.volume,
		whileloading:function(){
			$musicPlayer2._.loading.style.width = String( Math.round( this.bytesLoaded / this.bytesTotal * 100 ) ) + '%';
		}, // whileloading
		whileplaying:function(){
			if( $musicPlayer2.sm.paused ) removeClassName( $musicPlayer2._.button, 'pause' );			
			var node = $musicPlayer2._.curPos;
			if( ! Draugiem.moveNode.nowMoving( node ) && this.duration ){
				var x = ( node.parentNode.offsetWidth - node.offsetWidth ) * this.position / this.duration;
				node.style.left = x + 'px';
				$musicPlayer2._.curPosW.style.width = ( x + node.offsetWidth / 2  ) + 'px';
			}
		}, // whileplaying
		onfinish:function(){
			
		}
	} );
};

Draugiem.musicPlayer2.pauseAll = function(){
	soundManager.pauseAll();
	for( var i = 0; i < Draugiem.musicPlayer2.createdPlayers.length; i ++ ){
		removeClassName( Draugiem.musicPlayer2.createdPlayers[ i ]._.button, 'pause' );
	}
};
Draugiem.musicPlayer2.stopAll = function(){
	soundManager.stopAll();
	for( var i = 0; i < Draugiem.musicPlayer2.createdPlayers.length; i ++ ){
		removeClassName( Draugiem.musicPlayer2.createdPlayers[ i ]._.button, 'pause' );
		Draugiem.musicPlayer2.createdPlayers[ i ]._.curPos.style.left = '0px';
		Draugiem.musicPlayer2.createdPlayers[ i ]._.curPosW.style.width = '0px';
		Draugiem.musicPlayer2.createdPlayers[ i ]._.loading.style.width = '0px'; 
	}
};
