		var ll = new Array();
		var scroller = new Array();
		var scrollbar = new Array();
		var dimensions = new Array();
		    dimensions["_forums_w"] = 290;
		    dimensions["_forums_h"] = 200;
		    dimensions["_news_w"] = 410;
		    dimensions["_news_h"] = 210;

		function change_bg( x ) { setCookie("lp2comm_bgset",x,100); document.body.className="bg"+x; }

		function getHTTPObject() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; }

		if (window.attachEvent) {
			window.attachEvent("onresize", handleResize)
		} else {
			window.addEventListener("resize", handleResize, false)
		} 

		function handleResize() {
			document.body.className=document.body.className;
		}

		function pureAjaxCall( callto, args ) {
                    var http = getHTTPObject();
                    http.open("GET", callto + ".php"+args, true);
                    http.onreadystatechange = function() {
                        if (http.readyState == 4) {
				eval( http.responseText );
                        }
                    }
                    http.send(null);
                }

		function loadFragmentInToElement(element_id, callto, args ) {
		    if( !ll[element_id] )
			ll[element_id] = new LinkedList();
		    var element = document.getElementById(element_id);

		    if( args == null ) args = "";
		    if( callto == null ) callto = element_id;

                    if( element == null ) {
                        setTimeout("loadFragmentInToElement(\""+element_id+"\",\""+callto+"\",\""+args+"\")",1000);
                        return;
                    }

		    if( args != "" )
			args = "?"+args;

                    var tick = document.getElementById("marquee");
                    ll[element_id].add( callto+ ".php"+args );

		    element.innerHTML = '<img id="loading_img" src="images/loading.gif">';
		    var http = getHTTPObject();
		    http.open("GET", callto + ".php"+args, true);
		    http.onreadystatechange = function() {
		    	if (http.readyState == 4) { 
		    		element.innerHTML = http.responseText; 
				if( element_id == "_news" || element_id == "_forums" ) {
   				  scroller[""+element_id+""]  = new jsScroller(document.getElementById("Scroller"+element_id), dimensions[""+element_id+"_w"], dimensions[""+element_id+"_h"]);
   				  scrollbar[""+element_id+""] = new jsScrollbar (document.getElementById("Scrollbar-Container"+element_id), scroller[""+element_id+""], false);
				}
				if( element_id == "_media" ) {
				  pageLoad();
			  	}
				if( element_id == "_killbig" ) {
				  ticker_off();
				  if( callto.indexOf("leaderboard") != -1 )
		                    if( tick )
		                        tick.style.top = "410px";
				}
		    	}
		    }
		    http.send(null);
		}

		function twitter(){
			window.open("http://www.capcom.com/bumper.php?tgtwww=http%3A%2F%2Ftwitter.com%2FLost_Planet").focus();
			//"http://twitter.com/Lost_Planet");
		}
		function facebook(){
                        window.open("http://www.capcom.com/bumper.php?tgtwww=http%3A%2F%2Fwww.facebook.com%2Fpages%2FLost-Planet%2F285330833071%3Fref%3Dts").focus();
			//"http://www.facebook.com/pages/Lost-Planet/285330833071?ref=ts");
		}
		function myspace(){
			window.open("http://www.capcom.com/bumper.php?tgtwww=http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%3A%2F%2Fwww.lostplanetcommunity.com").focus();
		}
		function openGameStop() {
			pureAjaxCall("_po_bump",'');
		}

		function gamestop_xbox() {
			window.open("http://www.gamestop.com/Catalog/ProductDetails.aspx?product_id=75038");
		}
		function gamestop_ps3() {
			window.open("http://www.gamestop.com/Catalog/ProductDetails.aspx?product_id=75037");
		}

		function showMedia( x, y ) {
                    ticker_off();
		    loadFragmentInToElement("_killbig", "_media_loader.php?feed="+x);	
		}
		function openPhoto( x ) {
			window.open( urldecode(x) );
		}
                function openUrl( url ) {
                        window.open( urldecode(url) );
                }
                function previewPhoto( x ) {
		    ticker_off();
                    loadFragmentInToElement("_killbig", "_preview_img_loader", "feed="+x);
                }
                function preorderPreviewImg( x ) {
                    ticker_off();
                    loadFragmentInToElement("_killbig", "_po_preview_img_loader", "feed="+x);
                }
		function demoPreviewImg( x ) {
                    loadFragmentInToElement("_killbig", "_demo_preview_img_loader", "feed="+x);
		}
		function showEngagedAlertDlg(msg,x) {
			if( x )
				elm_id = x;
			else
				elm_id = "modal_alert_txt";
			var dlg = document.getElementById("modal_overlay_alert");
			if( dlg ) {
				dlg.style.display = 'inline';
				dlg_content = document.getElementById(elm_id);
				dlg_content.innerHTML = msg;
			}
		}
		function checkRedPlatform(){
			var p = document.getElementById('eng_red_plat_sel').platform;
			var choice = '';
			if( p[0].checked ) choice = p[0].value;
			if( p[1].checked ) choice = p[1].value;
                        var args = "?platform="+choice;
                        pureAjaxCall("_setred", args);
			return false;
		}
		function closeEngageDlg() {
                        var dlg = document.getElementById("modal_overlay_alert");
                        if( dlg )
                                dlg.style.display = 'none';
		}
		function ticker_off(){
                    var tick = document.getElementById("marquee");
                    if( tick ) {
                        tick.style.top = "-4000px";
                    }
		}
                function ticker_on(){
                    var tick = document.getElementById("marquee");
                    if( tick ) {
                        tick.style.top = "410px";
                    }
                }

		function toggleLBMenu( y ){
		   if( !document.lp_globals )
			document.lp_globals = new Object;

                   var x = document.getElementById("lb_menu_pane");
		   if( !x ) return false;
		   if( y == 1 ) {
			document.lp_globals.cooldown = 0;
                        document.lp_globals.lb_menu_extended = true;
                        x.style.display = "block";
		   }

		   if( y == 0 ) {
			clearTimeout( document.lp_globals.timer );
                        document.lp_globals.cooldown = 0;
                        document.lp_globals.timer = setTimeout( "toggleLBMenu(2)", 500 );
		   }

		   if( y == 2 && document.lp_globals.cooldown > 2 ) {
                        clearTimeout( document.lp_globals.timer );
                        document.lp_globals.cooldown = 0;
                        document.lp_globals.lb_menu_extended = false;
                        x.style.display = "none";
		   }

		   if( y == 2 ) {
			document.lp_globals.cooldown++;
			document.lp_globals.timer = setTimeout( "toggleLBMenu(2)", 500 );
		   }

/*
		   if( document.lp_globals.lb_menu_extended && x != null && y == 0 ) {
			document.lp_globals.lb_menu_extended = false;
			x.style.display = "none";
		   }
		   else {
                        document.lp_globals.lb_menu_extended = true;
			x.style.display = "block";
		   }
*/
		}

		function unloadFragment(element_id) {
                    var element = document.getElementById(element_id);
                    element.innerHTML = '<p></p>';
		}

		function closePreview(x){
			if( x ){
				// Remove the image in ctxt
				ll["_killbig"].remove( ll["_killbig"].size()-1 );
				// Back to the last time
				var callto = ll["_killbig"].item( ll["_killbig"].size()-1 );
			} else {
                        	var callto = ll["_killbig"].item( 0 );
			}
			if( callto.indexOf("?") > 0 )
				callto = callto+"&";
			else
				callto = callto+"?";	
			loadFragmentInToElement("_killbig", callto );
		}
		function datapost(){
                        loadFragmentInToElement("_killbig", "_leaderboards_U");
		}
                function config(){
                        loadFragmentInToElement("_killbig", "_leaderboards_U", "config");
                }
                function home(){
                        loadFragmentInToElement("_killbig", "_welcome");
                }
		function killbig(){
			ticker_off();
                        loadFragmentInToElement("_killbig", "_engage");
		}
		function preorder(){
                        ticker_off();
                        loadFragmentInToElement("_killbig", "_preorder");
		}
		function changeLB( titleid, lbid )
		{
		        loadFragmentInToElement("_killbig", "_leaderboards", "tid="+titleid+"&lbid="+lbid );
		}
                function changeLBCE( titleid, lbid )
                {
                        loadFragmentInToElement("_killbig", "_leaderboards_CE", "tid="+titleid+"&lbid="+lbid );
                }

                function setGamerTags(id,f){
			var xbl = f.xbl_gt.value;
			var psn = f.psn_gt.value;
			var args = "uid="+id;
			if( xbl != f.xbl_gt.defaultValue ) {
				args = args + "&xtag="+xbl+"&xpriv=0";
			}
			if( psn != f.psn_gt.defaultValue ) {
                                args = args + "&ptag="+psn+"&ppriv=0";
			}
                        loadFragmentInToElement("_killbig", "_setxbl", args);
                }

		function isValidEmail(str) {
		   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		}
                function validateEmail(id,f){
                        var eml = f.email.value;
                        var args = "?uid="+id;
			   if( isValidEmail( eml ) ) {
                                args = args + "&eml="+eml;
                       		pureAjaxCall("_seteml", args);
			   } else {
				alert("That email address appears to be invalid");
			   }
                }
		function resendEmail(){
			alert('oh my... this should do something');
		}
		function unsubscribe(id,f) {
			args = "?uid="+id;
                        pureAjaxCall("_unseteml", args);
		}
		function performSearch(titleid,lbid) {
			var tag = document.getElementById("search_text").value;
                        loadFragmentInToElement("_killbig", "_leaderboards_U", "tid="+titleid+"&lbid="+lbid+"&tag="+tag );
		}
		function lookupUser(network,titleid,lbid,tag) {
                        loadFragmentInToElement("_killbig", "_leaderboards_U", "network="+network+"&tid="+titleid+"&lbid="+lbid+"&tag="+tag );
		}

                function change_LB( titleid, lbid, act )
                {
                        loadFragmentInToElement("_killbig", "_leaderboards_U", "tid="+titleid+"&lbid="+lbid+"&act="+act );
                }
		function urldecode( encodedString ) {
  		  var output = encodedString;
		  var binVal, thisString;
		  var myregexp = /(%[^%]{2})/;
		  while ((match = myregexp.exec(output)) != null
		             && match.length > 1
		             && match[1] != '') {
		    binVal = parseInt(match[1].substr(1),16);
		    thisString = String.fromCharCode(binVal);
		    output = output.replace(match[1], thisString);
		  }
		  return output;
		}

		function setCookie(c_name,value,expiredays)
		{
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		}

		function getCookie(c_name)
		{
			if (document.cookie.length>0)
			  {
			  c_start=document.cookie.indexOf(c_name + "=");
			  if (c_start!=-1)
			    {
			    c_start=c_start + c_name.length+1;
			    c_end=document.cookie.indexOf(";",c_start);
			    if (c_end==-1) c_end=document.cookie.length;
			    return unescape(document.cookie.substring(c_start,c_end));
			    }
			  }
			return "";
		}
		function handleDefTxt(f){
		if(f.defaultValue==f.value){f.value='';}else if(f.value == ''){f.value=f.defaultValue;}
		}

		var ts_cooldown_req = false;
		function toolbarswipe(x)
		{
		   if( x ) // TRUE means expand
		   {
			if( !ts_cooldown_req ) {
			  ts_cooldown_req = true; toolbar_animate(1);
			}
		   }
		   else // Otherwise we are collapsing
		   {
			if( ts_cooldown_req )
			{
			   ts_cooldown_req = false;
			   toolbar_animate(0);
			   //alert( "initiate cooldown" );
			}
		   }
		}

		function toolbar_animate(x)
		{

		   if( x )
		   {
		      if( soundManager )
                        soundManager.play("snikt");

                          document.getElementById("toolbar_swipe").style.top = "0px";
                          //document.getElementById("page_swipe").style.top = "0px";
		   } else {
                      if( soundManager )
                        soundManager.stop("snikt");

                          document.getElementById("toolbar_swipe").style.top = "-47px";
                          //document.getElementById("page_swipe").style.top = "-47px";
		   }
		}


		function togglePanelAnimatingStatus( interval, step, max_height, step_height )
		{
			   var step_height_abs = Math.abs(step_height);

			    // schedule next animated collapse/expand event
			    if (step_height_abs>=step && step_height_abs<=(max_height-step))
			    {
				step_height += step;
				currentContent.style.height = Math.abs(step_height) + "px";
				setTimeout("togglePannelAnimatingStatus("
				    + interval + "," + step
				    + "," + max_height + "," + step_height + ")", interval);
			    }
			    // animated expand/collapse done
			    else
			    {
				if (step_height_abs<step)
				    currentContent.style.display = "none";
				currentContent.style.height = "";
				currentContent = null;
			    }
		}
	
