 
var currentPlaylist = new Object();
var currentIndex = -1;
var modPass = null;

var pMPlayer;
var pShuffleCBox;
var pSongInfo;
var pSearchResult;
var pSearchPageNumber;
var pSearchForm;
var pPlaylist;
var pCurrentPlaylistName;
var pCurrentPlaylistInfo;
var pPlaylistMenu;
var pPlaylistResult;
var pPlaylistPageNumber;
var pRecentSearchesPanel;
var pRecentSearches;
var pSearchBox;
var pSearchTabs;
var pChatAgent;


function initMusic(mPlayer, shuffleCBox, songInfo, searchResult, searchPageNumber, searchForm, playlist,
		currentPlaylistName, currentPlaylistInfo, playlistMenu, playlistResult, playlistPageNumber,
		recentSearchesPanel, recentSearches, searchBox, songSearchBox, playlistSearchBox, searchTabsElem, chatAgent)
{
	pMPlayer = mPlayer;
	pShuffleCBox = shuffleCBox;
	pSongInfo = songInfo;
	pSearchResult = searchResult;
	pSearchPageNumber = searchPageNumber;
	pSearchForm = searchForm;
	pPlaylist = playlist;
	pCurrentPlaylistName = currentPlaylistName;
	pCurrentPlaylistInfo = currentPlaylistInfo;
	pPlaylistMenu = playlistMenu;
	pPlaylistResult = playlistResult;
	pPlaylistPageNumber = playlistPageNumber;
	pRecentSearchesPanel = recentSearchesPanel;
	pRecentSearches = recentSearches;
	pSearchBox = searchBox;
	searchTabs[0].content = songSearchBox;
	searchTabs[1].content = playlistSearchBox;
	pSearchTabs = searchTabsElem;
	pChatAgent = chatAgent;


	var songId = null;
	var songName = null;
	var playlistId = null;
	var searchString = null;

	var query = window.location.search;
	if (query != "") {
		var params = query.substr(1).split("&");
		for (var i=0; i<params.length; i++) {
			var tokens = params[i].split("=");
			if (tokens[0] == "songId")
				songId = tokens[1];
			else if (tokens[0] == "songName")
				songName = tokens[1];
			else if (tokens[0] == "playlistId")
				playlistId = tokens[1];
			else if (tokens[0] == "search")
				searchString = tokens[1];
			else if (tokens[0] == "pass")
				modPass = tokens[1];
		}
	}

	if (songId != null && songName != null)
		playSong(songId, decodeURIComponent(songName));
	
	if (playlistId != null)
		loadPlaylistAutoplay(playlistId, true);
	else
		newPlaylist();
	
	if (searchString != null) {
		setSearchString(decodeURIComponent(searchString));
		doSearch();
	}
	else {
		setSearchString("[history]");
		doSearch();
	}
	
	setTimeout('albumQuery("")', 3000);
	pSearchBox.removeChild(searchTabs[1].content);
}

getUserStatusMessage = override(getUserStatusMessage, function(superHandler, userInfo) {
	if (typeof(userInfo.songId) != 'undefined')
		return "<i>&#x0111;ang nghe</i> <a href=\"javascript:playSong(" + userInfo.songId + ",'" + userInfo.songTitle.replace("'", "\\'") + "')\">" + userInfo.songTitle + "</a>";
	else
		return superHandler(userInfo);
});


//playback ---------------------------------------

function playSong(songId, songTitle) {
	var song = new Object();
	song.id = songId;
	song.title = songTitle;
	song.hits = "";
	playFile(song);
	showSongInfo(song);
}

function playFile(song) {
	pMPlayer.playFile(Number(song.id), String(song.title));
	me.songId = song.id;
	me.songTitle = song.title;
	pChatAgent.setUserInfo(me);
}

function isCursorValid() {
	return currentIndex >= 0 && currentIndex < currentPlaylist.entries.length;
}

