// required cookie.js file

function Mp3Player() {
	this.width  = 250,
	this.height = 180,
	this.left   = 0, // Math.round((screen.availWidth - this.width) / 2),
	this.top    = 0, // Math.round((screen.availHeight - this.height) / 2),
	
	this.windowName  = 'mpWindow',
	this.windowTitle = 'MediaPlayer',
	
	this.flashVer       = '8.0.0',
	this.identity       = 'mp3Player',
	this.popupUrl       = 'modules/blocks/mplayer/mplayer.html',
	this.playerFilePath = '../../../images/mplayer/playerMultipleList.swf',
	this.playlistPath   = '../../../files/mp3/playlist.xml',
	this.autoPlay       = 'yes',
	
	this.disabledCssClass = 'disabled',
	
	this.cookieName = 'mp3player'
}

Mp3Player.prototype = {

	init: function() {
		var oThis = this;		
		Event.observe(window, 'load', function() { oThis.run(); });	
    },
    
    run: function() {    	
    	switch (Cookie.read(this.cookieName)) {
    		case '0': 
    			this.iconDisable();    			
    			break;
    		case '1':
    			this.iconEnable();    			
    			break;
    		default:    			
    			this.showPlayer();    			    			
    	}
    },

	showPlayer: function() {
    	Cookie.create(this.cookieName, '1');
    	
    	var url = this.popupUrl + '?playerFilePath=' + this.playerFilePath + '&identity=' + this.identity + '&width=' +  this.width + '&height=' + this.height + '&flashVer=' + this.flashVer + '&playlistPath=' + this.playlistPath + '&autoPlay=' + this.autoPlay + '&windowTitle=' + this.windowTitle + '&disabledCssClass=' + this.disabledCssClass;
    	
    	mpWin = window.open(url, this.windowName,'width='+ this.width +', height='+ this.height +', left='+ this.left +', top='+ this.top +', screenX='+ this.left +', screenY='+ this.top +', directories=0, location=0, menubar=0, toolbar=0, status=0, resizable=0, scrollbars=0');
    	
    	/*mpWin.document.open();
    	mpWin.document.write('<html><head><title>'+ this.windowTitle +'</title><script type="text/javascript" src="js/swfobject.js"></script></head>');
    	mpWin.document.write('<body style="margin: 0px; padding: 0px; background-color: #FFFFFF;" onunload="window.opener.document.getElementById(\'' + this.identity + '_control\').className=\'' + this.disabledCssClass + '\';window.opener.document.getElementById(\'' + this.identity + '_control\').onclick();">');
    	mpWin.document.write('<div id="' + this.identity + '"></div>');
    	mpWin.document.write('<script type="text/javascript">swfobject.embedSWF(\'' + this.playerFilePath + '\', \'' + this.identity + '\', \'' + this.width + '\', \'' + this.height + '\', \'' + this.flashVer + '\', \'\', {playlistPath:\'' + this.playlistPath + '\',autoPlay:\'' + this.autoPlay + '\'}, {quality:\'best\',wmode:\'transparent\'}, {id:\'' + this.identity + '_flash\',name:\'' + this.identity + '_flash\'});</script>');
    	mpWin.document.write('</body></html>');		
    	mpWin.document.close();*/
    	    	
    	this.iconEnable();
    },
    
    enable: function() {
    	if (Cookie.read(this.cookieName) != '1') {
    		this.showPlayer();
    	}
    },
    
    disable: function() {
    	if (Cookie.read(this.cookieName) == '1') {
    		Cookie.create(this.cookieName, '0'); 
    		
    		if (!$(this.identity + '_control').hasClassName(this.disabledCssClass)) {
	    		mpWin = window.open('', this.windowName,'width='+ this.width +', height='+ this.height +', left='+ this.left +', top='+ this.top +', screenX='+ this.left +', screenY='+ this.top +', directories=0, location=0, menubar=0, toolbar=0, status=0, resizable=0, scrollbars=0');
		    	mpWin.document.open();
		    	mpWin.document.write('<html><head><title>'+ this.windowTitle +'</title></head>');
		    	mpWin.document.write('<body style="margin: 0px; padding: 0px; background-color: #FFFFFF;" onload="window.close();" >');
		    	mpWin.document.write('</body></html>');		
		    	mpWin.document.close();    	
    		}
    		
	    	this.iconDisable();	    	
    	}
    },
    
    iconEnable: function() {
    	var oThis = this;
    	
    	$(this.identity + '_control').onclick = function() { oThis.disable(); return false; };
    	
    	$(this.identity + '_control').removeClassName(this.disabledCssClass);   	
    },
    
    iconDisable: function() {
    	var oThis = this;
    	
    	$(this.identity + '_control').onclick = function() { oThis.enable(); return false; };
    	
    	$(this.identity + '_control').addClassName(this.disabledCssClass);    	
    }
        
}