var Upload = Class.create(
{
	initialize: function()
	{
		if(top.location.host == 'x7')
			uploadServer = 'http://x7/';
		
		$('butUpload').insert('<img src="img/elem/ul_err_en.jpg" onclick="window.open(\'http://get.adobe.com/flashplayer\')" style="cursor:pointer;margin:20px 0 0 24px" />');
		
		YAHOO.widget.Uploader.SWFURL = uploadServer+'misc/uploader.swf';

		this.uploader = new YAHOO.widget.Uploader('butUpload');
		this.uploader.addListener('contentReady', function(){ this.uploader.setAllowMultipleFiles(true); }.bind(this));
		this.uploader.addListener('fileSelect', this.onFileSelect.bind(this));
		this.uploader.addListener('uploadProgress', this.onUploadProgress.bind(this));
		this.uploader.addListener('uploadCompleteData', this.onUploadComplete.bind(this));
		this.uploader.addListener('uploadError', this.onUploadError.bind(this));
		
		this._IDs 		= {};
		this._waiting	= [];
		this._uploading = 0;
		this._complete 	= 0;
	},
	
	onFileSelect: function(entries)
	{
		var e;

		if(!uploadServer)
			return alert('Wegen hoher Auslastung sind unsere Upload-Kapazitäten aktuell vollständig in Verwendung.\nBitte versuchen Sie es in einigen Minuten erneut.');
		
		for(var i=0; i<Object.keys(entries.fileList).length; i++)
		{
			e = entries.fileList['file'+i];
			e.admincode = cookieAdminCode ? cookieAdminCode : generate(7);
			
			if(e.size < 1)
				continue;
			
			if(this._IDs[e.id])
				continue;
			else
				this._IDs[e.id] = e;
			
			this.checkDuplicity(e);
		}
	},
	
	initUpload: function(file, fake)
	{
		var c = $('content');
		
		if(!c.down('ul.listUpload'))
		{
			this.actContent = (c.select('*').slice(1, c.select('*').length-4).invoke('hide'));
			
			c.down('#butUpload').insert({before:
				'<div style="line-height:15px;text-shadow:#6966bc 1px 1px 1px;text-align:center;color:#3b377c;padding-top:8px;"><br style="clear:both" />Hier können Sie Ihre Daten hochladen.<br />'+
				'<small>Um eine weitere Datei zu übertragen, klicken Sie erneut auf &quot;<b style="cursor:help" onmouseover="$(\'butUpload\').pulsate({duration:1,pulses:3})">upload</b>&quot;.</small></div>' +
				'<div id="restoreC" style="cursor:pointer;position:absolute;top:0;left:20px;font-size:10px;color:#a4a0e2">' +
				'	<img src="img/sym/lifebuoy.png" style="vertical-align:top;padding-right:5px" />Restore content' +
				'</div>'+
				(UserScreen.width>1200?'<img src="img/elem/cursor.png" style="z-index:10;display:none;position:absolute;top:10px;right:-15px" /><img src="img/elem/helpAdminCode_en.png" id="help2" title="close" onclick="$(this).fade({duration:.5})" style="cursor:help;display:none;position:absolute;right:-100px;top:-10px" />':'') +
				'<ul class="listUpload"></ul>'});
			
			$('restoreC').observe('click', function() {
				$('restoreC').fade({duration:.3});
				this.actContent.invoke('appear', {duration:.5});
			}.bind(this));
		}
		
		c = c.down('ul.listUpload');
		c.insert({bottom:
			'<li id="'+file.id+'" class="AC_'+file.admincode+'">'+
			'	<h2 style="text-shadow:#6467a1 1px 1px 1px">'+file.name+'</h2>'+
			'	<h1><span style="text-shadow:#bebde2 1px 1px 1px">~</span><br /><small><span>'+(this._uploading>1?'in Warteschlange':'initialisiere upload')+'&hellip;</span><img src="img/sym/cross-small.png" title="Cancel upload" onclick="cUpload.cancelUpload(\''+file.id+'\')" class="cancel" /></small></h1>'+
			'	<div class="progress" style="width:0"><img src="img/elem/ulr.png" style="display:none;float:right" /></div>'+
			'	<img src="img/elem/mask.png" class="mask" />'+
			'	<span class="lsym"><small class="kbs" id="null'+(new Date().getTime())+'"></small> <img src="img/load/arr.gif" class="status" /></span>'+
			'	<span class="rsym"><small class="rem"></small> <img src="img/load/arr.gif" class="status" /></span>'+
			'</li>'});
		
		setTimeout(function(){ if(c.down('.progress img')) c.down('.progress img').appear({duration:3}); }.bind(this), 1000);
		
		if(!fake)
			this.startUpload(file);
	},
	
	startUpload: function(file)
	{
		if(this._uploading > 1)
			return this._waiting.push(file);
		
		// freeze starttime
		$(file.id).down('small.kbs').id = new Date().getTime();
		
		this._uploading++;
		this.setTransferStatus();
		
		// thats "THE LINE"!
		this.uploader.upload(file.id, uploadServer+'upload?admincode='+file.admincode+($('id')&&$('pw')?'&id='+$('id').value+'&pw='+$('pw').value:''), 'POST');
	},
	
	checkDuplicity: function(file)
	{
		if(file.size < (10485760))
			return this.initUpload(file);
		
		switch(file.name.substr(file.name.lastIndexOf('.')+1))
		{
			case 'rar':
			case 'txt':
				return this.initUpload(file);
			break;
		}
		
		new Ajax.Request('james/upload/duplicity', {parameters:Object.toQueryString(file),onComplete:function(t){
			if(!t.responseText)
				return this.initUpload(file);
			else
			{
				this.initUpload(file, true);
				setTimeout(function(){ this.onUploadComplete({data:t.responseText,id:file.id}, true); }.bind(this), 500);
			}
		}.bind(this)});
	},

	onUploadProgress: function(obj)
	{
		var c		= $(obj.id);
		var percent	= ((obj.bytesLoaded / obj.bytesTotal)*100).round();
		var kbs		= (obj.bytesLoaded / (new Date().getTime() - parseInt(c.down('small.kbs').id)));
		var rem		= new Date(((obj.bytesTotal-obj.bytesLoaded) / kbs));
		
			rem	= {hr:rem.getUTCHours(), min:rem.getUTCMinutes(), sec:rem.getUTCSeconds()};
		
			rem	= 'noch ' +
				  (rem.hr ? '<b>'+rem.hr+'</b> Hr, ' : '') +
				  (rem.min ? '<b>'+rem.min+'</b> Min, ' : '') +
				  (rem.sec ? '<b>'+rem.sec+'</b> Sec. ' : '');
		
		if(rem == 'noch ')
			rem = '';
		else
			rem = rem.strip().substr(0, rem.strip().length-1)+'.';

		if(parseInt(percent)==100)
		{
			if(c.down('h1 span').innerHTML == '100%')
				return;
			
			c.down('h1 span').update('100%');
			c.down('.progress').morph('width:854px', {duration:.4}).setStyle({backgroundImage:'url(img/elem/lbghl.gif)'}).done = true;
			c.down('.progress').down('img').remove();
			c.down('h1 span').wrap('span').down('span').fade({duration:2});
			c.down('h1 small span').update('processing&hellip;').next().hide();
			
			setTimeout(function(){ if(c.down('h1 small span').innerHTML == 'processing&hellip;') this.onUploadError(obj); }.bind(this), 300000);
			
			return;
		}

		c.down('.progress').morph('width:'+((obj.bytesLoaded / obj.bytesTotal)*854).round()+'px', {duration:.4});
		c.down('h1 span').update(percent+'%');
		c.down('h1 small span').update(((obj.bytesLoaded/1024/1024).toFixed(2))+' von '+((obj.bytesTotal/1024/1024).toFixed(1))+' MB');	
		c.down('small.kbs').update('<b>'+kbs.toFixed(0)+'</b> kb/s');
		c.down('small.rem').update(rem);
	},
	
	onUploadComplete: function(obj, duplicity)
	{
		if(!obj.data || obj.data == '')
			alert("Leider ist ein Fehler aufgetreten.\nBitte tätigen Sie den Upload erneut.");
		
		var id = obj.data.substr(0, 6);
		var c  = $(obj.id).setStyle({height:$(obj.id).getHeight()});
		
		this._uploading--;
		this._complete++;
		this.setTransferStatus();

		c.select('img.status').invoke('setAttribute', 'src', 'img/sym/tick.png');
		c.select('div.progress, img.mask, small.kbs').invoke('morph', 'margin-top:-350px').invoke('fade', {duration:.2});
		
		c.setStyle({background:'transparent'}).down('h2').morph('bottom:-30px;color:#ffb400',{duration:.5});
		c.down('h1').hide();
		c.insert({top:'<h1 style="display:none;margin:0 20%;auto;width:60%"><small style="font-size:10px;color:#aaa6f0;position:static;line-height:10px">'+(duplicity?'Bereits verfügbar, erneuter Upload nicht notwendig.':'Upload successful.')+'</small><br />' +
				'<input type="text" value="http://x7.to/'+id+'" style="padding:0;text-align:center;font-size:29px;color:#160250" title="Click = mark, Dobbleclick = switch to" class="invisible" onclick="$(this).select()" ondblclick="document.location.href=$(this).value" /></h1>'});
		c.down('h1').appear();

		c.down('span.rsym').morph('right:-30px', {duration:.4}).setStyle({fontSize:'11px'}).update('<table style="text-align:right;color:#544f9f">' +
			'<tr onmouseover="$(this).down(\'input.invisible\').setStyle({color:\'#ffde00\',borderColor:\'#6e67d4\',background:\'#ab9a7d\'})" onmouseout="$(this).down(\'input.invisible\').setStyle({color:\'#544eb0\',borderColor:\'#736dd0\',background:\'#544eb0\'})">' +
			'	<td><input type="text" value="'+c.className.substr(3)+'" title="click to mark" onclick="$(this).select()" class="invisible" style="text-align:center;font-size:11px;color:#544eb0;background:#544eb0;border:1px dashed #6761c2;width:48px" /></td>' +
			'	<td style="width:20px"><img src="img/sym/key.png" /></td>' +
			'</tr><tr class="editAccess">' +
			'	<td class="link">edit code</td><td><img src="img/sym/lock-unlock.png" /></td>' +
			'</tr></table>');
		
		c.down('tr.editAccess').observe('click', function(){ this.changeAccess(obj); }.bind(this));
		if(obj.data.substr(7,1)=='1')
		{
			c.insert({top:'<img src="img/elem/convert_en.png" class="mutate" style="display:none;cursor:pointer;position:absolute;left:175px;top:-8px;z-index:1000" />'});
			c.down('img.mutate').observe('click', function(){ this.mutate(id, c); }.bind(this));
			c.down('img.mutate').grow({duration:1.5});
		}

		if(this._complete==1 && UserScreen.width>1200)
		{
			if(Prototype.Browser.IE)
				$('help2').show();
			else
				$('help2').appear({duration:1.5});
			
			$('help2').previous().appear({duration:1.5}).morph('top:105px;right:45px', {duration:1.7});
			setTimeout(function(){ c.down('span.rsym input.invisible').pulsate({duration:.5,pulses:2}); $('help2').previous().fade({duration:1.5}); }.bind(this), 1500);
		}

		if(this._waiting.length > 0)
			this.startUpload(this._waiting.shift());
	},
	
	onUploadError: function(obj)
	{
		if(this._waiting.length > 0)
			this.startUpload(this._waiting.shift());
		
		alert(obj.status);
		var c = $(obj.id);
		this._uploading--;
		this.setTransferStatus();
		c.select('m.status').invoke('setAttribute', 'src', 'img/sym/cross_circle.png');
		c.select('small.kbs, small.rem').invoke('fade');
		c.down('.progress').insert({after:'<div class="progress" style="display:none;width:100%;background:url(img/elem/lbg_red.png)"></div>'});
		c.down('h1 span').update('! Fehler !').morph({color:'#fff'}).next('small').remove();
		c.down('h1').style.marginTop = '5px';
		c.down('h2').morph('color:#8e0f06');
		c.select('.progress').last().appear();
	},
	
	changeAccess: function(obj)
	{
		var newCode;
		if(newCode = prompt('Please enter a new Admin-Code.'))
		{
			var global;
			
			if(global = confirm('Soll dieser Code in Zukunft für alle Uploads von Ihrem Computer verwendet werden?'))
				cookieAdminCode = newCode;
			
			new Ajax.Request(obj.data.substr(0, 6)+'/edit/accessCode/'+newCode, {parameters:'global='+global,onComplete:function(t){
				if(t.responseText)
					return alert(t.responseText);
				
				$(obj.id).down('span.rsym input').setValue(newCode).highlight();
			}.bind(this)});
		}
	},
	
	setTransferStatus: function()
	{
		$$('head')[0].insert({top:'<link rel="shortcut icon" href="img/'+(this._uploading<1?'sym/tick.png':'load/dts.gif')+'" type="image/vnd.microsoft.icon">'});
		
		if(this._uploading>0)
			window.onbeforeunload = function(event){ event.returnValue = ('Es sind noch nicht alle Uploads abgeschlossen.'); };
		else
			window.onbeforeunload = null;
	},
	
	mutate: function(id, c)
	{
		if(!$('status'))
			if(confirm('Konvertierungsvorgänge bleiben Mitgliedern vorbehalten.\n\nWerden Sie jetzt Mitglied.'))
				return window.location.href = 'foyer';
			else
				return false;
		
		if(confirm( 'Stream = direktes Ansehen ohne Download.\n\n' +
					'Beachten Sie:\n' +
					('- Bei jedem Vorgang werden Ihnen %cost Punkte von Ihrem Konto abgezogen.\n').sub('%cost', 10) +
					'- Pornografische Dateien dürfen nicht als Streams bereitgestellt werden.\n' +
					'- Der Stream steht nach einer kurzen Konvertierungsphase bereit.\n' +
					'- Dieser Vorgang kann nicht rückgängig gemacht werden.\n\n' +
				   ('Möchten Sie "%file" als Stream anbieten?').sub('%file', (c.down('h2')?c.down('h2').innerHTML:c.down('span', 1).innerHTML.stripTags()))))
		{
			new Ajax.Request(id+'/mutate', {onComplete:function(d){
				if(d.responseText=='')
				{
					if(c.down('h2')) // upload
					{
						c.down('img.mutate').fade();
						c.insert({top:'<table style="display:none;position:absolute;left:150px;top:15px;color:#aaa6f0;font-size:10px;"><tr><td style="width:20px"><img src="img/sym/burning.gif" onclick="cUpload.getInfo(\''+c.down('input.invisible').value.sub('http://'+window.location.host+'/', '')+'\', this)" style="cursor:help" /></td><td>Konvertierungsphase<br />eingeleitet&hellip;</td></tr></table>'});
						c.down('table').appear({duration:1.5});
					} else { // my
						if($('upoints'))
							$('upoints').update((parseInt($('upoints').innerHTML.gsub('.', '').gsub(',', ''))-10).toLocaleString());
						
						c.down('img.mutate').replace('<img src="img/sym/burning.gif" class="mutate" title="File is converting..." onclick="cUpload.getInfo(\''+c.id.substr(2)+'\', this)" style="padding-right:3px;height:14px;cursor:help" />');
					}
				}
				else
				{
					d = d.responseText.evalJSON();
					
					if(d.err)
					{
						if(d.err == 'premium')
						{
							if(confirm('Konvertierungsvorgänge bleiben Premium-Mitgliedern vorbehalten.\nMöchten Sie Ihre Mitgliedschaft erweitern?'))
								window.location.href = 'foyer';
						}
						else
							alert(d.err);
					}
				}
			}.bind(this)});
			return true;
		}
		else return false;
	},
	
	getInfo: function(id, c)
	{
		c.insert({after:'<div class="cbox" style="z-index:9;display:none;width:240px;height:66px;position:absolute;line-height:150%;font-size:12px;margin:-62px 0 0 -220px;color:#2d296d;text-align:left;background:url(img/elem/convertinfo.png)">' +
				'<h3 style="margin:25px 0 0 -10px;color:#8682bf;text-align:center">ermittle Position&hellip;</h3></div>'});
		
		var b = c.next('div.cbox').appear();
		
		b.observe('click', function(){ b.fade({duration:.5}); }.bind(this));
		
		setTimeout(function(){ this.setConvertStatus(id, b); }.bind(this), 250);
	},
	
	setConvertStatus: function(id, b)
	{
		if(b.style.display == 'none')
			return false;
		
		new Ajax.Request(id+'/cstatus', {onComplete:function(t){
			t = t.responseText;
			
			if(t.include('%')) // collect capacity
			{
				if(b.down('b.perc'))
					b.down('.perc').update(t);
				else
					b.update('<div id="convstat'+id+'" style="margin:7px 5px 0 12px">' +
						'	<p style="margin:0 0 -4px 0">Konvertierungsphase wird eingeleitet</p>' +
						'	<small style="color:#8682bf">Sammle benötigte Kapazitäten&hellip;</small>' +
						'	<p style="margin:0 0 0 0">' +
						'		<img src="img/load/cs.gif" style="vertical-align:middle" />&nbsp;' +
						'		<b class="perc">'+t+'</b> abgeschlossen</p>' +
						'</div>');
				
				return setTimeout(function(){ this.setConvertStatus(id, b); }.bind(this), 5000);
			}
			
			if(t.include('status:converting'))
			{
				b.update('<div id="convstat'+id+'" style="margin:7px 5px 0 12px">' +
					'	<p style="margin:0 0 -4px 0"><b>1. Konvertierungsphase läuft</b></p>' +
					'	<small style="color:#8682bf">Evtl. finden zwei Durchläufe statt.</small>' +
					'	<p style="margin:0 0 0 0">' +
					'		<img src="img/sym/hourglass.png" style="vertical-align:middle" />' +
					'		wenige Minuten verbleibend&hellip;</p>' +
					'</div>');
				
				return setTimeout(function(){ this.setConvertStatus(id, b); }.bind(this), 25000);
			}
			if(t.include('status:hd'))
			{
				b.update('<div id="convstat'+id+'" style="margin:7px 5px 0 12px">' +
					'	<p style="margin:0 0 -4px 0"><b>2. Konvertierungsphase HD</b></p>' +
					'	<small style="color:#8682bf">Stream verfügbar.</small>' +
					'	<p style="margin:0 0 0 0">' +
					'		<img src="img/sym/hourglass.png" style="vertical-align:middle" />' +
					'		generiere HD-Version&hellip;</p>' +
					'</div>');
				return;
			}
			
			if(t.evalJSON())
			{
				b.remove();
				return alert(t.evalJSON().err);
			}
		}.bind(this)});
	},
	
	cancelUpload: function(fileID)
	{
		if(!confirm('Upload abbrechen?'))
			return false;
		
		this._uploading--;
		this.setTransferStatus();
		this.uploader.cancel(fileID);
		
		var d = 2; // how long 2 cancel?
		var c = $(fileID);
		
		c.down('.progress').morph('width:0px', {duration:d});
		c.down('.progress img').fade();
		c.down('h1 span').fade({duration:.2});
		c.down('h1 small').update('canceled.');
		c.select('.lsym img, .rsym img').invoke('setAttribute', 'src', 'img/sym/minus-circle.png');
		c.select('small.kbs, small.rem').invoke('fade');
		
		setTimeout(function(){
			c.fade({duration:2*3});
		}.bind(this), d*1000);
		
		if(this._waiting.length > 0)
			this.startUpload(this._waiting.shift());
	}
});

