/**
 * openPlayer(sURL, iWidth, iHeight)
 *
 * Open the 'embedded' player with the given url.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [string]  sURL    - the url to the player with the movie as argument (GET).
 * @param   [integer] iWidth  - the width of the player window.
 * @param   [integer] iHeight - the height of the player window. 
 * @return  [void]
 */
function openPlayer(sURL, iWidth, iHeight) {
	if(sURL != '') {
		iWidth = (iWidth) ? iWidth : 650;
		iHeight = (iHeight) ? iHeight : 300;
		
		var randomnumber = Math.floor(Math.random()*101);
		var iLeftPos = (screen.availWidth - iWidth) / 2;
		var iTopPos = (screen.availHeight - iHeight) / 2; 
		var sOpts = "toolbar=no, status=no, location=no, menubar=no, resizable=yes,";
		    sOpts += " width=" + iWidth + ", height=" + iHeight + ", scrollbars=no,";
		    sOpts += "top=" + iTopPos + ",left=" + iLeftPos;
		var eDialog = window.open("", "moviePlayer" + randomnumber, sOpts);
		eDialog.location = sURL;
		eDialog.focus();
	}
	return false;
}

function openSoloPlayer(sURL, iWidth, iHeight) {
	iWidth = iWidth + 5;
	iHeight = iHeight + 5;
	
	openPlayer(sURL, iWidth, iHeight);
	
	return false;
}

function openPopup(link) {
	if (link != '') {
		window.open(link,"3fmfanPopup","width=780,height=500,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,titlebar=no");
	}
	
	return false;
}

function trackOptionsOpenLink(selectedOption) {
	// Interne links in zelfde venster openen, andere in nieuw venster
	if(selectedOption.value == "") {
		return false;
	} else if(selectedOption.index == 1 || selectedOption.index == 2) {
		window.location=selectedOption.value;
	} else {
		window.open(selectedOption.value,"3fmfanNew");
	}
}

function showTrackOptions(artist, title) {
	//document.write(artist + title);
	document.write('<select class="trackOptions" onchange="trackOptionsOpenLink(this.options[this.selectedIndex])">');
	document.write('<option value="" selected="selected">-- Extra opties --</option>');
	document.write('<optgroup label="Zoeken">');
	document.write('<option value="' + siteURL + 'page/muziekstats/zoeken?zoekop=artiest&opdracht=' + artist + '">Zoek op artiest</option>');
	document.write('<option value="' + siteURL + 'page/muziekstats/zoeken?zoekop=titel&opdracht=' + title + '">Zoek op titel</option>');
	document.write('</optgroup>');
	document.write('<optgroup label="Audio/video">');
	document.write('<option value="http://www.last.fm/music?m=all&q=' + artist + ' ' + title + '">Last.FM</option>');
	document.write('<option value="http://nl.youtube.com/results?search_query=' + artist + ' ' + title + '">Youtube</option>');
	document.write('<option value="http://www.imeem.com/tag/' + artist + ' ' + title + '/">imeem</option>');
	document.write('</optgroup>');
	document.write('<optgroup label="Meer informatie">');
	document.write('<option value="http://nl.wikipedia.org/wiki/Speciaal:Zoeken?search=' + artist + '">Artiest op Wikipedia NL</option>');
	document.write('<option value="http://en.wikipedia.org/wiki/Special:Search?search=' + artist + '">Artiest op Wikipedia EN</option>');
	document.write('<option value="http://www.google.nl/search?q=%22' + artist + '%22 %22' + title + '%22 lyrics">Songtekst (via Google)</option>');
	document.write('<option value="http://www.google.nl/search?q=%22' + artist + '%22 %22' + title + '%22">Zoeken via Google</option>');
	document.write('</optgroup>');
	document.write('</select>');
}

// Date functions
function transformMillisecondsToDate(ms) {
	var x = ms / 1000;
	var seconds = Math.floor(x % 60);
	x /= 60;
	var minutes = Math.floor(x % 60);
	x /= 60;
	var hours = Math.floor(x % 24);
	x /= 24;
	var days = Math.floor(x);
	
	seconds = seconds.toString();
	if(seconds.length < 2) {
		seconds += "0";
	}
	
	return minutes + ":" + seconds;
}