function convertToAjax(scope) {
$j("#topbar").hide();
first=true;
ajaxallowed=true;

if (scope=='#mainContainer') {
	newpath=page_loading;
	if (newpath!=null) {
		newpath=newpath.replace("http://www.genleo.net/","");
		map();
		}
	if (newpath==null||newpath.substring(0,4)!='main') {

	if (document.getElementById('ajaxNavigationPanel')!=null) if (document.getElementById('ajaxNavigationPanel').value=='true') $j('#navigationContainer').load('bars/main_menu_in.php',"",function () {
	convertToAjax('#navigationContainer');
	});

	if (document.getElementById('ajaxUserPanel')!=null) if (document.getElementById('ajaxUserPanel').value=='true') $j('#userContainer').load('bars/user_panel_in.php',"",function() {
	convertToAjax('#userContainer');
	});
	
	/*	Code Added for Top Navigation Bar	*/
	if (document.getElementById('horz_navigation')!=null) if (document.getElementById('horz_navigation').value=='true') $j('#navigationContainerTop').load('bars/top_navigation_above.php',"",function () {
	convertToAjax('#navigationContainerTop');
	});
	
	if (document.getElementById('horz_navigation')!=null) if (document.getElementById('horz_navigation').value=='true') $j('#navigationContainerBelow').load('bars/top_navigation_below.php',"",function () {
	convertToAjax('#navigationContainerBelow');
	});
	/*	Code Added for Top Navigation Bar Ends	*/
	
	}
}

$j("a.mainAJAX",scope).click( function() {
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/,'');
	if (ajaxallowed) {
		if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		oldpath=newpath;
		$j.historyLoad(hash);
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}

	return false;
});



// BUTTONS START
$j("a.button1",scope).click( function() {
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/,'');
	if (ajaxallowed) {
		if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		oldpath=newpath;
		$j.historyLoad(hash);
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}

	return false;
});

$j("a.button2",scope).click( function() {
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/,'');
	if (ajaxallowed) {
		if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		oldpath=newpath;
		$j.historyLoad(hash);
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}

	return false;
});

$j("a.button1current",scope).click( function() {
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/,'');
	if (ajaxallowed) {
		if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		oldpath=newpath;
		$j.historyLoad(hash);
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}

	return false;
});

$j("a.button2current",scope).click( function() {
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/,'');
	if (ajaxallowed) {
		if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		oldpath=newpath;
		$j.historyLoad(hash);
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}

	return false;
});


// BUTTONS END



var options = { 
    target:     '#mainContainer', 
    success:    function() { 
        convertToAjax("#mainContainer"); 
    }

};

$j("a.noDisplayAjax",scope).click(function() {
	$.get(this.getAttribute("href"));
	return false;
});

$j("form.mainAJAX",scope).ajaxForm(options);

$j("form.mainAJAX",scope).submit(function() {
$j("#topbar").show();
if (this.action!=null) page_loading=this.action.value;
else page_loading=null;
});

$j("form.nodisplayAJAX",scope).ajaxForm();
 
}


function pageload(hash) {
		// hash doesnt contain the first # character.
		if(hash) {
			// restore ajax loaded state
			$j("#mainContainer").load(hash,"",function() {
			convertToAjax("#mainContainer");
// Let's update the cool new scrollbar after page is loaded	
var myDiv=document.getElementById("mycustomscroll");
if(myDiv!=null&&myDiv.scrollUpdate) myDiv.scrollUpdate(); 
			
			});

		} else {
		}
	}



$j(document).ready(function(){
$j("#topbar").hide();
$j.historyInit(pageload);
$j("a.mainAJAX").click(function(){
	var hash = this.getAttribute("href");
	hash = hash.replace(/^.*#/, '');
	if (ajaxallowed) {
	   if (chatintervalid!=-1) clearInterval(chatintervalid);
		chatintervalid=-1;
		$j("#topbar").show();
		$j.historyLoad(hash);
		oldpath=newpath;
		page_loading=this.getAttribute("href");
		ajaxallowed=false;
		first=true;
		}
	return false;
   });

var options = { 
    target:     '#mainContainer', 
    success:    function() { 
        convertToAjax("#mainContainer"); 
    } 
}; 


$j("a.noDisplayAjax").click(function() {
	$j.get(this.getAttribute("href"));
	return false;
});

$j("form.mainAJAX").ajaxForm(options);
$j("form.mainAJAX").submit(function() {
$j("#topbar").show();
if (this.action!=null) page_loading=this.action.value;
else page_loading=null;
});

$j("form.nodisplayAJAX").ajaxForm();




if ($j('#toggleOnlineContainerButton').text() != 'Show') {
// Disabled the below code because it would open the Online Container even though the user wants it hidden.
setInterval("online_caller()",120000);
}
setInterval("mini_chat_caller()",30000);
 
});


function mainmenu_caller() 
{
  $j('#navigationContainer').load('bars/main_menu_in.php','',function() 
    {
      convertToAjax('#navigationContainer');
    }
  );
}

function userinfo_caller() 
{
  $j('#userContainer').load('bars/user_panel_in.php','',function() 
    {
      convertToAjax('#userContainer');
    }
  );
}

function online_caller() {
	if ($j('#toggleOnlineContainerButton').text() == "Hide") {
        $j('#onlineContainer').load('bars/players_online_in.php','',function() {
	   convertToAjax('#onlineContainer');
	   });
	}
}

function mini_chat_caller() {
	if ($j('#toggleMiniChatButton').text() == "Hide") {
		$j('#miniChatContainer').load('bars/mini_chat_in.php','',function() {
			convertToAjax('#miniChatContainer');
			});
	}
}

// Functions added for Chat Bar ##

function mini_friends_caller() {
		$j('#onlineFriends').load('bars/friends_online_in.php','',function() {
			convertToAjax('#onlineFriends');
			});
}

function empire_chat_caller() { 
		$j('#show_empire_chat').load('mainchat.php?channel=chat_lines_clan_chat','',function() {
			convertToAjax('#show_empire_chat');
			});
}

function staff_chat_caller() { 
		$j('#show_staff_chat').load('mainchat.php?channel=chat_lines_staff_chat','',function() {
			convertToAjax('#show_staff_chat');
			});
}

function main_chat_caller() { 
		$j('#show_main_chat').load('mainchat.php','',function() {
			convertToAjax('#show_main_chat');
			});
}

function chat_alerts_caller() { 
		$j('#chat_alerts').load('chat/chat_alerts.php','',function() { 
			convertToAjax('#chat_alerts');
			});
}

// Chat Bar Fucntions End ##


function load_image_resize (img, max_height, max_width) {
		if (img.height > max_height)
			img.height= max_height;
		if (img.width > max_width)
			img.width= max_width;
}

function toggleOnlinePlayersBar () {
	var button=	$j('#toggleOnlineContainerButton');
	if (button.text() == "Hide") {
		button.text("Show");
		setInterval("online_caller()",9999999);
		$j('#onlineContainer').hide("slow");
		clearInterval("online_caller()");
	} else {
		button.text("Hide");
		setInterval("online_caller()",120000);
		$j('#onlineContainer').show("slow");
		online_caller();
	}
}

function toggleMiniChatBar () {
	var button=	$j('#toggleMiniChatButton');
	if (button.text() == "Hide") {
		button.text("Show");
		$j('#miniChatContainer').hide("slow");
	} else {
		button.text("Hide");
		$j('#miniChatContainer').show("slow");
		online_caller();
	}
	
}


