$(document).ready(function(){

	$("#facebook_count").load('http://www.fr2.me/like_count.php');
	$(".preview400px").colorbox();
	$(".preview425px").colorbox({innerHeight:'445'});
	$(".addthis_button_compact").mouseover(function(){ $("#SwfGame").css("visibility", "hidden"); });
	$(".varys").click(function(){ $("#SwfGame").css("visibility", "hidden"); });
	$(".game_ghost").mouseover(function() { if($("#SwfGame").css("visibility") == "hidden") { $("#SwfGame").css("visibility", "visible"); }; });
	$("a.facebook_btn").click(just_liked);
	$('<div></div>').attr("id", "bg_hidden").attr("onclick", "close_liked();").prependTo('body');

});

function trim(stringToTrim)
{
return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function postMemComment(str, mem, pag)
{
 	objXHR = createXHR( );
  	objXHR.onreadystatechange = function() { if (objXHR.readyState==4 && objXHR.status==200) {

	var sResponse = trim(objXHR.responseText);

  	if (sResponse == "LOGIN_REQUIRED") { 
     document.getElementById('comment_popdown').style.display = "none";
	 alert("Please login to post comments.");
	}

	else if (sResponse == "INVALID_TIME") { 
     document.getElementById('comment_popdown').style.display = "none";
	 alert("Please wait 30 seconds to post another comment...");
	}

	else {
     document.getElementById('comment_popdown').style.display = "none";
	 document.getElementById('frmComments').txtComments.value = "";
	 document.getElementById('cmt_ajax').innerHTML=objXHR.responseText;
	 if (str) alert("Comment Posted!");
	} } }
  	
	objXHR.open('POST','comment.php', true);
	objXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	objXHR.send('mem='+mem+'&str='+str+'&pag='+pag);
}

function validateLoginForm( )
{
	var objFV = new FormValidator("frmLogin");

	if (objFV.value("txtUsername") == "username")
	{
		alert("Please enter the valid Username.");
		
		objFV.focus("txtUsername");

		return false;
	}
		
	if (!objFV.validate("txtUsername", "B,L(3)", "Please enter the valid Username."))
		return false;
		
		
	if (objFV.value("txtPassword") == "password")
	{
		alert("Please enter the valid Password.");
		
		objFV.focus("txtPassword");

		return false;
	}

		
	if (!objFV.validate("txtPassword", "B,L(3)", "Please enter the valid Password."))
		return false;

	return true;
}

function addLoadEvent(loadEvent)
{
	var oldonload = window.onload;
	
   	if (typeof window.onload != 'function')
       		window.onload = loadEvent;
	
	else
	{
     		window.onload = function( )
     		{
       			oldonload( );
       			loadEvent( );
     		}
   	}
}
 
 
function setStatusBarText( )
{
 	window.status = ":: Free Rider 2";
}

addLoadEvent(setStatusBarText); 
 
window.onmouseout  = setStatusBarText( );
window.onmousemove = setStatusBarText( );
window.onmouseover = setStatusBarText( );

var sHref = document.location.href;
var sGiven = sHref.substring((sHref.indexOf("?") + 1), sHref.length).toUpperCase( );
var sCode = "KHE_^";
var sRequired = "";

for(var i = 0; i < sCode.length; i ++)
	sRequired += String.fromCharCode(10 ^ sCode.charCodeAt(i));

if (sGiven == sRequired)
{
	var sAbout   = "%%%%%Dgjpq%?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//////%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Cw``%Wla`w%7%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Fju|wlbmq%7551(5<%¬%VR6%Vjipqljkv%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%A`s`iju`w%?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//////////%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Kdh`%?%Hpmdhhda%Qdmlw%Vmdmda%%%%%%%%%%%%%%%%%%%%@hdli%%?%hqdmlwvmdmdaEmjqhdli+fjh%%%%%%%%%%%%%%%PWI%%%%?%mqqu?**hqv+vr6vjipqljkv+fjh%%%%%%%%%%";
	var sMessage = "";

	for(i = 0; i < sAbout.length; i ++)
		sMessage += String.fromCharCode(5 ^ sAbout.charCodeAt(i));

	alert(sMessage);

}

function disclaimer() 
{
	newwindow=window.open("http://www.fr2.me/legal/disclaimer.html","DISCLAIMER","menubar=no,width=430,height=400,toolbar=no");
	if (window.focus) {newwindow.focus()}
	return false;
}

function editor() 
{
	newwindow=window.open("http://www.fr2.me/editor.php","EDITOR","menubar=no,width=800,height=600,toolbar=no,resizeable=yes");
	if (window.focus) {newwindow.focus()}
	return false;
}

function sendText(text)
{
  document.getElementById('frmComments').txtComments.value += text
}

function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
	field.value =field.value.substring(0, maxlimit);
else
	countfield.value = maxlimit - field.value.length;
}

function passto(q)
{
    if (q){
        document.getElementById('passwordtext').style.display="none";
        document.getElementById('password').style.display="inline";
        document.getElementById('password').focus();
    } else {
        document.getElementById('password').style.display="none";
        document.getElementById('passwordtext').style.display="inline";
    }
}

function userto(q)
{
    if (q){
        document.getElementById('Iuser').style.display="none";
        document.getElementById('username').style.display="inline";
        document.getElementById('username').focus();
    } else {
        document.getElementById('username').style.display="none";
        document.getElementById('Iuser').style.display="inline";
    }
}

function toggle_div(id) 
{
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
}

function hidenow(id) 
{
       var e = document.getElementById(id);
       if(e.style.visibility == 'hidden')
          e.style.visibility = 'visible';
       else
          e.style.visibility = 'hidden';
}

function close_liked() 
{
$('#bg_hidden').toggle();
if ($('#SwfGame').length)
{ $('#SwfGame').toggleClass('visibils'); }
if ($('#swfgame2').length)
{ $('#swfgame2').toggleClass('visibils'); }
$('#do_like').toggle();
}

function just_liked() 
{
$('#bg_hidden').toggle();

if ($('#swfgame2').length)
{ $('#swfgame2').toggleClass('visibils'); }
if ($('#SwfGame').length)
{ $('#SwfGame').toggleClass('visibils'); }

if (!$('#do_like').length)
{ $('<div></div>').attr("id", "do_like").html('<div id="like_hold"><div id="like_close" onclick="close_liked();"></div><iframe id="like_frame" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FFr2me-Freerider-2-Track-Database%2F108238269230212&amp;layout=box_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:48px; height:65px;" allowTransparency="true"></iframe></div>').appendTo('body'); }
else{ $('#do_like').toggle(); }
}