function resetPlayCounts() {
	for (var i=0; i<currentPlaylist.entries.length; i++)
		if (currentPlaylist.entries[i] != null)
			currentPlaylist.entries[i].playCount = 0;
}

function getUnplayedIndices() {
	var entries = new Array();
	for (var i=0; i<currentPlaylist.entries.length; i++) {
		if (currentPlaylist.entries[i] != null && !currentPlaylist.entries[i].playCount)
			entries.push(i);
	}
	return entries;
}

function playNextSong() {
	if (pShuffleCBox.checked) {
		var unplayed = getUnplayedIndices();
		if (unplayed.length == 0) {
			resetPlayCounts();
			unplayed = getUnplayedIndices();
		}
		if (unplayed.length > 0) {
			var i = Math.floor(Math.random()*unplayed.length);
			pl_playSong(unplayed[i]);
		}
	}
	else {
		var playList = currentPlaylist.entries;
		if (isCursorValid()) {
			for (var i=1; i<=playList.length; i++) {
				var index = (currentIndex + i) % playList.length;
				if (playList[index] != null) {
					pl_playSong(index);
					break;
				}
			}
		}
		else {
			for (var i=0; i<playList.length; i++) {
				if (playList[i] != null) {
					pl_playSong(i);
					break;
				}
			}
		}
	}
}

function playPreviousSong() {
	var playList = currentPlaylist.entries;
	if (isCursorValid()) {
		for (var i=1; i<=playList.length; i++) {
			var index = (playList.length + currentIndex - i) % playList.length;
			if (playList[index] != null) {
				pl_playSong(index);
				break;
			}
		}
	}
	else {
		for (var i=playList.length-1; i>=0; i--) {
			if (playList[i] != null) {
				pl_playSong(i);
				break;
			}
		}
	}
}

function songFinished() {
	var unplayed = getUnplayedIndices();
	if (unplayed.length == 0) {
		resetPlayCounts();
		return;
	}
	playNextSong();
}


//song information ------------------------------------

function sr_showSongInfo(index) {
	showSongInfo(searchResult.pages[searchResult.currentPage][index]);
}

function pl_showSongInfo(index) {
	showSongInfo(currentPlaylist.entries[index]);
}

function showSongInfo(song) {
	var html = new StringBuilder();
	html.append("<table style='width: 100%'>");
	html.append("<tr><td><u>Song</u>:</td><td>").append(song.title).append("</td></tr>");
	html.append("<tr><td><u>Hits</u>:</td><td>").append(song.hits).append("</td></tr>");
	html.append("<tr><td><u>Song&nbsp;URL</u>:&nbsp;</td><td><form><input type='text' onfocus='this.select()' readonly value='http://").append(window.location.hostname).append(window.location.pathname).append("?songId=").append(song.id).append("&songName=").append(encodeURIComponent(song.title)).append("'/></form></td></tr>");
	html.append("<tr><td><u>Embed</u>:</td><td><form><input type='text' onfocus='this.select()' readonly value='").append(getEmbedCode(song.id, song.title)).append("'/></form></td></tr>");
	html.append("</table>");
	pSongInfo.innerHTML = html;
}

function printFileSize(size) {
	if (size > 1024*1024)
		return Math.round(size/1024/1024*10)/10 + "M";
	else if (size > 1024)
		return Math.round(size/1024*10)/10 + "k";
	else
		return size;
}

function getEmbedCode(id, title) {
	var url = 'http://' + window.location.hostname + '/mplayer.swf?id=' + id + '&title=' + encodeURIComponent(title).replace("'", "%27") + '&autoplay=false';
	var html = '<object width="320" height="60">';
	html += '<param name="movie" value="' +url+ '"></param>';
	html += '<param name="allowFullScreen" value="true"></param>';
	html += '<param name="allowScriptAccess" value="always"></param>';
	html += '<embed src="' +url+ '" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" width="320" height="60"></embed>';
	html += '</object>';
	return html;
}


//song search --------------------------------------

