function showFileSize (size) {
	if (size < 1024) return size + ' b';
	if (size < 1024*1024) return (Math.round(size * 10 / 1024) / 10) + ' Kb';
	return (Math.round(size * 10 / (1024 * 1024)) / 10) + ' Mb';
}

var Conversion = Class.create();
Conversion.prototype = {
	initialize: function (container, jsonObj, isOnLogin) {
		if (arguments.length == 2) var isOnLogin = false;
		this.container = container;
		this.jsonObj = jsonObj;

		if (isOnLogin) {
			//this.element_status.innerHTML = 'Checking... ';
			this.file_size = jsonObj.file_size;
		}else
			this.startDownload();

		this.trayItem = Tray.addToTray();
		this.trayItem.setObjectDownload(this.jsonObj, this);
		this.trayItem.showAjaxLoading();
		Element.addClassName (this.trayItem.img, 'working');
		if (!isOnLogin) {
			this.trayItem.showAlert('Your video is being prepared');
			this.trayItem.div_status.innerHTML = 'Starting to download on server';
		} else
			this.trayItem.div_status.innerHTML = 'Checking status';
	},

	startDownload: function () {
		var params = $H({id:this.jsonObj.id});
		var json = this.jsonObj;
		// if we don't remove the comments the object will not properly be serialized to JSON
		// if we don't remove the comment_count the player will think that there are
		// comments but will not be able to load them
		json.comments = null;
		json.comment_count = null;
		new Ajax.Request ('initiate_download.php', {
			method: 'post',
			parameters: params.toQueryString() +
				'&jsonObj=' + encodeURIComponent(ObjectToJsonString(json)),
			onSuccess: this.startDownload_handler.bind(this)
		})
		urchinTracker('download/initiate/' + this.jsonObj.id);
	},
	startDownload_handler: function (ajaxResponse) {
		var jsontext = ajaxResponse.responseText;
		var jsonObj = null;
		eval ('jsonObj = ' + jsontext);
		if (jsonObj != null) {
			if (jsonObj.error) {
				if (jsonObj.errorID == 1)
					show_download_limit_reached(this.container.downl_totals);
				else
					alert (jsonObj.error);
				this.finished = true;
				this.trayItem.div_status.innerHTML = 'Error: ' + jsonObj.error;
				this.trayItem.hideAjaxLoading();
				//this.showFinisedDownload();
				//this.trayItem.remove();
			} else {
				if (jsonObj.downloadsSoFar && jsonObj.downloadsAllowed) {
					this.container.downloadsAllowed = jsonObj.downloadsAllowed;
					this.container.downloadsSoFar = jsonObj.downloadsSoFar;
				}

				this.file_size = parseInt(jsonObj.size);	//store the size of the file that's being downloaded
				this.finished = false;
				this.converted = 0;
				this.updateProgress(0, '');
				this.container.startCheckingDownloads();
			}
		}
	},

	queueConversion: function (format) {
		this.queuedConvertingToFormat = format;
		if (!this.queued) {
			this.trayItem.div_status.innerHTML = 'Queued for conversion to ' + format;
			this.container.addConversionToQueue(this);
		}
		this.queued = true;
	},
	startConvertingFromQueue: function () { // called by the container
		this.startConverting(this.queuedConvertingToFormat, true);
	},

	startConverting: function (format, force) {
		if (arguments.length == 1) var force = false;
		if (Element.hasClassName (this.trayItem.img, 'ready'))
			Element.removeClassName (this.trayItem.img, 'ready');
		if (this.container.getRunningConversionsCount() > 0 && !force) {
			this.queueConversion (format);
			return; // it is queued so function will be called later
		}
		this.queued = false;
		Element.addClassName (this.trayItem.img, 'working');
		this.trayItem.div_status.innerHTML = 'Starting conversion to ' + format.toUpperCase() + '. Please wait';
		this.trayItem.showAjaxLoading();
		this.convertingToFormat = format;
		this.converting = true;
		this.trayItem.div_progress_bar.style.display = "block";
		this.trayItem.div_progress_bar.style.width = "0%";
		this.trayItem.div_hint.style.display = "none";
		var params = $H ({id:this.jsonObj.id, format: format, title: this.jsonObj.title});
		if (this.convertionTries)
			this.convertionTries ++;
		else
			this.convertionTries = 0;
		new Ajax.Request ('start_converting.php', {
			method: 'post',
			parameters: params.toQueryString(),
			onSuccess: this.startConverting_handler.bind(this),
			onFailure: this.startConverting_error.bind(this)
		});
		this.waitingToStartConverting = true;
		this.container.startCheckingConversions();
		urchinTracker('download/convert/' + format.toUpperCase() + '/' + this.jsonObj.id);
	},
	startConverting_handler: function (ajaxResponse) {
		var jsonText = ajaxResponse.responseText;
		var jsonObj = null;
		this.waitingToStartConverting = false;
		eval ('jsonObj = ' + jsonText);
		if (jsonObj != null) {
			if (jsonObj.errorid == 0) {
				//console.info('got start id ' + jsonObj.fileid);
				this.conversionFileID = jsonObj.fileid;
				this.container.startCheckingConversions();
			} else
				alert (jsonObj.error)
		}
	},
	startConverting_error: function () {
		this.waitingToStartConverting = false;
		if (this.convertionTries > 3) {
			alert ('The video cannot be converted at the moment, please try again later');
			this.convertionTries ++;
		} else
			this.startConverting(this.convertingToFormat)
	},
	recieveConversionProgresUpdate: function (jsonObj) {
		if (jsonObj.status == 'over') {
			this.converting = false;
			this.conversionFileID = null;
			/*this.element_operations.style.display = "block";
			this.element_operations.style.position = "static";*/
			this.finished = true;
			//this.element_progress_bar.style.width = '100%';
			this.trayItem.div_title.innerHTML = this.jsonObj.title;
			this.trayItem.div_status.innerHTML = "Finished converting to " + this.convertingToFormat.toUpperCase();
			this.trayItem.div_progress_bar.style.display = "none";
			//this.popupOpen('get_converted_file.php?id=' + this.jsonObj.id + '&format=' + this.convertingToFormat + '&title=' + encodeURI(this.jsonObj.title))
			Converter.showDownloadLinkDialog ('/get_converted_file.php?id=' + this.jsonObj.id + '&format=' + this.convertingToFormat + '&title=' + encodeURI(this.jsonObj.title))
			Element.removeClassName (this.trayItem.img, 'working');
			Element.addClassName (this.trayItem.img, 'ready');
			this.trayItem.hideAjaxLoading();
			this.container.removeFromQueue(this);
		} else
		if (jsonObj.status == 'starting') {
			var text = 'Starting conversion to ' + this.convertingToFormat.toUpperCase() + ". Please wait";
			this.updateProgress(0, text);
		} else {
			var prc = 100 * jsonObj.time / jsonObj.totalTime;
			var text = 'Converting to ' + this.convertingToFormat.toUpperCase();
			this.updateProgress(prc, text);
			//this.trayItem.div_status.innerHTML = 'Time left: ' + this.timeLeft;
		}
	},

	recieveDownloadProgressUpdate: function (size) {
		this.converted = size;
		if (this.converted >= this.file_size)
			this.showFinisedDownload();
		else {
			var prc = Math.round((100*this.converted/this.file_size))
			var text = 'Downloading to server: ' + showFileSize(this.converted) + ' of ' + showFileSize(this.file_size) + ' (' + prc + '%)';
			this.updateProgress(prc, text);
		}
	},

	updateProgress: function (prc, text) {
		/*this.element_status.innerHTML = text;
		this.element_progress_bar.style.width = prc + '%';*/
		this.finished = false;

		this.trayItem.div_title.innerHTML = this.jsonObj.title;
		this.trayItem.div_status.innerHTML = text; // this.element_status.innerHTML;
		this.trayItem.div_progress_bar.style.width = prc + '%';
	},

	showFinisedDownload: function () {
		Element.removeClassName (this.trayItem.img, 'working');
		Element.addClassName (this.trayItem.img, 'ready');
		this.trayItem.hideAjaxLoading();
		/*this.element_status.style.display = "none"; //innerHTML = 'Ready';
		this.element_operations.style.display = "block";
		this.element_operations.style.position = "static";
		this.element_progress_bar.style.width = '100%';*/
		this.finished = true;
		this.trayItem.div_title.innerHTML = this.jsonObj.title;
		this.trayItem.div_status.innerHTML = "Downloading ready";
		this.trayItem.div_progress_bar.style.display = "none";
		this.trayItem.div_hint.style.display = "block";
		this.trayItem.showAlert('Your video is ready to download. Right click to select format');
	},

	click_play: function (event) {
		bc.openNewVideo(this.jsonObj);
	},

	popupOpen: function (url) {
		/*if (isIE)
			window.open(url);
		else*/
			document.location = url;
	},

	/*click_downloadAsFLV: function (event) {
		if (!user_name)
			showLoginOrRegisterForm();
		else {
			urchinTracker('download/convert/FLV/' + this.jsonObj.id);
			this.popupOpen ('download_flv.php?id=' + this.jsonObj.id + '&title=' + encodeURI(this.jsonObj.title), event);
		}
	},*/
	click_downloadAsEXE: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else {
			urchinTracker('download/convert/EXE/' + this.jsonObj.id);
			this.popupOpen('download_exe.php?id=' + this.jsonObj.id + '&title=' + encodeURI(this.jsonObj.title), event);
		}
	},
	click_downloadAsZIP: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else {
			urchinTracker('download/convert/ZIP/' + this.jsonObj.id);
			this.popupOpen ('download_zip.php?id=' + this.jsonObj.id + '&title=' + encodeURI(this.jsonObj.title), event);
		}
	},
	click_downloadAsAVI: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else
			this.startConverting('avi');
	},
	click_downloadAsMOV: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else this.startConverting('mov');
	},
	
	click_downloadAsMP4: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else
			this.startConverting('mp4');
	},
	/*click_downloadAs3GP: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else
			this.startConverting('3gp');
	},*/
	click_downloadAs3G2: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else
			this.startConverting('3g2');
	},
	click_downloadAsWMV: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else
			this.startConverting('wmv');
	},

	click_downloadAsMP3: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else if (UserLimits.isUserAllowedTo(UserLimits.ua_download_advanced, true, 'MP3'))
			this.startConverting('mp3');

	},

	click_downloadAsWMA: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else if (UserLimits.isUserAllowedTo(UserLimits.ua_download_advanced, true, 'WMA'))
			this.startConverting('wma');
	},

	click_downloadAsAAC: function (event) {
		if (!this.finished) this.alertNotOver();
		else if (!user_name)
			showLoginOrRegisterForm();
		else if (UserLimits.isUserAllowedTo(UserLimits.ua_download_advanced, true, 'AAC'))
			this.startConverting('aac');
	},

	alertNotOver: function () {
		alert ("The video is not ready for converting yet.\nThis may take a few minutes, depending on it's size.");
	},

	click_remove: function (event) {
		//this.container.element.removeChild(this.element);
		this.trayItem.remove();
		this.container.removeConversion(this);
		var params = $H({id:this.jsonObj.id});
		new Ajax.Request ('remove_download.php', {
			method: 'get',
			parameters: params.toQueryString()
		});
		urchinTracker('download/remove/' + this.jsonObj.id);
	},

	remove: function () { //called when login/logout
		//this.container.element.removeChild(this.element);
		this.trayItem.remove();
		this.container.removeConversion(this);
	}
}

