$(function (){
//Fix Ajax
    $.ajaxSetup
        ({
        xhr: function()
            {
            if ($.browser.msie)
                {
                return new ActiveXObject("Microsoft.XMLHTTP");
                }
            else
                {
                return new XMLHttpRequest();
                }
            }
        });
//End Fix Ajax

//Logo script
$('.logo').crossSlide({
  sleep: 4,
  fade: 1
}, [
  { src: 'images/mainlogo.png' },
  { src: 'images/mainlogo2.png' },
  { src: 'images/mainlogo3.png' },
  { src: 'images/mainlogo4.png' },
  { src: 'images/mainlogo5.png' },
  { src: 'images/mainlogo6.png' },
  { src: 'images/mainlogo9.png' },
  { src: 'images/mainlogo7.png' },
  { src: 'images/mainlogo8.png' },
  { src: 'images/mainlogo10.png' }
]);
//End Logo script

//Modules + showhide
function load_module(page){
page=page.split("#!");

if(page[1]!=undefined)page=page[1].split("#");else page[0]="";

if(page[0]=="" || page[0]==undefined || page[0]=="home"){

$("#module1").hide();
$("#module2").show();
$("#module2").empty().html('<img src="images/loading.gif" alt="" />');
$("#module2").load("mods/home.php");
}
else{
$("#module1").show();
$("#module2").hide();
$(".content_table #module_content").empty().html('<img src="images/loading.gif" alt="" />');
$(".content_table #module_content").load("mods/"+page[0]+".php");
$(".content_table .title").html(page[0]);
if(page[0] !="search" && page[1] != undefined)$(".content_table .title").append(" -> "+page[1]);
}
}

load_module(window.location.href);
$(window).bind('hashchange', function () {
 load_module(location.hash);
});

$('a.showhide').click(function() {
$(this).next().toggle();
return false;
}); 
//End of Modules + showhide

//Top Rank function
function select_rank(rank){
$("#top20rank").empty().html('<img src="images/loading.gif" alt="" />');
var what="";

if(rank==1)what="top20_alltime";
else if(rank==2)what="top20_guilds";
else if(rank==3)what="top20_resets";
else if(rank==4)what="top20_gens";
else if(rank==5)what="top20_pk";
else if(rank==6)what="top20_zen";
else if(rank==7)what="top20_rated";
else if(rank==8)what="top20_dsq";

$("#top20rank").load("mods/rankings/"+what+".php");
}

select_rank($("#top20select").val());

$("#top20select").change(function(){
select_rank($(this).val());
});
//End of Top Rank function

//Login function
$('#login1,#login2').submit(function() {
	var id="."+this.id+"_info";
	var str=$(this).serialize();
   $.ajax({
        url: "mods/login.php",
        type: "POST",
        data: str,
        success: function(data){
$(id).hide().html(data).fadeIn("fast");
        }
    });
  return false;

});
//End of Login function

//Logout function
$('#logout1,#logout2').submit(function() {
	var id="."+this.id+"_info";
$.get("mods/logout.php", function(data){
$(id).html(data);
});
return false;
});
//End of Logout function

//Language function
$('.language').click(function() {
$.post('mods/change_lang.php',{ ChangeLanguage: 'ChangeLanguage', Language: $(this).attr("id") }, function(data){
window.location.reload();
});

}); 
//End of Language function

//Search function
$('#search_form').submit(function() {
var name=$("#search_form input[name='namesearch']").val();
$("input[name='namesearch']").val('');
window.location.href="#!search#"+name;
return false;
});
//End of Search function

//admincode function
$('#admin_code').submit(function() {
$.post('mods/admin_code.php',{ admin_code: $("input[name='admin_code']").val() }, function(data){
$("#admin_code_info").hide().html(data).fadeIn("fast");
});
return false;
});
//End of Logout function

});
