function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollTop() { 
	return f_filterResults ( window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0 ); 
}
	
var currentAlbum = "";
var currentSample = "";

function showSongList(album, e) {
	if (currentAlbum == album) return;

	hideSongList();	

	var posx = 0;
	var posy = 0;

	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + f_scrollTop();
	}	

	var albumDiv = document.getElementById(album);
	
	myHeight = albumDiv.getAttribute("myHeight");
	myWidth = albumDiv.getAttribute("myWidth");
	
	if (brow=='Safari') {
		var myClient = e.clientY - f_scrollTop();
		if ((parseInt(myClient) + parseInt(myHeight) + 80) > parseInt(screen.availHeight)) {
			posy = posy - myHeight;
		} 
	} else {
		if ((parseInt(e.clientY) + parseInt(myHeight) + 80) > parseInt(screen.availHeight)) {
			posy = posy - myHeight;
		} 
	}

	if ((parseInt(e.clientX) + parseInt(myWidth) + 80) > parseInt(screen.availWidth)) {
		posx = posx - myWidth;
	}

	albumDiv.style.top = "" + posy + "px";
	albumDiv.style.left = "" + posx + "px";
	albumDiv.style.display = "block";
	currentAlbum = album;
}
	
function hideSongList() {
	if (currentAlbum == "") return;

	var albumDiv = document.getElementById(currentAlbum);
	albumDiv.style.display = "none";
	
	stopMusic();
	currentAlbum = "";
}

function startMusic_songlist() {
	alert("A sample of this track will be available soon.");
}

function startSampleLag(sample) {
  if (brow=='Safari') {
    window.setTimeout('startSample(' + sample + ')', 6000);
  } else {
    window.setTimeout('startSample(' + sample + ')', 2000);
  }
}

function startSample(sample) {
	soundManager.stop(currentSample);
	soundManager.play(sample);
	currentSample = sample;
}

function stopSample(sample) {
	if (currentSample == "") return;
	soundManager.stop(currentSample);
}