var searchResult = null;
var pageSize = 20;

function doSearch() {
	var query = pSearchForm.query.value;
	if (!searchResult || query != searchResult.query) {
		searchResult = new Object();
		searchResult.pages = new Array();
		searchResult.query = query;
		searchResult.size = 0;
		searchResult.numPages = 0;
		searchResult.currentPage = 0;
		loadSearchResult(searchResult.currentPage, 1);
	}
	else if (typeof(searchResult.pages[searchResult.currentPage]) == 'undefined') {
		loadSearchResult(searchResult.currentPage, 1);
	}
	else if (searchResult.pages[searchResult.currentPage] == 'loading') {
	}
	else {
		updateSearchResult();
		return;
	}
	pSearchResult.innerHTML = "<span style='color: red'>Searching...</span>";
}

function loadSearchResult(pageNum, numPages) {
	for (var i=0; i<numPages; i++)
		searchResult.pages[pageNum+i] = 'loading';

	var query = searchResult.query;
	$.get("/dkmp3/search", {
			q: query,
			offset: pageNum*pageSize,
			limit: pageSize*numPages,
			t: new Date().getTime()
		},
		function(data){
			var result = eval('(' + data + ')');
			if (searchResult.query == query) {
				searchResult.size = result.size;
				searchResult.numPages = Math.ceil(result.size/pageSize);
				for (var i=0; i<numPages; i++)
					searchResult.pages[pageNum+i] = (i*pageSize < result.itemList.length) ? result.itemList.slice(i*pageSize, Math.min((i+1)*pageSize, result.itemList.length)) : [];
				if (searchResult.currentPage >= pageNum && searchResult.currentPage < pageNum+numPages)
					updateSearchResult();
			}
		});
}

function updateSearchResult() {
	var html = new StringBuilder();
	for (var i=0; i<searchResult.pages[searchResult.currentPage].length; i++) {
		var song = searchResult.pages[searchResult.currentPage][i];
		html.append("<li>");
		html.append(searchResult.currentPage*pageSize+i+1).append(".&nbsp;&nbsp;");
		if (typeof(song.deleted) == 'undefined') {
			html.append("<a href='javascript:sr_playSong(").append(i).append(")'>").append(song.title).append("</a>");
			html.append("&nbsp;<a href='javascript:sr_addSongToPlaylist(").append(i).append(")'><img src='images/add_icon.gif'/></a>");
			if (modPass != null) {
				html.append("<a href='javascript:sr_editSongName(").append(i).append(")'><img src='images/editIcon.gif'/></a>");
				html.append("<a href='javascript:sr_deleteSong(").append(i).append(")'><img src='images/deleteIcon2.gif'/></a>");
			}
		}
		else {
			html.append("<span style='text-decoration: line-through'>").append(song.title).append("</span>");
		}
		html.append("</li>");
	}
	pSearchResult.innerHTML = html;
	pSearchPageNumber.innerHTML = "Page " + (searchResult.currentPage+1) + " of " + searchResult.numPages;
	
	if (searchResult.currentPage+1 < searchResult.numPages && typeof(searchResult.pages[searchResult.currentPage+1]) == 'undefined')
		loadSearchResult(searchResult.currentPage+1, 3);
}

function setSearchPage(page) {
	if (page == searchResult.currentPage)
		alert("FATAL");
	searchResult.currentPage = page;
	doSearch();
}

function nextPage() {
	if (searchResult.currentPage+1 < searchResult.numPages)
		setSearchPage(searchResult.currentPage+1);
}

function lastPage() {
	if (searchResult.currentPage > 0)
		setSearchPage(searchResult.currentPage-1);
}

function sr_playSong(index) {
	sr_showSongInfo(index);
	playFile(searchResult.pages[searchResult.currentPage][index]);
}