function overlay(content, options)
{
	var o = Object.extend({
			id:			'overlay',
			scrollUp:	true,
			closable:	true,
			showLogo:	false,
			onExit:		function(e)
						{
							if(Object.isUndefined(e))
								var	c = $('overlay');
							else
								var c = Event.element(e);
							
							if(c.id == 'overlay' || c.hasClassName('close'))
							{
								c = $('overlay');
								c.fade({duration:.3,Transition:Effect.Transitions.linear,afterFinish:function(){ c.remove();if(o.afterExit)o.afterExit(); }.bind(this)});
								c.stopObserving();
							}
						},
			afterExit:	null,
			fixBG:		function()
						{
							if(!$('overlay'))
								return false;
							
							$('overlay').setStyle({height:(document.viewport.getScrollOffsets().top+document.viewport.getHeight())+'px',width:(document.viewport.getScrollOffsets().left+document.viewport.getWidth())+'px'});
						}
		}, arguments[1] || { });
	
	Event.observe(window, 'resize', o.fixBG);
	Event.observe(window, 'scroll', o.fixBG);
	
	$('logo').setStyle({zIndex:'auto'});
	
	if(o.showLogo)
		$('logo').setStyle({zIndex:'99999'});
	
	$('body').up().select('#overlay').invoke('remove');
	$('body').up().insert({bottom:'<div id="'+o.id+'" style="display:none;height:'+document.viewport.getDimensions().height+'"><div class="ol">' +
			'<img src="img/elem/overlay_top.png" style="margin-top:-77px" /><div style="margin:0 80px">'+content+'</div>'+
			'<img src="img/elem/overlay_bottom.png" style="position:absolute;left:0;bottom:-77px;" />' +
		'</div><small class="close" style="position:fixed;top:5px;right:4px;color:#888"><b class="link close">close</b> <img src="img/sym/cross-small.png" class="close" style="vertical-align:middle" /></small></div>'});
	var c = $(o.id);
	
	if(o.scrollUp)
		new Effect.ScrollTo($('logo'));
	if(o.closable)
		c.observe('click', o.onExit);
	
	o.fixBG();
	
	return c;
}

