/* DOMContentLoaded event handler - by Tanny O'Haley [4] */

var domReadyEvent =
{
	name: "domReadyEvent",
	/* Array of DOMContentLoaded event handlers.*/
	events: {},
	domReadyID: 1,
	bDone: false,
	DOMContentLoadedCustom: null,

	/* Function that adds DOMContentLoaded listeners to the array.*/
	add: function(handler)
	{
		/* Assign each event handler a unique ID. If the handler has an ID, it has already been added to the events object or been run.*/
		if (!handler.$$domReadyID)
		{
			handler.$$domReadyID = this.domReadyID++;

			/* If the DOMContentLoaded event has happened, run the function. */
			if(this.bDone)
			{
				handler();
			}

			/* store the event handler in the hash table */
			this.events[handler.$$domReadyID] = handler;
		}
	},

	remove: function(handler)
	{
		/* Delete the event handler from the hash table */
		if (handler.$$domReadyID)
		{
			delete this.events[handler.$$domReadyID];
		}
	},

	/* Function to process the DOMContentLoaded events array. */
	run: function()
	{
		/* quit if this function has already been called */
		if (this.bDone)
		{
			return;
		}

		/* Flag this function so we don't do the same thing twice */
		this.bDone = true;

		/* iterates through array of registered functions */
		for (var i in this.events)
		{
			this.events[i]();
		}
	},

	schedule: function()
	{
		/* Quit if the init function has already been called*/
		if (this.bDone)
		{
			return;
		}
	
		/* First, check for Safari or KHTML.*/
		if(/KHTML|WebKit/i.test(navigator.userAgent))
		{
			if(/loaded|complete/.test(document.readyState))
			{
				this.run();
			}
			else
			{
				/* Not ready yet, wait a little more.*/
				setTimeout(this.name + ".schedule()", 100);
			}
		}
		else if(document.getElementById("__ie_onload"))
		{
			/* Second, check for IE.*/
			return true;
		}

		/* Check for custom developer provided function.*/
		if(typeof this.DOMContentLoadedCustom === "function")
		{
			/* if DOM methods are supported, and the body element exists (using a double-check 
			including document.body, for the benefit of older moz builds [eg ns7.1] in which 
			getElementsByTagName('body')[0] is undefined, unless this script is in the body section) */
			if(typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null))
			{
				/* Call custom function. */
				if(this.DOMContentLoadedCustom())
				{
					this.run();
				}
				else
				{
					/* Not ready yet, wait a little more. */
					setTimeout(this.name + ".schedule()", 250);
				}
			}
		}
		return true;
	},

	init: function()
	{
		/* If addEventListener supports the DOMContentLoaded event.*/
		if(document.addEventListener)
		{
			document.addEventListener("DOMContentLoaded", function() { domReadyEvent.run(); }, false);
		}

		/* Schedule to run the init function.*/
		setTimeout("domReadyEvent.schedule()", 100);

		function run()
		{
			domReadyEvent.run();
		}
		
		/* Just in case window.onload happens first, add it to onload using an available method.*/
		if(typeof addEvent !== "undefined")
		{
			addEvent(window, "load", run);
		}
		else if(document.addEventListener)
		{
			document.addEventListener("load", run, false);
		}
		else if(typeof window.onload === "function")
		{
			var oldonload = window.onload;
			window.onload = function()
			{
				domReadyEvent.run();
				oldonload();
			};
		}
		else
		{
			window.onload = run;
		}
		
		/* for Internet Explorer */
		/*@cc_on
			@if (@_win32 || @_win64)
			document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
			var script = document.getElementById("__ie_onload");
			script.onreadystatechange = function()
			{
				if (this.readyState == "complete")
				{
					domReadyEvent.run(); // call the onload handler
				}
			};
			@end
		@*/
	}
};

var domReady = function(handler) { domReadyEvent.add(handler); };
domReadyEvent.init();

////////////////////////////////////////////////////////////////////

/**
 * reflection.js v2.0
 * http://cow.neondragon.net/stuff/reflection/
 * Freely distributable under MIT-style license.
 */