function sr_addSongToPlaylist(index) {
	for (var i=0; i<currentPlaylist.entries.length; i++) {
		var song = currentPlaylist.entries[i];
		if (song != null && song.id == searchResult.pages[searchResult.currentPage][index].id) {
			alert("Song already exists in Playlist");
			return;
		}
	}
	currentPlaylist.entries.push(searchResult.pages[searchResult.currentPage][index]);
	currentPlaylist.isDirty = true;
	updatePlaylist();
	updatePlaylistInfo();
}

function sr_editSongName(index) {
	var song = searchResult.pages[searchResult.currentPage][index];
	var newName = prompt("Enter new name:", song.title);
	if (newName == null)
		return;
	$.post("/dkmp3/editSong", {
			songId: song.id,
			newName: newName,
			pass: modPass
		},
		function(data) {
			song.title = newName;
			updateSearchResult();
		});
}

function sr_deleteSong(index) {
	var song = searchResult.pages[searchResult.currentPage][index];
	$.post("/dkmp3/deleteSong", {
			songId: song.id,
			pass: modPass
		},
		function(data) {
			song.deleted = true;
			updateSearchResult();
		});
}

function setSearchString(s) {
	pSearchForm.query.value = s;
}

function searchNew() {
	setSearchString("[most recent]");
	doSearch();
}

function searchPopular() {
	setSearchString("[most popular]");
	doSearch();
}

function searchRecentlyPlayed() {
	setSearchString("[history]");
	doSearch();
}


//playlist ---------------------------------------------

function updatePlaylist() {
	var html = "";
	for (var i=0, j=0; i<currentPlaylist.entries.length; i++) {
		var song = currentPlaylist.entries[i];
		if (song != null) {
			if (i == currentIndex)
				html += '<li class="playing">';
			else if (j%2 == 1)
				html += '<li class="odd">';
			else
				html += '<li class="even">';
			html += '<a href="javascript:pl_removeSongFromPlaylist('+i+')"><img src="images/remove_icon.gif"/></a>';
			html += '<div><a href="javascript:pl_playSong('+i+')">' + song.title + '</a></div>';
			html += '</li>';
			j++;
		}
	}
	pPlaylist.innerHTML = html;
}

function pl_playSong(index) {
	pl_showSongInfo(index);
	if (index != currentIndex) {
		currentIndex = index;
		updatePlaylist();
	}
	if (currentPlaylist.entries[currentIndex].playCount)
		currentPlaylist.entries[currentIndex].playCount++;
	else
		currentPlaylist.entries[currentIndex].playCount = 1;
	playFile(currentPlaylist.entries[currentIndex]);
}

function pl_removeSongFromPlaylist(index) {
	if (currentIndex == index)
		currentIndex = -1;
	currentPlaylist.entries[index] = null;
	currentPlaylist.isDirty = true;
	updatePlaylist();
	updatePlaylistInfo();
}


//playlist information ---------------------------------

function updatePlaylistInfo() {
	var playlistId = "";
	var playlistUrl = "";
	var playlistName = "Playlist M&#x1EDB;i";
	if (currentPlaylist.id) {
		playlistId = currentPlaylist.id;
		playlistUrl = "http://" + window.location.hostname + "/?playlistId=" + currentPlaylist.id;
		playlistName = currentPlaylist.title;
		if (currentPlaylist.isDirty)
			playlistName += "*";
	}
	var html = "<div class='close-button' onclick='hideCurrentPlaylistInfo()'>x</div>";
	html += "<table>";
	html += "<tr><td>Playlist ID:</td><td>" + playlistId + "</td></tr>";
	html += "<tr><td>Playlist URL:&nbsp;&nbsp;</td><td><form><input type='text' onfocus='this.select()' value='" + playlistUrl + "'/></form></td></tr>";
	html += "</table>";
	pCurrentPlaylistInfo.innerHTML = html;
	pCurrentPlaylistName.innerHTML = playlistName;
}

function showCurrentPlaylistInfo() {
	pCurrentPlaylistInfo.style.visibility = "visible";
}

function hideCurrentPlaylistInfo() {
	pCurrentPlaylistInfo.style.visibility = "hidden";
}