function errForm(elem, evulate)
{
	$(elem).setStyle({backgroundColor:'#ff0000'}).morph('background-color:#ffffff', {delay:.1,duration:.3}).focus();
	setTimeout(function(){ $(elem).setStyle({backgroundColor:''}); }.bind(this), 450);
	
	if(evulate)
		evulate();
	
	return true;
}

function login()
{
	var form = $$('form.user')[0].up();
	
	if(form.down('input').value.empty())
		return errForm(form.down('input'));
	
	if(form.down('input', 1).value.empty())
		return errForm(form.down('input', 1));
	
	form.down('button').update('<img src="img/load/fb.gif" style="vertical-align:middle" />');
	
	new Ajax.Request('james/login', {parameters:form.down('form').serialize(),onComplete:function(t){
		t = t.responseText.evalJSON();
		
		if(t.err)
		{
			form.down('button').update('Login').disabled = false;
			if(!$('lostpw')) form.down('button').insert({after:'&nbsp; &nbsp; <span id="lostpw" class="link">Passwort vergessen?</span>'});
			$('lostpw').observe('click', function(){ lostPw(); }).pulsate();
			return alert(t.err);
		}
		
		window.location.href = 'my';
	}.bind(this)});
}

function lostPw()
{
	overlay('<h1><img src="img/elem/lostpw.png" style="margin:0 7px -1px -12px" />Recover password<br />' +
			'<small style="padding-left:13px;font-size:11px;color:#9999c9">Sollten Sie Ihr Passwort verlegt haben, so können Sie sich an dieser Stelle ein Neues generieren lassen.</small></h1>' +
			'<form method="post" action="james/login/recover" id="lostpwf"><table style="width:97%;margin-left:20px"><tbody><tr><td><h2 style="margin:0">User Alias / ID</h2><small style="color:#9999c9">Bitte geben Sie Ihre Account-ID oder Ihren Alias an.</small></td>' +
			'<td style="text-align:right"><input type="text" name="user" style="width:313px;text-align:center;font-size:23px" /></td></tr></tbody>' +
			'<tbody style="height:50px"><tr><td colspan="2" style="text-align:right"><button style="font-size:18px;color:#555" id="pob"><img src="img/sym/key.png" /> Request a new password</button></td></tr></tbody>' +
			'</table></form>').appear().down('div').morph('margin-top:150px');
	
	$('lostpwf').observe('submit', function(e){ e.stop();
		var f = $('lostpwf');
		
		if(f.down('input').value.blank())
			return errForm(f.down('input'));
		
		f.down('button').update(f.down('button').innerHTML.sub('sym/key.png', 'load/ovl.gif')).disabled = true;
		
		f.request({onComplete:function(t){
			t = t.responseText.evalJSON();
			f.down('button').update(f.down('button').innerHTML.sub('load/ovl.gif', 'sym/key.png')).disabled = false;
			
			if(t.err || !t)
				return alert(t.err);
			
			f.down('tbody').update('<tr><td colspan="2">' +
				'<h2 style="text-align:center;margin:5px 0 0 0">' +
				'	<small style="font-size:11px">Please check your inbox.</small><br />' +
				'	<img src="img/sym/tick.png" /> Ein Bestätigungslink ist auf dem Weg zu Ihnen.' +
				'</h2></td></tr>');
			f.down('button').fade({duration:.5});
			f.down('tbody', 1).morph('height:1px').down('h2').setStyle({margin:'0'});
		}.bind(this)});
	});
}

