

	// ---------------------------------------------------------------------------------------
	// JAVASCRIPT DOCUMENT FOR MP3 PLAYER
	// ---------------------------------------------------------------------------------------
	

// Read cookie functions
function readUnescapedCookie(cookieName) {
	var cookieValue = document.cookie;
	var cookieRegExp = new RegExp("\\b" + cookieName + "=([^;]*)");
	cookieValue = cookieRegExp.exec(cookieValue);
	
	if (cookieValue != null) {
		cookieValue = cookieValue[1];
	}
	return cookieValue;
}

function readCookie2(cookieName) {

	cookieValue = readUnescapedCookie(cookieName);
	
	if (cookieValue != null) {
		cookieValue = unescape(cookieValue);
	}
	return cookieValue;
}

// Open playlist function
function openPlaylist(query_string) {

	if (document.cookie) {
		// Gets current time
		var now = new Date();
		var timestamp = (now.getTime() - now.getMilliseconds()) / 1000;
		
		var difference = (timestamp - readCookie2("PlaylistTime"));
		
		// ------------------------------------------------------
		// OUTPUTS THE DETAILS FOR TESTING PURPOSES
		// ------------------------------------------------------
		
		//alert(timestamp + ' = Time now');
		//alert(readCookie("PlaylistTime") + ' = Cookie time');
		//alert('Time difference = ' + difference + ' seconds');
		
				
		if (difference > 2) {
			var playlist = window.open('playlistClear.php'+query_string,'newWin','width=275,height=376,left=0,top=0,toolbar=no,location=no,scrollbars=no,status=no,resizable=yes,fullscreen=no');  
			playlist.focus();
		} else {
			var playlist = window.open('playlist.php'+query_string,'newWin','width=275,height=376,left=0,top=0,toolbar=no,location=no,scrollbars=no,status=no,resizable=yes,fullscreen=no');  
			playlist.focus();			
		}
	} else {
		var playlist = window.open('playlist.php'+query_string,'newWin','width=275,height=376,left=0,top=0,toolbar=no,location=no,scrollbars=no,status=no,resizable=yes,fullscreen=no');  
		playlist.focus();
	}

}

// Writes cookie
function writeCookie2(cookieName, cookieValue) {
	
	var cookieDetails = cookieName + "=" + escape(cookieValue);
	document.cookie = cookieDetails;
	timer();
}

// Timer to loop with writeCookie()
function timer() {
	now = new Date();
	timestamp = (now.getTime() - now.getMilliseconds()) / 1000;
	setTimeout("writeCookie2('PlaylistTime',timestamp)",1000);
}