//playlist menu ----------------------------------------

function loadPlaylist(playlistId) {
	loadPlaylistAutoplay(playlistId, false);
}

function loadPlaylistAutoplay(playlistId, autoplay) {
	$.get("/dkmp3/loadpl", {
			id: playlistId,
			t: new Date().getTime()
		},
		function(data) {
			currentPlaylist = eval('(' + data + ')');
			currentIndex = -1;
			updatePlaylist();
			updatePlaylistInfo();
			if (autoplay)
				playNextSong();
		});
	$("#playlist").html("<li style='color: red'>Loading...</li>");
}

function savePlaylist() {
	var songlist = "";
	for (var i=0; i<currentPlaylist.entries.length; i++) {
		if (currentPlaylist.entries[i] != null) {
			songlist += currentPlaylist.entries[i].id + ";";
		}
	}
	$.post("/dkmp3/savepl", {
			playlistName: currentPlaylist.title,
			songlist: songlist
		},
		function(data) {
			eval(data);
			currentPlaylist.id = playlistId;
			currentPlaylist.isDirty = false;
			updatePlaylistInfo();
		});
}

function newPlaylist() {
	currentPlaylist = new Object();
	currentPlaylist.entries = new Array();
	currentPlaylist.title = "New Playlist";
	updatePlaylist();
	updatePlaylistInfo();
}

function openPlaylist() {
	var playlistId = prompt("Enter Playlist ID:");
	if (playlistId)
		loadPlaylist(playlistId);
}

function closePlaylist() {
	if (currentPlaylist == null) {
		alert("No playlist");
		return;
	}
	if (currentPlaylist.entries.length == 0) {
		alert("Playlist is empty");
		return;
	}
	var playlistName = prompt("Save As:", currentPlaylist.title);
	if (playlistName) {
		currentPlaylist.title = playlistName;
		savePlaylist();
	}
}

function togglePlaylistMenu() {
	var el = pPlaylistMenu;
	if (el.style.display && el.style.display == 'inline')
		el.style.display = 'none';
	else
		el.style.display = 'inline';
}


//playlist search ------------------------------------

var playlistResult = null;

function albumQuery(query) {
	$.get("/dkmp3/albumsearch", {
			query: query,
			offset: 0,
			limit: 1000,
			orderBy: "lastPlayed",
			t: new Date().getTime()
		},
		function(data) {
			var result = eval('(' + data + ')');
			playlistResult = new Object();
			playlistResult.all = result.itemList;
			playlistResult.other = [];
			playlistResult.currentCategory = 'all';
			playlistResult.currentPage = 0;
			categorizePlaylistResult();
			updatePlaylistResult();
		});
	pPlaylistResult.innerHTML = "<span style='color: red'>Loading...</span>";
}

function categorizePlaylistResult() {
	for (var i=0; i<playlistResult.all.length; i++) {
		var firstChar = playlistResult.all[i].title.charAt(0).toUpperCase();
		if (firstChar.match(/^[A-Z]$/) != null) {
			if (typeof(playlistResult[firstChar]) == 'undefined')
				playlistResult[firstChar] = [];
			playlistResult[firstChar].push(playlistResult.all[i]);
		}
		else {
			playlistResult.other.push(playlistResult.all[i]);
		}
	}
}

function selectPlaylistCategory(cat) {
	playlistResult.currentCategory = cat;
	playlistResult.currentPage = 0;
	updatePlaylistResult();
}