function generate(len)
{
	var conso = new Array("b","c","d","f","g","h","j","k","l","m","n","p","r","s","t","v","w","x","y","z");
	var vocal = new Array("a","e","i","o","u");
	var password = '';
	
	for(i=0; i < len/2; i++)
	{
		var c = Math.ceil(Math.random() * 1000) % 20;
		var v = Math.ceil(Math.random() * 1000) % 5;
		password += conso[c] + vocal[v];
	}
	
	return password;
}

function getUserScreen(){ return {width:$$('body')[0].getWidth(),height:document.viewport.getHeight()}; }
function ifReady(funct){ return document.observe('dom:loaded', funct); }

var UserScreen, cUpload, cookieAdminCode;

ifReady(function()
{
	UserScreen 		= getUserScreen();
	cUpload			= new Upload();
	cookieAdminCode = (document.cookie+';').match(/AdminCode\=(.*)\;/) ? (document.cookie+';').match(/AdminCode\=(.*)\;/)[1] : false;
	
	if(!Prototype.Browser.IE)
	{
		$$('small.lang')[0].select('img').invoke('setOpacity', .3).invoke('observe', 'mouseover', function(){ this.setOpacity(1); }).invoke('observe', 'mouseout', function(){ this.setOpacity(('en'==this.id ? .7 : .3)); });
		$('en').setOpacity(.7);
	}
	$$('small.lang')[0].show();
});