
var myListener = new Object();

myListener.onInit = function() {
	this.position = 0;
};


/*
this.isPlaying;
this.url;
this.volume;
this.position;
this.duration;
this.bytesLoaded
this.bytesTotal
this.bytesPercent
this.isPlaying == "true"

*/

var jsFlashPlayer = new Object();
jsFlashPlayer.myListener = new Object();
jsFlashPlayer.myListener.onInit = function() {
	this.position = 0;
};

jsFlashPlayer.myListener.onUpdate = function() {
	var isPlaying = (this.isPlaying == "true");
	
	var div_Progress = document.getElementById('flashplayer_progress_div');
	
	var progressWidth = ((this.position/this.duration)*jsFlashPlayer.img_PlayIcon.width);
	if (!progressWidth > 0) {
		progressWidth = 0;
	}
	div_Progress.style.width = progressWidth;
	
	
	if (this.duration > 2500 && this.duration - this.position < 2500 && this.volume > 0) {
		jsFlashPlayer.getFlashObject().SetVariable("method:setVolume", this.volume - 4);
	} else if (this.duration - this.position > 2500 && this.volume != 100) {
		jsFlashPlayer.getFlashObject().SetVariable("method:setVolume", 100);
	}
	
	var int_Img1Left = getRelativePos(jsFlashPlayer.img_PlayIcon).offsetLeft;
	var int_Img1Top = getRelativePos(jsFlashPlayer.img_PlayIcon).offsetTop;
	
	div_Progress.style.position = 'absolute';
	if (isIE()) {
		div_Progress.style.left = int_Img1Left+2;
	} else {
		div_Progress.style.left = int_Img1Left+1;
	}
	div_Progress.style.top = int_Img1Top+1;
	
	if(!isPlaying) {
		jsFlashPlayer.stop();
		jsFlashPlayer.img_PlayIcon.src = '/images/icons/icon_play.gif';
	} else {
		if (this.position > 1 && jsFlashPlayer.img_PlayIcon.src.indexOf('icon_playing_fast.gif') == -1 && !jsFlashPlayer.isPaused) {
			jsFlashPlayer.img_PlayIcon.src = '/images/icons/icon_playing_fast.gif';
		}
	}
}



jsFlashPlayer.play = function(str_Serial, str_PlayIconId) {
	this.getFlashObject().SetVariable("method:setVolume", 100);
	if(this.str_SongPlaying == str_Serial) {
		if (!this.isPaused) {
			this.pause();
			jsFlashPlayer.img_PlayIcon.src = '/images/icons/icon_play.gif';
		} else {
			this.getFlashObject().SetVariable("enabled", "true");
			this.getFlashObject().SetVariable("method:play", "");
			this.isPaused = false;
		}
	} else {
		if (this.img_PlayIcon) {
			this.img_PlayIcon.src = '/images/icons/icon_play.gif';
		}
		this.getFlashObject().SetVariable("method:setUrl", '/song_sample.php?song='+str_Serial);
		this.getFlashObject().SetVariable("method:setPosition", 0);
		this.getFlashObject().SetVariable("method:play", "");
		this.getFlashObject().SetVariable("enabled", "true");
		this.isPaused = false;
		this.str_SongPlaying = str_Serial;
		var img_PlayIcon = document.getElementById(str_PlayIconId);
		if (img_PlayIcon) {
			if(!document.getElementById('flashplayer_progress_div')) {
				this.div_Progress = document.createElement('div');
				this.div_Progress.id = 'flashplayer_progress_div';
				this.div_Progress.style.display = 'none';
				document.body.appendChild(this.div_Progress);
			} else {
				this.div_Progress = document.getElementById('flashplayer_progress_div');
				this.div_Progress.style.display = 'none';
			}
			this.div_Progress.onclick = function(){img_PlayIcon.onclick()};
			var int_Img1Left = getRelativePos(img_PlayIcon).offsetLeft;
			var int_Img1Top = getRelativePos(img_PlayIcon).offsetTop;
			
			this.div_Progress.style.position = 'absolute';
			if (isIE()) {
				this.div_Progress.style.left = int_Img1Left+2;
			} else {
				this.div_Progress.style.left = int_Img1Left+1;
			}
			this.div_Progress.style.top = int_Img1Top+1;
			this.div_Progress.style.width = 1;
			this.div_Progress.style.height = img_PlayIcon.height;
			this.div_Progress.alt = img_PlayIcon.alt;
			this.div_Progress.style.cursor = img_PlayIcon.style.cursor;
			this.div_Progress.title = img_PlayIcon.title;
			
			this.div_Progress.style.backgroundColor = '#CC6666';
			//if (isIE()) {
				this.div_Progress.style.filter = 'alpha(opacity=60)';
			//} else {
				this.div_Progress.style.opacity=0.6;
			//}
			this.div_Progress.style.zIndex = 99;
			this.div_Progress.style.display = 'block';
			this.img_PlayIcon = img_PlayIcon;
		} else {
		}
	}
};

jsFlashPlayer.getFlashObject = function() {
	return document.getElementById("FlashPlayer");
};

jsFlashPlayer.pause = function() {
	this.getFlashObject().SetVariable("enabled", "false");
	this.getFlashObject().SetVariable("method:pause", "");
	this.isPaused = true;
}

jsFlashPlayer.stop = function() {
	this.getFlashObject().SetVariable("method:stop", "");
	this.getFlashObject().SetVariable("method:setUrl", '');
	this.getFlashObject().SetVariable("enabled", "false");
	this.str_SongPlaying = '';
}