var Reflection = {
	defaultHeight : 0.25,
	defaultOpacity: 0.5,
	
	add: function(image, options) {
		image.onload	= function(){ Reflection.set(image, options); };
		image.src		= image.src;
	},
	
	set: function(image, options) {
		Reflection.remove(image);
		
		doptions = { "height" : Reflection.defaultHeight, "opacity" : Reflection.defaultOpacity }
		if (options) {
			for (var i in doptions) {
				if (!options[i]) {
					options[i] = doptions[i];
				}
			}
		} else {
			options = doptions;
		}
	
		try {
			var d = document.createElement('div');
			var p = image;
			
			var classes = p.className.split(' ');
			var newClasses = '';
			for (j=0;j<classes.length;j++) {
				if (classes[j] != "reflect") {
					if (newClasses) {
						newClasses += ' '
					}
					
					newClasses += classes[j];
				}
			}

			var reflectionHeight = Math.floor(p.height*options['height']);
			var divHeight = Math.floor(p.height*(1+options['height']));
			
			var reflectionWidth = p.width;
			
			if (document.all && !window.opera) {
				/* Fix hyperlinks */
                if(p.parentElement.tagName == 'A') {
	                var d = document.createElement('a');
	                d.href = p.parentElement.href;
                }  
                    
				/* Copy original image's classes & styles to div */
				d.className = newClasses;
				p.className = 'reflected';
				
				d.style.cssText = p.style.cssText;
				p.style.cssText = 'vertical-align: bottom';
			
				var reflection = document.createElement('img');
				reflection.src = p.src;
				reflection.style.width = reflectionWidth+'px';
				reflection.style.display = 'block';
				reflection.style.height = p.height+"px";
				
				reflection.style.marginBottom = "-"+(p.height-reflectionHeight)+'px';
				reflection.style.filter = 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')';
				
				d.style.width = reflectionWidth+'px';
				d.style.height = divHeight+'px';
				p.parentNode.replaceChild(d, p);
				
				d.appendChild(p);
				d.appendChild(reflection);
			} else {
				var canvas = document.createElement('canvas');
				if (canvas.getContext) {
					/* Copy original image's classes & styles to div */
					d.className = newClasses;
					p.className = 'reflected';
					
					d.style.cssText = p.style.cssText;
					p.style.cssText = 'vertical-align: bottom';
			
					var context = canvas.getContext("2d");
				
					canvas.style.height = reflectionHeight+'px';
					canvas.style.width = reflectionWidth+'px';
					canvas.height = reflectionHeight;
					canvas.width = reflectionWidth;
					
					d.style.width = reflectionWidth+'px';
					d.style.height = divHeight+'px';
					p.parentNode.replaceChild(d, p);
					
					d.appendChild(p);
					d.appendChild(canvas);
					
					context.save();
					
					context.translate(0,image.height-1);
					context.scale(1,-1);
					
					context.drawImage(image, 0, 0, reflectionWidth, image.height);
	
					context.restore();
					
					context.globalCompositeOperation = 'destination-out';
					var gradient = context.createLinearGradient(0, 0, 0, reflectionHeight);
					
					gradient.addColorStop(1, 'rgba(255, 255, 255, 1.0)');
					gradient.addColorStop(0, 'rgba(255, 255, 255, '+(1-options['opacity'])+')');
		
					context.fillStyle = gradient;
					context.rect(0, 0, reflectionWidth, reflectionHeight*2);
					context.fill();
				}
			}
		} catch (e) {
	    }
	},
	
	remove : function(image) {
		if (image.className == 'reflected') {
			image.className = image.parentNode.className;
			image.parentNode.parentNode.replaceChild(image, image.parentNode);
		}
	}
}

function addReflections() {
	var rimages = $$('.reflect');
	for (i=0;i<rimages.length;i++) {
		var rheight = null;
		var ropacity = null;
		
		var classes = rimages[i].className.split(' ');
		for (j=0;j<classes.length;j++) {
			if (classes[j].indexOf('rheight') == 0) {
				var rheight = classes[j].substring(7)/100;
			} else if (classes[j].indexOf('ropacity') == 0) {
				var ropacity = classes[j].substring(8)/100;
			}
		}
		
		Reflection.add(rimages[i], { height: rheight, opacity : ropacity});
	}
}