Converter = {
	initialize: function () {
		this.conversions = new Array();

		this.downloadsTimer = -1;
		this.conversionsTimer = -1;
		this.conversionQueue = new Array();
		//this.updateDownloads();

		setTimeout("$('download_link_ad_frame').src = '/ga-frame.html?r=' + Math.round(1000000 * Math.random(0,1));", 4000);
	},

	showDownloadVideoDialog: function (jsonObj) {
		if (!user_name) {
			showLoginOrRegisterForm();
			return false;
		}
		if (!UserLimits.isUserAllowedTo(UserLimits.ua_download, true)) {
			return false;
		}
		//$('download_get_video_versions').style.display = 'block';
		//$('download_dialog_versions').innerHTML = 'Loading available video formats...';
		$('download_dialog_versions').innerHTML = '';
		$('download_dialog_video_title').innerHTML = jsonObj.title;
		showBackground();
		$('download_formats_dialog').style.display = 'block';
		this._current_jsonObj = jsonObj;
		/*new Ajax.Request('/get_video_versions.php?id=' + jsonObj.id, {
			method:'get', onSuccess: this.onGetVideoVersions_handler.bind(this)
		})*/;
	},
	hideDownloadVideoDialog: function () {
		hideBackground();
		$('download_formats_dialog').style.display = 'none';
		$('download_dialog_versions').innerHTML = '';
		$('download_get_video_versions').style.display = 'none';
	},
	onGetVideoVersions_handler: function (ajaxRequest) {
		var t = ajaxRequest.responseText;
		var jsonObj = null;
		eval ('jsonObj = ' + t);
		var html = '';
		if (!jsonObj.errorid) {
			var formats = [22,18,35,6,34,5,17,13];
			var formats_descriptions = {22 : 'Hight Definition 720p MP4 (1280x720, 44 kHz stereo)',
			                            18 : 'High Quality MP4 (480x360, 44 kHz stereo)',
			                            35 : 'High Quality FLV (640x380, 44 kHz stereo)',
			                            6 : 'Mid Quality FLV (480x360, 44 kHz mono)',
			                            34 : 'Low Quality FLV (320x240, 22.1 kHz stereo)',
			                            5 : 'Low Quality FLV (320x240, 22.1 kHz mono)',
			                            17 : '3GP for Mobile devices (176x144, 22.1 kHz mono)',
			                            13 : '3GP for Mobile devices (176x144, 8 kHz mono)'};
			for (var i = 0; i < formats.length; i ++) {
				if ($A(jsonObj.formats).indexOf(formats[i]) > -1) {
					html += '<span class="blue_link bulleted_link" onclick="Converter.onClickDownloadDirect(' + formats[i] + ')">' + formats_descriptions[formats[i]] + '</span><br />';
				}
			}

			$('download_dialog_versions').innerHTML = html;
			$('download_get_video_versions').style.display = 'none';
		}
	},
	onClickDownloadDirect: function (fmt) {
		if (fmt == 22) {
			if (!UserLimits.isUserAllowedTo(UserLimits.ua_download_advanced, true, 'HD')) {
				return;
			}
		}
		if (!UserLimits.isUserAllowedTo(UserLimits.ua_download, true)) {
			return;
		}
		if (!fmt) return;
		new Ajax.Request ('/get_video_versions.php?id=' + this._current_jsonObj.id + '&df=' + fmt, {
			onSuccess: this.onClickDownloadDirect_handler.bind(this)
		});
		urchinTracker('download/direct/' + fmt + '/' + this._current_jsonObj.id);
		$('download_formats_dialog').style.display = 'none';
		$('download_link_dialog').style.display = 'block';
		$('download_link_dialog_content').innerHTML = 'Loading, please wait...';
		$('download_link_dialog_loading').style.display = 'block';
	},
	onClickDownloadDirect_handler: function (ajaxRequest) {
		var t = ajaxRequest.responseText;
		var jsonObj;
		eval ('jsonObj = ' + t);

		if (jsonObj.url) {
			UserLimits.takeDownloadCredit();
			$('download_link_dialog_loading').style.display = 'none';
			$('download_link_dialog_content').innerHTML = 'Your download should begin momentarily.<br />' +
			'If it does not, you can use this link instead:<br />' +
			'<a class="blue_link bulleted" href="' + jsonObj.url + '" title="" id="download_link_direct" target="_blank">download your video</a>';
			document.location = jsonObj.url;
		} else if (jsonObj.error) {
			alert (jsonObj.error);
		}
	},
	showDownloadLinkDialog: function (link) {
		showBackground();
		$('download_link_dialog').style.display = 'block';
		$('download_link_dialog_content').innerHTML = 'Your download should begin momentarily<br />' +
			'If it does not, you can use this link instead:<br />' +
			'<a class="blue_link bulleted" href="' + link + '" title="" target="_blank">download</a>';

		document.location = link;
	},
	hideDownloadLinkDialog: function () {
		hideBackground();
		$('download_link_dialog').style.display = 'none';
	},

	onClickDownloadOther: function () {
		this.hideDownloadVideoDialog();
		this.addConversion(this._current_jsonObj);
	},
	// simple alias to showDownloadVideoDialog
	downloadVideo: function (jsonObj) {
		this.showDownloadVideoDialog(jsnObj);
	},

	addConversion: function (jsonObj, isOnLogin) {
		if (!isOnLogin) {
			if (this.getConversionById(jsonObj.id) != null) {
				alert ('This file is already being downloaded!');
				return;
			}
			if (!user_name) {
				showLoginOrRegisterForm();
				return false;
			}
			if (!UserLimits.isUserAllowedTo(UserLimits.ua_download, true)) {
				return false;
			} else
				UserLimits.takeDownloadCredit();
		}

		if (arguments.length == 1) var isOnLogin = false;
		var new_conversion = new Conversion(this, jsonObj, isOnLogin);
		this.conversions.push(new_conversion);
		this.startCheckingDownloads();
		return new_conversion;
	},

	getConversionById: function (id) {
		for (var i = 0; i < this.conversions.length; i ++)
			if (this.conversions[i].jsonObj.id == id)
				return this.conversions[i];
		return null;
	},

	startCheckingDownloads: function () {
		if (this.downloadsTimer < 0)
			this.downloadsTimer = setInterval(this.updateDownloads.bind(this), 4000);
	},
	startCheckingConversions: function () {
		//console.info('set cc timer');
		if (this.conversionsTimer < 0)
			this.conversionsTimer = setInterval(this.updateConversions.bind(this), 2000);
	},

	updateConversions: function () {
		//console.info('check conversions');
		var fileIDs = new Array();
		var waitingConversionStartFilesCount = 0;
		for (var i = 0; i < this.conversions.length; i ++) {
			if (this.conversions[i].conversionFileID && this.conversions[i].conversionFileID != null)
				fileIDs.push(this.conversions[i].conversionFileID);
			else if (this.conversions[i].waitingToStartConverting)
				waitingConversionStartFilesCount ++;
		}
		if (fileIDs.length == 0) {
			if (waitingConversionStartFilesCount == 0) this.stopCheckingConversions();
			return;
		}
		var params = $H({fileids: fileIDs});
		new Ajax.Request ('check_conversion_progress.php',{
			onSuccess:this.updateConversions_handler.bind(this),
			method: 'post',
			parameters: params.toQueryString()
		});
	},

	updateConversions_handler: function (ajaxResponse) {
		var t = ajaxResponse.responseText;
		var jsonArr = null;
		eval ('jsonArr = ' + t);
		var running = 0;
		if (jsonArr != null) {
			for (var i = 0; i < jsonArr.length; i ++) {
				if (jsonArr[i].status != 'over') running ++ ;
				for (var j = 0; j < this.conversions.length; j ++)
					if (this.conversions[j].converting && this.conversions[j].conversionFileID == jsonArr[i].fileid)
						this.conversions[j].recieveConversionProgresUpdate(jsonArr[i]);
			}
		}
		if (running == 0 && this.conversionQueue.length == 0) {
			this.stopCheckingConversions();
		}
	},
	stopCheckingConversions: function () {
		clearInterval (this.conversionsTimer);
		this.conversionsTimer = -1;
	},

	updateDownloads: function () {
		//send request for updating the progress bars
		var param_ids = new Array ();
		for (var i = 0; i < this.conversions.length; i ++)
			if (!this.conversions[i].finished)
				param_ids.push(this.conversions[i].jsonObj.id);
		//if (param_ids.length == 0) return;
		var params = $H({files:param_ids});
		new Ajax.Request ('check_progress.php', {
			method: 'post',
			parameters: params.toQueryString(),
			onSuccess: this.updateDownloads_handler.bind(this)
		})
	},

	updateDownloads_handler: function (response) {
		var jsontext = response.responseText;
		var jsonObj = null;
		var running = 0;
		eval ('jsonObj = ' + jsontext);
		if (jsonObj != null) {
			/* if (jsonObj.downloadsSoFar && jsonObj.downloadsAllowed) {
				this.downloadsAllowed = jsonObj.downloadsAllowed;
				this.downloadsSoFar = jsonObj.downloadsSoFar;
			}*/

			var cnv = null;
			for (var i = 0; i < jsonObj.results.length; i ++) {
				cnv = this.getConversionById(jsonObj.results[i].id);
				if (cnv != null) {
					cnv.recieveDownloadProgressUpdate(jsonObj.results[i].size);
					if (cnv.file_size > jsonObj.results[i].size)
						running ++;
				}
			}
		}
		if (running == 0) {
			clearInterval (this.downloadsTimer);
			this.downloadsTimer = -1;
		}
	},
	// the conversion calls this to be removed from list
	removeConversion: function(conversion) {
		this.conversions = this.conversions.without(conversion);
		if (this.conversionQueue.indexOf(conversion) >= 0) { // remove from queue
			if (!conversion.queued)
				this.removeFromQueue(conversion);
			else
				this.conversionQueue = this.conversionQueue.without(conversion);
		}
		delete(conversion);
	},

	removeAllConvertions: function () { // called when login/logout
		for (var i = this.conversions.length - 1; i >= 0; i --)
			this.conversions[i].remove();
	},
	// the conversion queue
	getRunningConversionsCount: function () {
		var count = 0;
		for (var i = 0; i < this.conversions.length; i ++)
			if (this.conversions[i].converting)
				count ++;
		return count;
	},
	removeFromQueue: function (finishedCnv) {
		this.conversionQueue = this.conversionQueue.without(finishedCnv);
		// check if there is conversion waiting
		if (this.conversionQueue.length > 0)
			this.conversionQueue[0].startConvertingFromQueue();
	},
	addConversionToQueue: function (cnvObj) {
		this.conversionQueue.push(cnvObj);
	},
	/* /// next two - called by different objects to initiate download
	downloadFLV: function (jsonObj) {
		//window.open ('download_flv.php?id=' + jsonObj.id + '&title=' + encodeURI(jsonObj.title));
		new Ajax.Request('download_flv.php?precheck=true&id=' + jsonObj.id + '&title=' + encodeURI(jsonObj.title), {
			method:'get',
			onSuccess:this.downloadFLV_handler.bind(this)});
	},

	downloadFLV_handler: function (jsonResponse) {
		var jsonObj = null;
		eval ('jsonObj = ' + jsonResponse.responseText);
		if (jsonObj) {
			if (jsonObj.error) {
				alert (jsonObj.error);
			} else
			window.open ('download_flv.php?id=' + jsonObj.id + '&title=' + encodeURI(jsonObj.title));
		} else { alert ('error!')}
	},
	*/
	/*downloadFLV: function (jsonObj) {
		if (!UserLimits.isUserAllowedTo(UserLimits.ua_download, true)) {
			return false;
		} else {
			//ok, here is the problem - we should take credit ONLY if not taken for this video already
			//this may happen if the user first clicked "download" and then "Save as FLV" - the credit is taken on step one
			//but if he clicks straight on "Download as FLV" in the player - we have to take it here
			//so we check if there is a download with same video id
			if (!this.getConversionById(jsonObj.id))
				UserLimits.takeDownloadCredit();
		}
		window.open ('download_flv.php?id=' + jsonObj.id + '&title=' + encodeURI(jsonObj.title));
	},*/
	downloadConverted: function (jsonObj) {
		this.showDownloadVideoDialog(jsonObj);
	},
	userHasLoggedIn: function () {
		this.removeAllConvertions();
		new Ajax.Request ('get_user_downloads.php', {method: "post", onSuccess: this.getDownloads_handler.bindAsEventListener(this)})
	},

	getDownloads_handler: function (ajaxResponse) {
		var t = ajaxResponse.responseText;
		var jsonObj = null;
		eval ("jsonObj = " + t);
		if (jsonObj != null) {
			if (jsonObj.errorid == 0) {
				for (i = 0; i < jsonObj.downloads.length; i++) {
					jsonObj.downloads[i].file_size = jsonObj.sizes[i];
					this.addConversion(jsonObj.downloads[i], true);
				}
			} else {
				alert (jsonObj.error);
			}
		}
	},

	addOldUnRegDownload: function (ajaxResponse) {
		var t = ajaxResponse.responseText;
		var jsonObj = null;
		eval ('jsonObj = ' + t);
		if (jsonObj != null) { 	}
	},
	userHasLoggedOut: function () {
		this.removeAllConvertions();
	},
	onThemeChange: function () {
		$('download_link_ad_frame').src = '/ga-frame.html?r=' + Math.round(1000000 * Math.random(0,1));
	}
}