	if( !root ) {
		var root = '';
	}
	
	function updateCheckbox(element) {
		var container = element.getParent('span');
		
		if( element.get('checked') )
			container.setStyle('background-position', '0 -11px');
		else container.setStyle('background-position', '0 0');
	}

	function playMusic(url) {
		var container = $('hiddenPlayer');
		var fname = url.substr(0, url.indexOf('.'));
		container.set('src', root + 'swf/player.php?fname=../' + fname);
	}
	
	function stopMusic() {
		var container = $('hiddenPlayer');
		if( !container ) return false;
		container.set('src', '');
	}

	function userPlaylist_addEvent() {
		
		var pollUserTab = $$('#pollUserTab .buttons .button');
		if( pollUserTab && pollUserTab[0] )
			pollUserTab[0].addEvent('click', function() {
		 		var userTab = $$('#pollUserTab .pollUser-mod');
				var userId = this.getElement('span.userId').get('text');
				var request = new Request.HTML({
					url: 'util/pollUser.php',
					method: 'post',
					data: { userId: userId },
					onSuccess: function(html) {
						userTab.set('text', '');
						userTab.adopt(html);
						userPlaylist_addEvent();
					}
				});
				request.send();
			
				this.removeProperty('href');
				return false;
			
			});
		
	}

	window.addEvent('load', function() {
		var tmpImg = new Image();
		tmpImg.src = root + 'img/checkbox.gif';
		
		tmpImg.onload = function() {
			var in_checkboxs = $$('input[type=checkbox]');
			if( in_checkboxs ) {
				in_checkboxs.each(function(item) {
					var container = new Element('span');
					container.addClass('checkbox');
					container.setStyle('display', 'inline-block');
					container.setStyle('background', 'transparent url(' + root + 'img/checkbox.gif) no-repeat');
					container.setStyle('vertical-align', 'middle');
					container.setStyle('margin-right', '3px');
					container.setStyle('width', '13px');
					container.setStyle('height', '11px');
					container.setStyle('overflow', 'hidden');
				
					container.wraps(item);
			
					item.setStyle('display', 'none');
					updateCheckbox(item);
					container.addEvent('click', function(){
						var element = this.getElement('input');
						if( element.get('checked') ) element.removeProperty('checked');
						else element.set('checked', 'true');
						element.fireEvent('click');
					
						updateCheckbox(element);
					});
				});
			}
		};
		
		userPlaylist_addEvent()
		
		/**
		 * Botões para tocar som
		 */
		var playerElem = new Element('iframe', {id: 'hiddenPlayer'});
		if( playerElem ) {
			playerElem.setStyle('width', '1px');
			playerElem.setStyle('height', '1px');
			playerElem.setStyle('position', 'absolute');
			playerElem.setStyle('top', '-9999px');
			playerElem.setStyle('left', '-9999px');
			playerElem.setStyle('overflow', 'hidden');
			playerElem.set('src', root + 'swf/player.php');
			playerElem.inject($('wrap'));
		}
		
		var in_player = $$('.player input');
		if( in_player ) {
			in_player.each(function(item) {
				item.addEvent('click', function() {
					if( this.hasClass('playing') ) {
						this.removeClass('playing');
						stopMusic();
					} else {
						$$('.player input').each(function(item2) {
							item2.removeClass('playing');
						});
				
						this.addClass('playing');
						var url = item.get('value');
						playMusic(url);
					}
				
					return false;
				});
			});
		}
			
		var msgElem = $('sendMsg_msg');
		if( msgElem ) {
			var handleMsg = function() {
				var txt = msgElem.get('value');
				if( txt.length > 100 ) {
					txt = txt.substr(0, 100);
					msgElem.set('value', txt);
				}
			}
			handleMsg.periodical(500, handleMsg);
		}
	});