domReady(function()
{
	addReflections();
});

///////////////////////////////////////////////////////////////////

var ShortCuts = Class.create(
{
	initialize: function()
	{
		this.elements	= 'h1, h2, h3, h4, h5, span, small, big, div, button, input, img, a, i, b, s, th, td';
		
		$$(this.elements).each(function(obj)
		{
			this.add(obj);
		}.bind(this));
		
	},
	add: function(obj)
	{
		if(obj.title.blank() || obj.title == 'undefined' || obj.hasClassName('sc_false'))
			return;
		
		if(!this.id)
			$$('body')[0].insert({bottom:
				'<div id="shortcut" style="display:none">' +
				'	<img src="img/elements/sct.gif" id="sc_arrt" style="margin-top:-6px" />' +
				'	<div style="background:#000"></div>' +
				'	<img src="img/elements/scb.gif" id="sc_arrb" />' +
				'</div>'});
	
		this.id		= $('shortcut');
		
		obj.stopObserving('mouseover').observe('mouseover', function(){ this.show(obj); }.bind(this));
		obj.stopObserving('mouseout').observe('mouseout',   function(){ this.hide(obj); }.bind(this));
	},
	show: function(obj)
	{
		if(this.id.visible())
			return;
		
		this.position	= (obj.hasClassName('sc_bot') ? 'bot' : ((obj.cumulativeOffset().top-28)>0 ? 'top' : 'bot'));
		this.cache		= obj.title;
		this.id.up().select('#shortcut>img').invoke('show');
		
		obj.title = '';
		
		switch(this.position)
		{			
			case 'top':	$('sc_arrt').hide();
						if(Prototype.Browser.IE) this.id.style.marginTop	= '-44px';
						else this.id.style.marginTop	= '-28px';			break;
			
			case 'bot':	$('sc_arrb').hide();
						this.id.style.marginTop	= (obj.getHeight()+14)+'px';	break;
		}
		
		this.id.down('div').update(this.cache);
		this.id.show().setStyle({top:(obj.cumulativeOffset().top+obj.cumulativeScrollOffset().top)+'px',left:obj.cumulativeOffset().left+'px'});
		
		if((this.id.cumulativeOffset(this.id).left+this.id.getWidth()) > (document.viewport.getWidth()-1))
			this.id.setStyle({left:(this.id.cumulativeOffset(this.id).left-this.id.getWidth()+12)+'px'}).
					down('img').setStyle({float:'right'}).next('img').setStyle({float:'right'});
		else
			this.id.down('img').setStyle({float:'left'}).next('img').setStyle({float:'left'});
	},
	hide: function(obj)
	{
		if(obj)
			obj.title = this.cache;
		
		this.position = false;
		this.id.hide();
	}
});

domReady(function()
{
	setTimeout('cShortCuts = new ShortCuts();', 250);
});

///////////////////////////////////////////////////////////////////