function updatePlaylistResult() {
	var entries = [];
	if (typeof(playlistResult[playlistResult.currentCategory]) != 'undefined')
		entries = playlistResult[playlistResult.currentCategory];
	var numPages = Math.ceil(entries.length / pageSize);
	var html = new StringBuilder();
	var start = playlistResult.currentPage*pageSize;
	var end = Math.min(playlistResult.currentPage*pageSize+pageSize, entries.length);
	for (var i=start; i<end; i++) {
		var playlist = entries[i];
		html.append("<li>");
		html.append(i+1).append(".&nbsp;&nbsp;");
		if (typeof(playlist.deleted) == 'undefined') {
			html.append("<a href='javascript:ps_openPlaylist(").append(i).append(")'>").append(playlist.title).append("</a>");
			if (modPass != null)
				html.append("&nbsp;<a href='javascript:ps_deletePlaylist(").append(i).append(")'><img src='images/deleteIcon2.gif'/></a>");
		}
		else {
			html.append("<span style='text-decoration: line-through'>").append(playlist.title).append("</span>");
		}
		html.append("</li>");
	}
	pPlaylistResult.innerHTML = html;
	pPlaylistPageNumber.innerHTML = "Page " + (playlistResult.currentPage+1) + " of " + numPages;
}

function ps_openPlaylist(index) {
	loadPlaylist(playlistResult[playlistResult.currentCategory][index].id);
}

function ps_deletePlaylist(index) {
	var playlist = playlistResult[playlistResult.currentCategory][index];
	$.post("/dkmp3/deletePlaylist", {
			playlistId: playlist.id,
			pass: modPass
		},
		function(data) {
			playlist.deleted = true;
			updatePlaylistResult();
		});
}

function nextPlaylistPage() {
	var numPages = Math.ceil(playlistResult[playlistResult.currentCategory].length / pageSize);
	if (playlistResult.currentPage < numPages-1)
		playlistResult.currentPage++;
	else
		playlistResult.currentPage = 0;
	updatePlaylistResult();
}

function lastPlaylistPage() {
	var numPages = Math.ceil(playlistResult[playlistResult.currentCategory].length / pageSize);
	if (playlistResult.currentPage > 0)
		playlistResult.currentPage--;
	else
		playlistResult.currentPage = numPages-1;
	updatePlaylistResult();
}


//recent searches --------------------------------

var recentSearches = null;

function toggleRecentSearches() {
	var el = pRecentSearchesPanel;
	if (el.style.display && el.style.display == 'inline')
		el.style.display = 'none';
	else {
		el.style.display = 'inline';
		loadRecentSearches();
	}
}

function loadRecentSearches() {
	$.get("/dkmp3/recentsearches", {
			t: new Date().getTime()
		},
		function(data) {
			recentSearches = eval('(' + data + ')');
			updateRecentSearches();
		});
	pRecentSearches.innerHTML = "<span style='color:red'>Searching...</span>";
}

function updateRecentSearches() {
	var html = "<ul>";
	html += "<li><a href='javascript:searchNew()'>C&#x00E1;c b&#x00E0;i m&#x1EDB;i up</a></li>";
	for (var i=0; i<Math.min(recentSearches.length, 20); i++) {
		html += "<li><a href='javascript:runRecentSearch("+i+")'>" + recentSearches[i] + "</a></li>";
	}
	html += "</ul>";
	pRecentSearches.innerHTML = html;
}

function runRecentSearch(index) {
	setSearchString(recentSearches[index]);
	doSearch();
}


//search tabs ------------------------------------------

var searchTabs = [
	{title:"MP3"},
	{title:"Playlist"}
];
var activeSearchTabIndex = 0;

function selectSearchTab(index) {
	if (index != activeSearchTabIndex) {
		pSearchBox.removeChild(searchTabs[activeSearchTabIndex].content);
		pSearchBox.appendChild(searchTabs[index].content);
		activeSearchTabIndex = index;
		updateSearchTabs();
	}
}

function updateSearchTabs() {
	var html = new StringBuilder();
	for (var i=0; i<searchTabs.length; i++) {
		if (i == activeSearchTabIndex)
			html.append("<span class='active'");
		else
			html.append("<span class='inactive'");
		html.append(" onclick='selectSearchTab(").append(i).append(")'>").append(searchTabs[i].title);
		html.append("</span>");
	}
	pSearchTabs.innerHTML = html.toString();
}