function jsScroller (o, w, h) {var self = this;var list = o.getElementsByTagName("div");for (var i = 0; i < list.length; i++) {if (list[i].className.indexOf("Scroller-Container") > -1) {o = list[i];}}this._setPos = function (x, y) {if (x < this.viewableWidth - this.totalWidth) x = this.viewableWidth - this.totalWidth;if (x > 0) x = 0;if (y < this.viewableHeight - this.totalHeight) y = this.viewableHeight - this.totalHeight;if (y > 0) y = 0;this._x = x;this._y = y;with (o.style) {left = this._x +"px";top  = this._y +"px";}};this.reset = function () {this.content = o;this.totalHeight = o.offsetHeight;this.totalWidth = o.offsetWidth;this._x = 0;this._y = 0;with (o.style) {left = "0px";top  = "0px";}};this.scrollBy = function (x, y) {this._setPos(this._x + x, this._y + y);};this.scrollTo = function (x, y) {this._setPos(-x, -y);};this.stopScroll = function () {if (this.scrollTimer) window.clearInterval(this.scrollTimer);};this.startScroll = function (x, y) {this.stopScroll();this.scrollTimer = window.setInterval(function(){ self.scrollBy(x, y); }, 40);};this.swapContent = function (c, w, h) {o = c;var list = o.getElementsByTagName("div");for (var i = 0; i < list.length; i++) {if (list[i].className.indexOf("Scroller-Container") > -1) {o = list[i];}}if (w) this.viewableWidth  = w;if (h) this.viewableHeight = h;this.reset();};this.content = o;this.viewableWidth  = w;this.viewableHeight = h;this.totalWidth = o.offsetWidth;this.totalHeight = o.offsetHeight;this.scrollTimer = null;this.reset();};
function jsScrollbar (o, s, a, ev) {
	var self = this;this.reset = function () {
		this._parent = o;this._src    = s;this.auto = a ? a : false;
		this.eventHandler = ev ? ev : function () {};
		this._up = this._findComponent("Scrollbar-Up", this._parent);
		this._down = this._findComponent("Scrollbar-Down", this._parent);
		this._yTrack  = this._findComponent("Scrollbar-Track", this._parent);
		this._yHandle = this._findComponent("Scrollbar-Handle", this._yTrack);
		this._trackTop = findOffsetTop(this._yTrack);
		this._trackHeight = this._yTrack.offsetHeight;
		this._handleHeight = this._yHandle.offsetHeight;
		this._x = 0;this._y = 0; this._scrollDist = 5;this._scrollTimer = null;
		this._selectFunc = null;this._grabPoint = null;this._tempTarget = null;
		this._tempDistX = 0;this._tempDistY = 0;this._disabled = false;
		this._ratio = (this._src.totalHeight - this._src.viewableHeight)/(this._trackHeight - this._handleHeight);
		this._yHandle.ondragstart = function () {return false;};
		this._yHandle.onmousedown = function () {return false;};
		this._addEvent(this._src.content, "mousewheel", this._scrollbarWheel);
		this._removeEvent(this._parent, "mousedown", this._scrollbarClick);
		this._addEvent(this._parent, "mousedown", this._scrollbarClick);
		this._src.reset();
		with (this._yHandle.style) {top  = "0px";left = "0px";}
		this._moveContent();
		if (this._src.totalHeight < this._src.viewableHeight) {
			this._disabled = true;
			this._yHandle.style.visibility = "hidden";
			if (this.auto)
				this._parent.style.visibility = "hidden";
		} else {
			this._disabled = false;
			this._yHandle.style.visibility = "visible";
			this._parent.style.visibility  = "visible";
		}
	};
	this._addEvent = function (o, t, f) {
		if (o.addEventListener)
			o.addEventListener(t, f, false);
		else if (o.attachEvent)
			o.attachEvent('on'+ t, f);
		else
			o['on'+ t] = f;};
	this._removeEvent = function (o, t, f) {
		if (o.removeEventListener)
			o.removeEventListener(t, f, false);
		else if (o.detachEvent)
			o.detachEvent('on'+ t, f);
		else o['on'+ t] = null;
	};
	this._findComponent = function (c, o) {
		var kids = o.childNodes;
		for (var i = 0; i < kids.length; i++) {
			if (kids[i].className && kids[i].className == c) {
				return kids[i];
			}
		}
	};
	function findOffsetTop (o) {
		var t = 0;
		if (o.offsetParent) {
			while (o.offsetParent) {
				t += o.offsetTop;
				o = o.offsetParent;
			}
		}
		return t;
	};
	this._scrollbarClick = function (e) {
		if (self._disabled)
			return false;
		e = e ? e : event;
		if (!e.target)
			e.target = e.srcElement;
		if (e.target.className.indexOf("Scrollbar-Up") > -1)
			self._scrollUp(e);
		else if (e.target.className.indexOf("Scrollbar-Down") > -1)
			self._scrollDown(e);
		else if (e.target.className.indexOf("Scrollbar-Track") > -1)
			self._scrollTrack(e);
		else if (e.target.className.indexOf("Scrollbar-Handle") > -1)
			self._scrollHandle(e);
		self._tempTarget = e.target;
		self._selectFunc = document.onselectstart;
		document.onselectstart = function () {
			return false;
		};
		self.eventHandler(e.target, "mousedown");
		self._addEvent(document, "mouseup", self._stopScroll, false);
		return false;
	};
	this._scrollbarDrag = function (e) {
		e = e ? e : event;
		var t = parseInt(self._yHandle.style.top);
		var v = e.clientY + document.body.scrollTop - self._trackTop;
		with (self._yHandle.style) {
			if (v >= self._trackHeight - self._handleHeight + self._grabPoint)
				top = self._trackHeight - self._handleHeight +"px";
			else if (v <= self._grabPoint)
				top = "0px";
			else
				top = v - self._grabPoint +"px";
			self._y = parseInt(top);
		}
		self._moveContent();
	};
	this._scrollbarWheel = function (e) {
		e = e ? e : event;
		var dir = 0;
		if (e.wheelDelta >= 120)
			dir = -1;
		if (e.wheelDelta <= -120)
			dir = 1;
		self.scrollBy(0, dir * 20);
		e.returnValue = false;
	};
	this._startScroll = function (x, y) {
		this._tempDistX = x;
		this._tempDistY = y;
		this._scrollTimer = window.setInterval(function () {
			self.scrollBy(self._tempDistX, self._tempDistY); }, 40);
		};
		this._stopScroll = function () {
			self._removeEvent(document, "mousemove", self._scrollbarDrag, false);
			self._removeEvent(document, "mouseup", self._stopScroll, false);
			if (self._selectFunc)
				document.onselectstart = self._selectFunc;
			else
				document.onselectstart = function () { return true; };
			if (self._scrollTimer)
				window.clearInterval(self._scrollTimer);
			self.eventHandler (self._tempTarget, "mouseup");
		};
		this._scrollUp = function (e) {
			this._startScroll(0, -this._scrollDist);
	};
	this._scrollDown = function (e) {
		this._startScroll(0, this._scrollDist);
	};
	this._scrollTrack = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._scroll(0, curY - this._trackTop - this._handleHeight/2);
	};
	this._scrollHandle = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._grabPoint = curY - findOffsetTop(this._yHandle);
		this._addEvent(document, "mousemove", this._scrollbarDrag, false);
	};
	this._scroll = function (x, y) {
		if (y > this._trackHeight - this._handleHeight) y = this._trackHeight - this._handleHeight;
		if (y < 0) y = 0;this._yHandle.style.top = y +"px";
		this._y = y;
		this._moveContent();
	};
	this._moveContent = function () {
		this._src.scrollTo(0, Math.round(this._y * this._ratio));
	};
	this.scrollBy = function (x, y) {
		this._scroll(0, (-this._src._y + y)/this._ratio);
	};
	this.scrollTo = function (x, y) {
		this._scroll(0, y/this._ratio);
	};
	this.swapContent = function (o, w, h) {
		this._removeEvent(this._src.content, "mousewheel", this._scrollbarWheel, false);
		this._src.swapContent(o, w, h);
		this.reset();
	};
	this.reset();
};