var UserInfo = Class.create(
{
	initialize: function()
	{
		$$('body')[0].insert(
			'<div id="userInfo" class="rimg" style="display:none;position:absolute;">'+
			'	<img src="img/sym/bw/cross_circle_frame.png" class="x" title="Kurzprofil schließen" />'+
			'	<div class="pic" style="margin:-6px -10px"><a href="profile/x/"><img src="img/elements/s.gif" class="userImg" title="Zum Profil" /></a><h4></h4></div>'+
			'	<div class="detailbox">'+
			'		<b class="age"></b>&nbsp;Jahre jung<br />aus <b class="city"></b>.'+
			'	</div>'+
			'	<div class="infos">'+
			'		<div class="bottom">'+
			'			<img src="img/sym/balloon.png" class="chat link" title="Chat mit \'Hi\' beginnen" /><img src="img/elements/vr.png" class="vr" />'+
			'			<img src="img/sym/heart.png" class="kiss link" title="Kompliment machen" /><img src="img/elements/vr.png" class="vr" />'+
			'			<img src="img/sym/lightning.png" class="nudge link" title="Anstupsen" /><img src="img/elements/vr.png" class="vr" />'+
			'			<img src="img/sym/crown_silver.png" class="contact link" title="als Kontakt hinzufügen" /><img src="img/elements/vr.png" class="vr" />'+
			'			<form style="display:inline"><input type="text" value="Nachricht pinnen..." /></form>'+
			'		</div>'+
			'		<div style="padding:0;float:right">'+
			'			<a href="profile/x/"><img src="img/sym/newspaper.png" title="Zum Profil" /></a><img src="img/elements/vr.png" class="vr" />'+
			'			<a href="profile/x/~gallery"><img src="img/sym/pictures.png" title="Zu den Fotos" /> <small class="pics small"></small></a><img src="img/elements/vr.png" class="vr" />'+
			'			<a href="profile/x/~groups"><img src="img/sym/group.png" title="Zu den Gruppen" /> <small class="groups small"></small></a><img src="img/elements/vr.png" class="vr" />'+
			'			<a href="profile/x/~contacts"><img src="img/sym/members.png" title="Zu den Kontakten" /> <small class="relations small"></small></a>'+
			'		</div>'+
			'		<h3 style="color:#777;margin:5px 0 8px 5px;font-weight:normal"><img src="img/sym/star_small.png" style="vertical-align:middle" /> Events</h3>'+
			'		<h2 style="font-weight:normal" class="events"></h2>'+
			'	</div>'+
			'</div>');
		
		this.Element = $('userInfo');
		
		if(typeof Draggable != 'undefined')
			new Draggable(this.Element);
		
		this.Element.down('.x').observe('click', function(){ this.close(); }.bind(this));
		
		this.scan();
	},
	
	scan: function()
	{
		$$('.userInfo').each(function(o)
		{
			if(o.title)
				this.add(o);
		}.bind(this));
	},
	
	add: function(obj, id)
	{
		this.remove(obj, id);
		
		if(!id && obj.title)
		{
			id = obj.title
			obj.title = '';
		}

		obj.setStyle({cursor:'pointer'}).observe('click', function(e){ this.open(Event.element(e), id); }.bind(this));
	},
	
	remove: function(obj, id)
	{
		obj.setStyle({cursor:'auto'}).stopObserving('click', function(e){ this.open(Event.element(e), id); }.bind(this));
	},
	
	open: function(obj, user, options)
	{
		this.id	 = user;
		this.Obj = $(obj);
		
		this.Obj.setStyle({cursor:'wait'}).observe('dblclick', function(e){ this.Obj.stopObserving(); window.location.href = 'profile/'+this.id; }.bind(this));

		this.Element.down('.pic img').src = cSIIU.getData('user', user).small;
		this.Element.down('img.contact').src = 'img/sym/crown_silver.png';
		this.Element.down('img.chat').stopObserving().observe('click', function(){ this.chat(); }.bind(this)).src = 'img/sym/balloon.png';
		this.Element.down('img.kiss').stopObserving().observe('click', function(){ this.kiss(); }.bind(this)).src = 'img/sym/heart.png';
		this.Element.down('img.nudge').stopObserving().observe('click', function(){ this.nudge(); }.bind(this)).src = 'img/sym/lightning.png';
		this.Element.down('form').stopObserving().observe('submit', function(e){ e.stop(); this.pin(); }.bind(this));
		this.Element.down('input').stopObserving().observe('click', function(){ this.stopObserving(); this.setStyle({color:'#444'}); this.value = ''; });
		
		this.options = Object.extend({
			onLoad:		Prototype.emptyFunction,	// has to return true!
			onComplete:	Prototype.emptyFunction
		}, arguments[2] || { });
		
//		if(!this.options.onLoad())
//			load(this.Obj);
		
		new Ajax.Request('james/profile/'+this.id+'/short', {onComplete:function(data)
		{
			var user = data.responseText.evalJSON(true);
			user.id  = this.id;
			var id;
		
			this.Element.down('img.contact').stopObserving().observe('click', function(){ cI.newFriend(user); }.bind(this));
			if(user.relation)
				this.Element.down('img.contact').hide().next().hide();
			else
				this.Element.down('img.contact').show().next().show();
			
			this.Obj.setStyle({cursor:'pointer'});
			
			this.Element.select('a').each(function(link)
			{
				link.href = link.href.sub(/profile\/(.*)\//, 'profile/'+this.id+'/');
			}.bind(this));

			this.Element.down('.pic h4').update(user.firstName).className = user.gender;
			this.Element.down('.age').update(user.age);
			this.Element.down('.city').update(user.city || '<i>n/a</i>');
			
			if(user.pics)
				this.Element.down('.pics').update(user.pics).up().show().previous().show();
			else
				this.Element.down('.pics').up().hide().previous().hide();
			
			if(user.groups)
				this.Element.down('.groups').update(user.groups).up().show().previous().show();
			else
				this.Element.down('.groups').up().hide().previous().hide();
			
			if(user.relations)
				this.Element.down('.relations').update(user.relations).up().show().previous().show();
			else
				this.Element.down('.relations').up().hide().previous().hide();
			
			new iText(this.Element.down('.events'), user.events, {duration:1.5});
						
			Event.observe(document.onresize ? document : window, 'resize', function(){ this.place(); }.bind(this));  
			
			
			if(this.options.onComplete)
				this.options.onComplete();
			else
				this.Obj.down('.overlay').fade({duration:.25});
			
			this.place();
			this.Element.show();
			Reflection.add(this.Element.down('.pic img'));
		}.bind(this)});
		this.place();
	},
	
	chat: function()
	{
		if(!this.id)
			return;
		
		cShortCuts.hide();
		var elem = this.Element.down('img.chat');
		
		elem.stopObserving().src = 'img/load/smallgrey.gif';
		error = false;
		
		new Ajax.Request('james/profile/'+this.id+'/make/chat', {parameters:'text=hi',onComplete:function()
		{
			elem.highlight();
			elem.title	= error ? error.message : 'Der Chat wurde eröffnet. :)';
			elem.src	= 'img/sym/'+(error ? 'information' : 'tick')+'.png';
			cShortCuts.initializie();
		}});
	},
	
	pin: function()
	{
		if(!this.id)
			return;
		
		var form  = this.Element.down('form');
		var value = form.down('input').value;
		
		if(value=='Nachricht pinnen...' || value.blank())
			return;
		
		form.update('<img src="img/load/smallgrey.gif" />');
		error = false;
		
		new Ajax.Request('james/profile/'+this.id+'/make/pin', {parameters:'text='+encodeURIComponent(value),onComplete:function()
		{
			form.highlight({endcolor:'#dedede'});
			
			if(error)
				return form.update('<img src="img/sym/information.png" /> <small class="small">'+error.message+'</small>');
			
			form.update('<img src="img/sym/tick.png" /> Dein Pinn wurde gepinnt. :)');
		}});
	},
	
	kiss: function()
	{
		if(!this.id)
			return;
		
		var elem = this.Element.down('img.kiss');
		
		elem.stopObserving().src = 'img/load/smallgrey.gif';
		error = false;
		
		new Ajax.Request('james/profile/'+this.id+'/make/kiss', {onComplete:function(t)
		{
			elem.highlight();
			elem.title	= error ? error.message : 'Dein Kompliment wurde abgegeben. :)';
			elem.src	= 'img/sym/'+(error ? 'information' : 'tick')+'.png';				
			cShortCuts.initializie();
		}});
	},
	
	nudge: function()
	{
		if(!this.id)
			return;
		
		var elem = this.Element.down('img.nudge');
		
		elem.stopObserving().src = 'img/load/smallgrey.gif';
		error = false;
		
		new Ajax.Request('james/profile/'+this.id+'/make/nudge', {onComplete:function()
		{
			elem.highlight();
			elem.title	= error ? error.message : 'Du hast gestupst. :)';
			elem.src	= 'img/sym/'+(error ? 'information' : 'tick')+'.png';				
			cShortCuts.initializie();
		}});
	},
	
	place: function()
	{
		this.getPosition();
		
		if(!Prototype.Browser.IE)
			this.Element.clonePosition(this.Obj, {setHeight:false,setWidth:false,offsetTop:(this.pos.y=='+'?-38:-165),offsetLeft:(this.pos.x=='+'?-38:-390)});
	},
	
	getPosition: function()
	{
		var pos = {x:'+',y:'+'};
		
		if((this.Obj.viewportOffset(this.Obj).top+180) > document.viewport.getHeight())
			pos.y = '-';
		
		if((this.Obj.viewportOffset(this.Obj).left+440) > document.viewport.getWidth())
			pos.x = '-';
		
		this.pos = pos;
	},
	
	close: function()
	{
		this.id = false;
		this.Element.hide();
	}
});

domReady(function()
{
	cUserInfo = new UserInfo();
});

///////////////////////////////////////////////////////////////////

var iText = Class.create(
{
	initialize: function(id, text, options)
	{
		if(id.iText || !id)
			return false;
		
		this.id			= $(id);
		this.id.iText	= true;
		
		if(typeof text == 'undefined')
			text = id.innerHTML;
		
		if(typeof text == 'string')
			text = [text];
		
		this.options 	= Object.extend({
			duration:		1,
			start:			0,
			effect:			'fade',
			onSwitch:		null,
			height:			20,
			highlightcolor:	'#eeeeee',
			endcolor:		'#000000'
		}, arguments[2] || { });

		this.pos	= this.options.start;
		this.text	= text;
		
		if(this.options.effect == 'slide')
		{
			this.id.wrap('div', {id:this.id.id,style:'position:relative;overflow:hidden;height:'+this.options.height+'px'});
			this.id.style.position = 'absolute';
			this.id.id = '';
			this.id	= this.id.up();
		}
		
		this.id.onmouseover = function(){ this.freeze(); }.bind(this);
		this.id.onmouseout	= function(){ this.melt(); }.bind(this);
		
		this.next();		
	},
	freeze: function()
	{
		clearTimeout(this.timeout);
	},
	melt: function()
	{
		this.timeout	= setTimeout(function(){ this.next(); }.bind(this), (this.options.duration/2)*1000);
	},
	next: function(direction)
	{
		if(!this.id.descendantOf($$('body')[0]) || !this.id.visible()) return false;	// checks if element is inside the body and really(!) visible
		
		switch(this.options.effect)
		{
			case 'lick':	this.lick();	break;
			case 'slide':	this.slide();	break;
			case 'plain':	this.plain();	break;
			default:		this.fade();	break;
		}

		if(this.options.onSwitch)
			this.options.onSwitch(this.text[this.pos]);
		
		if(!direction)
			this.pos 		= (this.pos < this.text.length-1 ? this.pos+1 : 0);
		else
			this.pos		= (this.pos > this.text.length+1 ? this.pos-1 : this.text.length);
		
		this.freeze();
		this.timeout	= setTimeout(function(){ this.next(); }.bind(this), (this.options.duration+0.5)*1000);
	},
	add: function(text)
	{		
		this.text.splice(this.pos, 0, text);
	},
	plain: function()
	{
		this.id.update(this.text[this.pos]);
	},
	fade: function()
	{
		this.id.fade({to:.01,duration:.2});
		var next = this.text[this.pos];
		
		setTimeout(function()
		{
			this.id.update(next);
			this.id.appear({duration:.2});
		}.bind(this), 200);
	},
	lick: function()
	{
		if(this.text.length>1)
			this.fade();
		else
			this.id.update(this.text[this.pos]);
		
		this.id.style.color = this.options.endcolor;
		setTimeout(function()
		{
			new Effect.tagifyText(this.id);
		
			this.time	= ((this.options.duration*0.4) / $$('#'+this.id.id+' span').length);
			this.letter	= $$('#'+this.id.id+' span')[0];
			
			new PeriodicalExecuter(function(pe)
			{
				if(!this.letter)
					return pe.stop();
				
				var id = this.letter.identify();
				
				new Effect.Morph(this.letter, {fps:35,style:'color:'+this.options.highlightcolor,queue:{scope:'s'+id},duration:0.2});
				new Effect.Morph(this.letter, {fps:35,style:'color:'+this.options.endcolor,queue:{scope:'s'+id,position:'end'},duration:0.3});
				
				if(!this.letter.next())
					pe.stop();
				else
					this.letter = this.letter.next();
			}.bind(this), this.time);
		}.bind(this), this.text.length>1?400:0);
		
	},
	slide: function()
	{
		this.id.insert({top:this.id.innerHTML});
		var newT = $(this.id.firstChild);
		var oldT = $(this.id.lastChild);

		oldT.morph('top:-100%', {duration:.3});
		oldT.fade();

		newT.update(this.text[this.pos]);
		newT.style.bottom	= '-'+this.id.getHeight()+'px';
		newT.morph('bottom:0', {duration:.3});
		newT.setOpacity(0.1);
		newT.appear({duration:.3});
		
		setTimeout(function(){ this.id.lastChild.remove(); }.bind(this), 300);
	}
});

///////////////////////////////////////////////////////////////////

var Submenu = Class.create(
{
	initialize: function(id, handler)
	{
		this.id			= $(id);
		this.handler	= handler;
		this.active		= this.id.down(1);
		this.pos 		= 0;
		this.width		= this.id.down(1).getWidth()+12;
		this.gender		= $("body").hasClassName('umale') ? 'male' : ($("body").hasClassName('ufemale') ? 'female' : '');
		
		this.id.down(1).style.color = "#fff";
		
		this.id.insert({bottom:
			'<div style="position:absolute;top:-1px;left:-7px;width:'+this.width+'px;background:url(img/elements/sb_'+this.gender+'_center.png) repeat-x 2px 0">' +
			'	<img src="img/elements/sb_'+this.gender+'_left.png" style="background:#fff;float:left">' +
			'	<img src="img/elements/sb_'+this.gender+'_right.png" style="background:#fff;float:right">' +
			'</div>'});
		
		$$("#"+id+" span").each(function(obj)
		{
			obj.observe('click', function(){ this.click(obj); }.bind(this));
		}.bind(this));
	},
	
	click: function(obj)
	{	
		if(this.pos<((obj.viewportOffset()[0])-($("center").viewportOffset()[0])-7))
			this.dir	= '-';
		else
			this.dir	= '+';

		if(this.active.id != obj.id)
			this.handler(obj, this);
		
		return this.dir == '+' ? true: false;
	},
	
	move: function(obj)
	{
		obj.up().adjacent("span").each(function(o)
		{
			new Effect.Morph(o, {style:"color:#aaaaaa;",duration:.3});
		});
		
		this.active	= obj;
		this.pos	= ((obj.viewportOffset()[0])-($("center").viewportOffset()[0]));
		this.width	= obj.getWidth()+2;

		new Effect.Morph(obj, {style:"color:#ffffff",duration:.5});
		new Effect.Morph(obj.up().adjacent("div")[0], {style:"margin-left:"+this.pos+"px;width:"+(this.width+10)+"px;",duration:.5});
	}
});

///////////////////////////////////////////////////////////////////

function $FE(form)
{
	form = $(form);

	form.select('input, textarea, select').reverse().each(function(o)
	{
		if(!o.getValue())
		{
			if(o.tagName != 'SELECT')
				o.focus();
			return o;
		}
	});
}

var Sound = Class.create(
{
	initialize: function(){ this.Element = Array(); },
	play: function(file)
	{
		return ($$('body')[0].insert('<embed src="sound/'+file+'" autostart="true" style="width:0;height:0" />').identify());
	}
});

domReady(function(){ cSound = new Sound(); });

///////////////////////////////////////////////////////////////////

var SIIU = Class.create(
{
	getData: function(from, id)
	{
		return {path:'data/'+from+'/'+id+'/',small:'data/'+from+'/'+id+'/small.jpg'};
	},
	fetchResponse: function(transport)
	{
		var data = transport.responseText ? transport.responseText.evalJSON() : false;

		if(!data)
			return;
		
		if(data.error)
			return alert(data.error.message);
		
		return data;
	}
});

var cSIIU = new SIIU();
var error = false;