

	function runTrailer(src, fVars, type)
	{
		var trailerContainer = getObject('tutorialTrailer');
		if(trailerContainer)
		{
			trailerContainer.innerHTML = '<div id="tutorialTrailerPlayer"></div>';

			swfobject.embedSWF
			(
				src,
				'tutorialTrailerPlayer',
				'500',
				'343',
				'9.0.115',
				null,
				null,
				{
					allowScriptAccess : "always",
					allowFullscreen : "true",
					flashvars : "info="+ fVars + "&type=" + type
				}
			);

			/**
			AC_FL_ToText
			(
				"src", src,
				"width", '500', 
				"height", '343',
				"align", "middle",
				"id", "TrailerPlayer",
				"quality", "high",
				"bgcolor", '#000000',
				"name", "mainPlayer",
				"allowScriptAccess","always",
				"allowFullscreen", "true",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer",
				"flashvars", 'info='+ flashVars +'&amp;type='+ type
			);
			*/
		}
	}

	function replaceImage(obj, url)
	{
		obj.src = url;
	}

	String.prototype.trim = function(str) {
	
		str = str.replace(/^[ ]+(.*)$/, '$1'); // LEFT
		str = str.replace(/^(.*)[ ]+$/, '$1'); // RIGHT
		return str;
	}

	function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}

	function toHex(N) {
	 if (N==null) return "00";
	 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
	 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
	 return "0123456789ABCDEF".charAt((N-N%16)/16)
	      + "0123456789ABCDEF".charAt(N%16);
	}

	function getWindowSize()
	{
	    var myWidth = 0, myHeight = 0;  

	    if( typeof( window.innerWidth ) == 'number' )
	    {
	        //Non-IE  
	        myWidth = window.innerWidth;  
	        myHeight = window.innerHeight;  
	    }
	    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	    {
	        //IE 6+ in 'standards compliant mode'  
	        myWidth = document.documentElement.clientWidth;  
	        myHeight = document.documentElement.clientHeight;  
	    }
	    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	    {
	        //IE 4 compatible  
	        myWidth = document.body.clientWidth;  
	        myHeight = document.body.clientHeight;  
	    }

	    return [ myWidth, myHeight ];  
	}


	function getScrollPosition()
	{
		var scrOfX = 0, scrOfY = 0;  
	   
		if( typeof( window.pageYOffset ) == 'number' )
		{
			//Netscape compliant  
			scrOfY = window.pageYOffset;  
			scrOfX = window.pageXOffset;  
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			//DOM compliant  
			scrOfY = document.body.scrollTop;  
			scrOfX = document.body.scrollLeft;  
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			//IE6 standards compliant mode  
			scrOfY = document.documentElement.scrollTop;  
			scrOfX = document.documentElement.scrollLeft;  
		}

		return [ scrOfX, scrOfY ];  
	}


	function getObject(IDorOBJ) {

		if (typeof(IDorOBJ) == 'object') {
			return IDorOBJ;
		}
	
		if (document.getElementById(IDorOBJ)) {
			return document.getElementById(IDorOBJ);
		} else {
			return false;
		}
	}
	
	
	function delChild(parentObj, obj) {
	
		parentObj.parentNode.removeChild(obj);
		return true;
	}
	
	
	function getChilds(obj) {
		return obj.childNodes;
	}
	
	
	function getChildsLength(obj){
		return obj.childNodes.length;
	}
	
	
	function setChildPosition(parentObj, position, obj) {
	
	  parentObj.parentNode.insertBefore(obj, parentObj.parentNode.childNodes[posisiton]);
	  return true;
	}
	
	
	function setAttributes(obj, params) {
	
		for (var attribute in params) {
			obj.setAttribute(attribute, params[attribute]);
		}
	}
	
	
	function getAttributes(obj, neededAttributes) {
	
		var returnObject = new Object();
		var attributes = neededAttributes.split(',');
	
		for (var index in attributes) {
			returnObject[attributes[index]] = obj.getAttribute(attributes[index]) || false;
		}
	
		return returnObject;
	}
	
	
	function newElement(objName) {
	
		var obj = document.createElement(objName);
		return obj;
	}
	
	
	function deleteElement(id_OR_obj) {
	
		var obj = getObject(id_OR_obj);
		obj.parentNode.removeChild(obj);
		return true;
	}
	
	
	function addText(obj, text) {
	
		var textObj = document.createTextNode(text);
		obj.appendChild(textObj);
	}
	
	
	function addAttribute(obj, attribute, value) {
	
		var elem = document.createAttribute(attribute);
		elem.nodeValue = value;
		obj.setAttributeNode(elem);
	}
	
	
	function attachElement(obj, id_OR_obj) {
	
		if (typeof id_OR_obj == 'string') {
			var bindObj = getObject(id_OR_obj);
		} else {
			var bindObj = id_OR_obj;
		}
	
		if (!typeof bindObj == 'object') {
			return false;
		}

		obj.appendChild(bindObj);
	}


	function switchDisplay(targetOff, targetOn) {

		if(targetOff)
		{	
			var hideObjects = targetOff.split(",");
			for(obj in hideObjects) {
				hideObj = getObject(hideObjects[obj]);
				if(hideObj) hideObj.style.display	= 'none';
			}
		}
		
		if(targetOn)
		{
			var showObjects = targetOn.split(",");
			for(obj in showObjects) {
				showObj = getObject(showObjects[obj]);
				if(showObj) showObj.style.display	= 'block';
			}
		}
	}

	function AJAX_CLASS() {
		this.connection		= null;
		this.running		= false;
		this.requestQueue	= new Array();
		this.requestCounter	= 0;

		this.initRequest();
	}


	AJAX_CLASS.prototype.initRequest = function() {

		if (window.XMLHttpRequest) {
			this.connection = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				this.connection = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					this.connection = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) { 
					return false;
				}
			}
		}

		if (!this.connection) {
			return false;
		}

		return true;
	}


	AJAX_CLASS.prototype.startRequest = function() {
	
		if (this.connection == null) {
		  this.initRequest();
		}

		this.running = true;

		var request = this.requestQueue[this.requestCounter];

		try{
			this.connection.open(request['method'], request['url'], true);
		} catch(e) {
			return false;
		}

		if(request['method'] == 'POST')
		{
			this.connection.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		this.connection.onreadystatechange = this.exeCallback;
		this.connection.send(request['send']);

		return true;
	}


	AJAX_CLASS.prototype.registerRequest = function(requestObject) {

		this.requestQueue[this.requestQueue.length] = requestObject;

		if (!this.running) {
			this.startRequest();
		}

		return true;
	}


	AJAX_CLASS.prototype.exeCallback = function() {
	
		if (AJAX.connection.readyState == 4) {
			if (AJAX.connection.status == 200) {

				if(AJAX.connection.responseXML) {
					if(typeof AJAX.requestQueue[AJAX.requestCounter].callback == 'function') {
						var requestCallback = function(){};
		        		requestCallback.call(this, AJAX.requestQueue[AJAX.requestCounter].callback(AJAX.connection.responseXML.documentElement));
		        	}
		        	else
		        	{
						XMLParser(AJAX.connection.responseXML.documentElement);
		        	}
				}

	        	AJAX.requestCounter++;

				if (AJAX.requestQueue.length > AJAX.requestCounter) {
					setTimeout("AJAX.startRequest()",500);
				} else {
					AJAX.running = false;
					AJAX.requestQueue = new Array();
					AJAX.requestCounter = 0;
				}
				

			} else if (AJAX.connection.status == 404) {
			}
		}
	}


	AJAX_CLASS.prototype.sendRequest = function(requestObj,requestType) {
	
		var reqObj= new Object();
		reqObj.id = requestObj.id || 'unknown process';
		reqObj.callback = requestObj.callback || false;
		reqObj.method =  requestObj.method || 'GET';
		reqObj.url = ''+( requestObj.url || '');
		reqObj.option = requestObj.option || true;
		reqObj.send = requestObj.send || null;
		reqObj.xml	= requestType;
	
		return this.registerRequest(reqObj);
	}
	
	function clearLogin(XMLDocument)
	{
		getObject('login_container').removeChild(getObject('login_placeholder'));
		XMLParser(XMLDocument);
	}


	function initialize() {
		
		if(POPUP)
		{
			return false;
		}

		AJAX = new AJAX_CLASS;
	    
		if (CHATTIMER > 0) 
		{
			window.setTimeout("checkForChats()", CHATTIMER);
		}
	}


	function XMLParser(XMLDocument) {

		if (XMLDocument.childNodes.length == 0 || XMLDocument.nodeName != 'maketv') {
			return false;
		}

		var counter		= 0;
		var XMLElement	= null;

		while(counter < XMLDocument.childNodes.length) {

			if (XMLDocument.childNodes[counter].nodeType != 1) {
				counter++;
				continue;
			}

			XMLElement	= XMLDocument.childNodes[counter];

			switch(XMLElement.nodeName) {

				case 'text':
					CreateText(XMLElement);
				break;

				case 'image':
					CreateImage(XMLElement);
				break;

				case 'container':
					CreateContainer(XMLElement);
				break;

				case 'link':
					CreateLink(XMLElement);
				break;
				
				case 'embedUrl':
					EMBEDPLAYER.setTinyUrl(XMLElement);
				break;

			}

			counter++;
		}
	}

	function loginKeypressed(e, callback, arguments)
	{
		var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
		if(isOpera)
		{
			return;
		}

		var evt = (e) ? e : ( (window.event) ? window.event : null); 
		if(evt)
		{
			var key = (evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
		}
		if(key=="13")
		{
			eval(callback+'("'+arguments+'");');
		} 
	}

	function sendRegister()
	{
		if
		(
			getObject("username").value == "" || 
			getObject("register_email").value == "" ||
			getObject("channelname").value == "" ||
			getObject("register_email").value != getObject("confirm_email").value ||
			!getObject('agb').checked
		)
		{
			if(getObject("username").value == "")
			{
				RequestHandler.displayMessage('register_username');
			}
			if(getObject("channelname").value == "")
			{
				RequestHandler.displayMessage('register_channelname');
			}
			if(getObject("register_email").value == "")
			{
				RequestHandler.displayMessage('register_email');
			}
			if(getObject("register_email").value != getObject("confirm_email").value)
			{
				RequestHandler.displayMessage('register_email_notmatch');
			}
			if(!getObject('agb').checked)
			{
				RequestHandler.displayMessage('register_acceptAGB');
			}
			return false;
		}

		getObject("register_form").submit();
		return true;
	}

	function sendForgot()
	{
		if(getObject("forgot_email").value == "")
		{
			return false;
		}

		getObject("forgot_form").submit();
		return true;
	}

	function sendChannelCreate()
	{
		if(getObject("channelname").value == "")
		{
			return false;
		}

		getObject("channelcreate_form").submit();
		return true;
	}

	function sendLogin(sessionKey)
	{
		if(getObject("password").value == "" || getObject("email").value == "")
		{
			return false;
		}

		getObject("submit_password").value = hex_md5(sessionKey.concat(hex_md5(getObject("password").value)));
		getObject("password").value = '';
		getObject("login_form").submit();
		return true;
	}

	function sendSearch()
	{
		if(getObject("search_keywords").value == "" || getObject("search_keywords").value.length < 3)
		{
			getObject('search_fail_message').style.display = 'block';
			return false;
		}

		getObject('search_fail_message').style.display = 'none';
		getObject("search_form").submit();
		return true;
	}

	function postRepeatPassword(sessionKey, passwordField)
	{
		if (getObject(passwordField).value != '') 
		{
			getObject(passwordField + '_hidden').value = hex_md5(sessionKey.concat(hex_md5(getObject(passwordField).value)));
		}
		else
		{
			getObject(passwordField + '_hidden').value = '';
		}
		getObject(passwordField).value = '';
		if (getObject(passwordField + '_repeat').value !='') 
		{
			getObject(passwordField + '_repeat_hidden').value = hex_md5(sessionKey.concat(hex_md5(getObject(passwordField + '_repeat').value)));
		}
		else
		{
			getObject(passwordField + '_repeat_hidden').value = '';
		}
		getObject(passwordField + '_repeat').value = '';
		return true;
	}
	
	
	function postChangePassword(sessionKey, formName)
	{
		var pwFields = new Array('old', 'new', 'confirm');
		for( var pwIndex in pwFields ) 
		{
        	var passwordField = formName + '_form_password_' + pwFields[pwIndex];
			if (getObject(passwordField).value) 
			{
				if (pwFields[pwIndex] == 'old') 
				{
					getObject(passwordField + '_hidden').value = hex_md5(sessionKey.concat(hex_md5(getObject(passwordField).value)));
				}
				else 
				{
					getObject(passwordField + '_hidden').value = hex_md5(getObject(passwordField).value);
				}
			}
			else
			{
				getObject(passwordField + '_hidden').value = '';
			}
			getObject(passwordField).value = '';
		}
		return true;
	}
	
	function CreateText(XMLElement)
	{
		attributes = getAttributes(XMLElement, 'container,style');

		if(!getObject(attributes.container))
		{
			return false;
		}

		var textElement = newElement('SPAN');
		addText(textElement, XMLElement.childNodes[0].nodeValue);
		if(attributes.style) addAttribute(textElement, 'class', attributes.style);
		attachElement(getObject(attributes.container), textElement);
	}


	function CreateImage(XMLElement)
	{
		attributes = getAttributes(XMLElement, 'container,class,onclick,style');

		if(!getObject(attributes.container))
		{
			return false;
		}

		var imageElement = newElement('IMG');
		
		if(attributes.style) addAttribute(imageElement, 'class', attributes.style);
		if(attributes.onclick) addAttribute(imageElement, "onclick", attributes.onclick);
		attachElement(getObject(attributes.container), imageElement);
	}


	function CreateContainer(XMLElement)
	{
		attributes  = getAttributes(XMLElement, 'container,style,id');

		if(!getObject(attributes.container))
		{
			return false;
		}

		var divElement = newElement('DIV');
		if(attributes.id) addAttribute(divElement, 'id', attributes.id);
		if(attributes.style) addAttribute(divElement, 'class', attributes.style);
		attachElement(getObject(attributes.container), divElement);
	}


	function CreateLink(XMLElement)
	{
		attributes = getAttributes(XMLElement, 'container,style,target,url,title,click');

		if(!getObject(attributes.container) || !attributes.url)
		{
			return false;
		}

		var linkElement = newElement('A');
		if(attributes.style) addAttribute(linkElement, 'class', attributes.style);
		if(attributes.target) addAttribute(linkElement, 'target', attributes.target);
		if(attributes.url) addAttribute(linkElement, 'href', attributes.url);
		if(attributes.title) addAttribute(linkElement, 'title', attributes.title);
		if(attributes.click)
		{
			linkElement.code = attributes.click;
			linkElement.onclick = function() {eval(this.code);};
		}
		addText(linkElement, XMLElement.childNodes[0].nodeValue);

		attachElement(getObject(attributes.container), linkElement);
	}
	

	function openStudio(studioUrl)
	{
		var studio = window.open(studioUrl, "_blank", "width="+screen.width+",height="+screen.height+",status=no,scrollbars=no,menubar=no,toolbar=no,resizable=yes");
		studio.focus();
		
	}
	
	function showActivity(activityObj)
	{
		getObject(activityObj.id+'_button').style.visibility = (getObject(activityObj.id+'_button').style.visibility == 'visible' ? 'hidden' : 'visible');
	}


	function refreshPage(status)
	{
		if(status)
		{
			document.location.href = CURRENT_PAGE;
			return true;
		}

		if(RequestHandler)
		{
			RequestHandler.closeCurrentWindow();
		}
	}
	
	function openChat(userId)
	{
		window.open(HTTP_HOST+'/pages/chat/create/'+userId,'_chat_'+userId,'width=360,height=240,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,location=no');
	}

	function checkForChats()
	{
		reqObj = new Object();
	    reqObj.id = 'cancel_chat';
	    reqObj.callback = handleChatIncoming;
	    reqObj.method =  'GET';
	    reqObj.url = HTTP_HOST+'pages/chatCheck';
	    reqObj.option = true;
	    reqObj.send = '';

	    AJAX.sendRequest(reqObj, false);
	    window.setTimeout("checkForChats()", CHATTIMER);
	}

	function handleChatRequest(layerId, request, originId)
	{
		getObject('navigation_chat_requests').removeChild(getObject('chat_request_'+layerId));

		if(request == 'accept')
		{
			window.open(HTTP_HOST+'pages/chat/'+request+'/'+originId, '_chat_'+originId,'width=360,height=240,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,location=no');
		}
		else
		{
			reqObj = new Object();
		    reqObj.id = 'cancel_chat';
		    reqObj.callback = false;
		    reqObj.method =  'POST';
		    reqObj.url = HTTP_HOST+'pages/chat/'+request+'/'+originId;
		    reqObj.option = true;
		    reqObj.send = 'lang='+LANG+'&XML=1';
		
		    AJAX.sendRequest(reqObj, false);
		}
		
		if(CHATMESSAGES)
		{
			for(var index in CHATMESSAGES)
			{
				if(CHATMESSAGES[index] == layerId)
				{
					delete(CHATMESSAGES[index]);
					break;
				}
			}
			if(CHATMESSAGES.length == 1)
			{
				getObject('navigation_chat_requests').style.display = 'none';
			}
		}
	}

	function handleChatIncoming(XMLDocument)
	{
		if (XMLDocument.childNodes.length == 0 || XMLDocument.nodeName != 'maketv') {
			return false;
		}

		var counter		= 0;
		var XMLElement	= null;

		while(counter < XMLDocument.childNodes.length) {

			if (XMLDocument.childNodes[counter].nodeType != 1) {
				counter++;
				continue;
			}

			XMLElement	= XMLDocument.childNodes[counter];
			counter++;

			var attributes = getAttributes(XMLElement, 'chatId,inviterName,inviterId,inviterLink,message,cancelName,acceptName');
			if(!attributes.chatId)
			{
				continue;
			}
			
			var exists = false;
			if(CHATMESSAGES)
			{
				for(var index in CHATMESSAGES)
				{
					if(CHATMESSAGES[index] == attributes.chatId)
					{
						exists = true;
						break;
					}
				}

				if(exists) continue;
				else
				{
					CHATMESSAGES[CHATMESSAGES.length] = attributes.chatId;
				}
			}
			
			getObject('navigation_chat_requests').style.display = 'block';

			// render
			var messageBox = newElement('DIV');
			addAttribute(messageBox, "id", 'chat_request_'+attributes.chatId);
			addAttribute(messageBox, "class", 'navigation_chat_request_row');

			var actionBox = newElement('DIV');
			addAttribute(actionBox, "class", 'navigation_chat_actions');

			var acceptLink = newElement('A');
			addAttribute(acceptLink, "href", '#_');
			addAttribute(acceptLink, "title", '');
			addText(acceptLink, attributes.acceptName);

			acceptLink.chatId 		= attributes.chatId;
			acceptLink.inviterId	= attributes.inviterId;
			acceptLink.onclick		= function() { handleChatRequest(this.chatId, 'accept', this.inviterId); }

			attachElement(actionBox, acceptLink);

			var cancelLink = newElement('A');
			addAttribute(cancelLink, "href", '#_');
			addAttribute(cancelLink, "title", '');
			addText(cancelLink, attributes.cancelName);

			cancelLink.chatId 		= attributes.chatId;
			cancelLink.inviterId	= attributes.inviterId;
			cancelLink.onclick		= function() { handleChatRequest(this.chatId, 'cancel', this.inviterId); }

			attachElement(actionBox, cancelLink);
			attachElement(messageBox, actionBox);

			var inviterBox = newElement('DIV');
			addAttribute(inviterBox, "class", 'navigation_chat_inviter');

			var inviterLink = newElement('A');
			addAttribute(inviterLink, "href", attributes.inviterLink);
			addAttribute(inviterLink, "title", '');
			addText(inviterLink, attributes.inviterName)
			attachElement(inviterBox, inviterLink);

			attachElement(messageBox, inviterBox);

			var clearBox = newElement('DIV');
			addAttribute(clearBox, "class", 'clear_float');
			attachElement(messageBox, clearBox);
			
			addText(messageBox, attributes.message);

			attachElement(getObject('navigation_chat_requests'), messageBox);
		}
	}
	
	function RequestHandlerToogle(id, status)
	{
		RequestHandler.toggle(id, status);
	}
	
	function flashLogin(flashSessionId)
	{
		reqObj = new Object();
	    reqObj.id = 'flash_login';
		    reqObj.callback = false;
	    reqObj.method =  'POST';
	    reqObj.url = HTTP_HOST+'pages/loginXML';
	    reqObj.option = true;
	    reqObj.send = 'flashLogin='+flashSessionId;
	
	    AJAX.sendRequest(reqObj, false);
	}

	function fbs_click()
	{
		u=location.href;
		t=document.title;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
	}

	function openShowTrimmer(targetUrl)
	{
		window.open(targetUrl,'trimmer','toolbar=0,status=0,width=800,height=600');
	}
	
	function getMouseX(event)
	{
	  return window.event ? window.event.clientX : event.clientX;
	}


	function getMouseY(event)
	{
	  return window.event ? window.event.clientY : event.clientY;
	}

	function infoshow(event, layerId)
	{
		var layer = getObject(layerId);
		if(! layer)
		{
			return false;
		}

		var scroll = getScrollPosition();
		var posLeft	= getMouseX(event);
		var posTop	= getMouseY(event);

		layer.style.top		= (posTop + scroll[1]) + 'px';
		layer.style.left	= (posLeft+ 10 + scroll[0]) + 'px';
	}

	function infohide(layerId)
	{ 
		var layer = getObject(layerId);
		if(! layer)
		{
			return false;
		}

		with(layer)
		{
			style.top		= '-5000px';
			style.left	= '-5000px';
		}
	}


		