//upload -----------------------------------------------

var pUploadQueue;

function updateUploadQueue() {
	var html = new StringBuilder();
	html.append("<table>");
	html.append("<tr><th>File</th><th>Status</th></tr>");
	for (var i=0; uploader.getFile(i) != null; i++) {
		var file = uploader.getFile(i);
		html.append("<tr>");
		html.append("<td>").append(file.name).append("</td>");
		html.append("<td><span id='uploadStatus").append(i).append("'>").append(getStatusMsg(file)).append("</span></td>");
		html.append("</tr>");
	}
	html.append("</table>");
	pUploadQueue.innerHTML = html;
}

function updateUploadStatus(index, statusMsg) {
	document.getElementById("uploadStatus" + index).innerHTML = statusMsg;
}

function getStatusMsg(file) {
	switch (file.filestatus) {
		case SWFUpload.FILE_STATUS.QUEUED : return "Pending";
		case SWFUpload.FILE_STATUS.IN_PROGRESS : return "Downloading";
		case SWFUpload.FILE_STATUS.ERROR : return "Error";
		case SWFUpload.FILE_STATUS.COMPLETE : return "Complete";
		case SWFUpload.FILE_STATUS.CANCELLED : return "Cancelled";
		case -6 : return "Skipped";
	}
	return "???";
}


var uploader;
var uploadQueueSize = 0;

function initUploader(uploadQueue) {
	pUploadQueue = uploadQueue;

	uploader = new SWFUpload({
		upload_url : "/dkmp3/upload",
		flash_url : "flash/swfupload.swf",
		
		file_post_name : "Filedata",
		post_params : {},
		use_query_string : false,
		requeue_on_error : true,
		http_success : [201, 202],
		assume_success_timeout : 0,
		file_types : "*.mp3",
		file_types_description: "MP3 Files",
		file_size_limit : "20 MB",
		file_upload_limit : 0, 
		file_queue_limit : 0,
	
		debug : false,
		prevent_swf_caching : false,
		preserve_relative_urls : false,
	
		button_placeholder_id : "upload-button-div",
		button_image_url : "images/upload_button.jpeg",
		button_width : 84,
		button_height : 84,
		button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
		button_disabled : false, 
		button_cursor : SWFUpload.CURSOR.HAND,
		button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
	
		swfupload_loaded_handler : swfupload_loaded_function,
		file_dialog_start_handler : file_dialog_start_function,
		file_queued_handler : file_queued_function,
		file_queue_error_handler : file_queue_error_function,
		file_dialog_complete_handler : file_dialog_complete_function,
		upload_start_handler : upload_start_function,
		upload_progress_handler : upload_progress_function,
		upload_error_handler : upload_error_function,
		upload_success_handler : upload_success_function,
		upload_complete_handler : upload_complete_function,
		debug_handler : debug_function
	});
}

function swfupload_loaded_function() {
}

function file_dialog_start_function() {
}

function file_queued_function(file) {
}

function file_queue_error_function(file, errorCode, errorMessage) {
	alert(errorCode + ": " + errorMessage + " (" + file.name + ")");
}

function file_dialog_complete_function(numSelected, numQueued, queueSize) {
	uploadQueueSize = queueSize;
	updateUploadQueue();
	uploader.startUpload();
}

function upload_start_function(file) {
	updateUploadStatus(file.index, "Starting");
}

function upload_progress_function(file, bytesCompleted, bytesTotal) {
	updateUploadStatus(file.index, Math.round(bytesCompleted*100/bytesTotal) + "%");
}

function upload_error_function(file, errorCode, errorMessage) {
	updateUploadStatus(file.index, errorCode + " " + errorMessage);
}

function upload_success_function(file, serverData, receivedResponse) {
	updateUploadStatus(file.index, "Success");
}

function upload_complete_function(file) {
	updateUploadStatus(file.index, "Complete");
	this.startUpload();
}

function debug_function(message) {
}
