/**
 * Main Game server Manager class
 *
 * @author Alex Greenland
 */
var gsc = {};

var gscMain = function(){

    var updateTimer = null;

	var initialised = false;


	function pageload(hash) {
		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
//			$("#load").load(hash + ".html");
		} else {
			// start page
//			$("#load").empty();
		}
	}

	
	$.historyInit(pageload);
    
    $.ajaxSetup({
        type: "POST"
    });
    
    
    $("#errordialog").dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        buttons: {
            'Ok': function(){
                $(this).dialog('close');
            }
        },
        width: 500
    });
    
    $(document).ajaxError(function(event, request, settings){
        $('#errortext').html('An ajax error occured attempting to perform the operation.');
        $("#errordialog").dialog('open');
    });
    
    
    function getDomain(){
        return 'http://' + document.domain;
    }
    
    function showRconDialog(serverId, clearDialog){
        if (clearDialog) {
            $('#txtDescription').val('');
            $('#txtCommand').val('');
            $('#txtid').val('');
        }
        $('#newrcon').dialog('open');
    }
    
    function doInitAdmin(){
        $('#ctabs').tabs({
            fx: {
                opacity: 'toggle',
                duration: 'fast'
            }
        });
        
        $('#userstree').treeview({
            url: '/admin/getUserNode'
        })
    }
    
    function doInitAdminUserPage(){
        $('#utabs').tabs({
            fx: {
                opacity: 'toggle',
                duration: 'fast'
            }
        });
        
        $('#adminName').ajaxForm(function(data){
        });
        $('#adminPassword').ajaxForm(function(data){
        });
        $('#adminEmail').ajaxForm(function(data){
        });
        $('#adminMaxServers').ajaxForm(function(data){
        });
    }
    
	function destroyHomePage() {
		if (typeof $('#messageplayerdialog').destroy !== 'undefined') {
			$('#messageplayerdialog').destroy();
		}
	}
	
    function doInitInHomePage(){
    	if (initialised) {
			destroyHomePage();	
		}

		if ($('#datepicker')) {
			$('#datepicker').datepicker({
				onClose: function(dateText, inst) {
			   		if (dateText !== '') {
						dateText = dateText.replace(/\//g,'-');
						gsc.Main.updateGraph(gsc.controller, gsc.serverId, dateText);
					}
			   	}
			});			
		}

							
/*        $("div.panel_button").click(function(){
            $("div#panel").animate({
                height: "250px"
            }).animate({
                height: "200px"
            }, "fast");
            $("div.panel_button").toggle();
            
        });
        
        $("div#hide_button").click(function(){
            $("div#panel").animate({
                height: "0px"
            }, "fast");
        });
 */       
        if ($('#startupoptions')) {
            $('#startupoptions').ajaxForm(function(data){
            });
        }
        
        if ($('#rtabs')) {
            $('#rtabs').tabs({
                fx: {
                    opacity: 'toggle',
                    duration: 'fast'
                }
            });
        }
        
        if ($('#ctabs')) {
            $('#ctabs').tabs({
                fx: {
                    opacity: 'toggle',
                    duration: 'fast'
                }
            });
        }
        
        if ($('#pbtabs')) {
            $('#pbtabs').tabs({
                fx: {
                    opacity: 'toggle',
                    duration: 'fast'
                }
            });
        }
        
        if ($('#rconcommand')) {
            $('#rconcommand').autocomplete(getDomain() + '/' + gsc.controller + '/rconlist/' + gsc.serverId, {
                width: 260,
                selectFirst: false,
                type: 'POST'
            });
        }
        
        if ($('#newrconform')) {
            $('#newrconform').validate({
                messages: {
                    txtDescription: '',
                    txtCommand: ''
                }
            });
        }
        
        if ($('#addServerForm')) {
            $('#addServerForm').validate({
                messages: {
                    servername: '',
                    rconpassword: '',
                    ip: '',
                    port: ''
                }
            });
        }
        
        if ($('#newfileform')) {
            $('#newfileform').validate({
                messages: {
                    txtFilename: ''
                }
            });
        }
        
        if ($('#newfile')) {
            $('#newfile').dialog({
                autoOpen: false,
                resizable: false,
                width: 350,
                buttons: {
                    'Create': function(){
                        if ($('#newfileform').valid()) {
                        
                            var data = $(this).data('params');
                            
                            $('#configfilescontainer').load(getDomain() + '/' + data.gameType + '/saveNewFile/' + data.serverId, {
                                fileName: $('#txtFilename').val()
                            }, function(){
                                gsc.Main.loadFile(data.serverId, data.gameType, $('#txtFilename').val());
                            });
                            $(this).dialog('close');
                        }
                    },
                    'Cancel': function(){
                        $(this).dialog('close');
                    }
                }
            });
        }
        
        if ($('#messageplayerdialog')) {
            $('#messageplayerdialog').dialog({
                autoOpen: false,
                resizable: false,
                width: 500,
                buttons: {
                    'Send': function(){
                        $.blockUI({
                            message: '<h1><img src="/img/ajax.gif" /> Sending Message ...</h1>'
                        });
                        var data = $(this).data('params');
                        
                        $.post(getDomain() + '/' + data.gameType + '/sendMessageToPlayer/', {
                            playerId: data.playerId,
                            serverId: data.serverId,
                            message: $('#message').val()
                        }, function(data){
                        
                        });
                        $(this).dialog('close');
                    },
                    'Cancel': function(){
                        $(this).dialog('close');
                    }
                }
            });
        }

        if (gsc.AntiCheat) {
            gsc.AntiCheat.initAntiCheat();
        }
        
        if ($("#newrcon")) {
            $("#newrcon").dialog({
                autoOpen: false,
                resizable: false,
                width: 500,
                buttons: {
                    'Save': function(){
                        if ($('#newrconform').valid()) {
                            var description = $('#txtDescription').val();
                            var command = $('#txtCommand').val();
                            var commandId = $('#txtId').val();
                            var show = $('#cbShow').val();
                            
                            if (commandId != '') {
                                $.blockUI({
                                    message: '<h1><img src="/img/ajax.gif" /> Saving Command ...</h1>'
                                });
                            }
                            else {
                                $.blockUI({
                                    message: '<h1><img src="/img/ajax.gif" /> Adding Command ...</h1>'
                                });
                            }
                            
                            $('#quick').load(getDomain() + '/' + gsc.controller + '/addQuickRcon/' + gsc.serverId + '/', {
                                command: command,
                                description: description,
                                show: show,
                                id: commandId
                            }, function(data){
                            });
                            $('#newrcon').dialog('close');
                            
                        }
                        
                    },
                    'Cancel': function(){
                        $(this).dialog("close");
                    }
                }
            });
        }
		
        if ($('.mapselector')) {
			$(".mapselector").multiselect({
				height: 300,
				width: 500
			});
		}

		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
			return false;
		});
		
		initialised = true;		
    }
    
    if ($.unblockUI) {
        $().ajaxStop($.unblockUI);
    }
    
    return {
  
    
        messagePlayer: function(serverId, playerId, gameType){
            $('#message').val('');
            
            $('#messageplayerdialog').data('params', {
                serverId: serverId,
                playerId: playerId,
                gameType: gameType
            });
            $('#messageplayerdialog').dialog('open');
        },
        
        kickPlayer: function(serverId, playerId){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Kicking Player...</h1>'
            });
            $.get(getDomain() + '/' + gsc.controller + '/kickplayer/' + serverId + '/' + playerId, {}, function(data){
                $('#content').html(data);
                doInitInHomePage();
            });
        },
        
        banPlayer: function(serverId, playerId){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Banning Player...</h1>'
            });
            $.get(getDomain() + '/' + gsc.controller + '/banplayer/' + serverId + '/' + playerId, {}, function(data){
                $('#content').html(data);
                doInitInHomePage();
            });
        },
        
        startServer: function(serverId,gameType,action){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Starting Server...</h1>'
            });
			if (action !== 'index') {
				controller = 'home';
			} else {
				controller = gameType;
			}
			
            $.get(getDomain() + '/'+controller+'/startserver/' + serverId + '/' + action, {}, function(data){
                $('#content').html(data);
                doInitInHomePage();
            });
            
            
        },
        
        stopServer: function(serverId,gameType,action){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Stopping Server...</h1>'
            });
			if (action !== 'index') {
				controller = 'home';
			} else {
				controller = gameType;
			}			
            $.get(getDomain() + '/'+controller+'/stopserver/' + serverId + '/' + action, {}, function(data){
                $('#content').html(data);
                doInitInHomePage();
            });
        },
        
        refreshServer: function(serverId, gameType){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Refreshing Server...</h1>'
            });
            $('#content').load(getDomain() + '/' + gameType + '/index/' + serverId , {}, function(){
                doInitInHomePage();
            });
        },
        
        setrefreshTime: function(serverId, gameType){
            var interval = $('#serverRefreshInterval').val();
            if (interval == 0) {
                $('#serverdetails').stopTime();
            }
            else {
                $('#serverdetails').everyTime(interval + 's', function(){
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Refreshing Server...</h1>'
                    });
                    $('#serverdetails').load(getDomain() + '/' + gameType + '/refreshServer/' + serverId, {}, function(){
                        $('#serverRefreshInterval').val(interval);
                        doInitInHomePage();
                    });
                });
            }
        },
        
		addMod : function(serverId, gameType) {
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Adding Mod ...</h1>'
            });			
            $('#content').load(getDomain() + '/' + gameType + '/addMod', {
            	serverId: serverId,
				modId: $("input[@name='mod']:checked").val()
			});

		},
		
        addServer: function(){
            if ($('#addServerForm').valid()) {
            
                var gameCode = $('#gamename').val();
                
                $.blockUI({
                    message: '<h1><img src="/img/ajax.gif" /> Adding Server ...</h1>'
                });
                
                $('#content').load(getDomain() + '/' + gameCode + '/addServer', {
                    gameid: $('#gameid').val(),
                    servername: $('#servername').val(),
                    serveradmin: $('#serveradmin').val(),
                    adminemail: $('#adminemail').val(),
                    website: $('#website').val(),
                    serveradmin: $('#location').val(),
                    motd: $('#motd').val(),
                    rconpassword: $('#rconpassword').val(),
                    privatepassword: $('#privatepassword').val(),
                    serverpassword: $('#serverpassword').val(),
                    slots: $('#slots').val(),
                    privateslots: $('#privateslots').val(),
                    map: $('#map').val(),
                    servertype: $('#servertype').val(),
                    ip: $('#ip').val(),
                    port: $('#port').val(),
                    location: $('#location').val(),
                    anticheat: $('#anticheat').val(),
                    baseconfig: $('#baseconfig').val()
                
                }, function(data){
                    $('#menu').load(getDomain() + '/' + gameCode + '/getMenu')
                    doInitInHomePage();
                });
            }
        },
        
        deleteServer: function(serverId,gameType){
            jConfirm('Are you sure you wish to delete this server?', 'Delete Server', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Deleting Server ...</h1>'
                    });
                    $('#content').load(getDomain() + '/' + gameType + '/doDelete/' + serverId, {}, function(){
                        $('#menu').load(getDomain() + '/' + gameType + '/getMenu')
                        $('#ctabs').tabs({
                            fx: {
                                opacity: 'toggle'
                            }
                        });
                    });
                }
            });
        },
        
        saveStartup: function(){
            $('#startupcontainer').block({
                message: '<h2><img src="/img/ajax.gif" /> ...</h2>'
            });
            
            $('#startupoptions').ajaxSubmit({
                success: function(){
                    $('#startupcontainer').unblock();
                }
            });
        },
        
        confirmQuickDelete: function(serverId, commandId){
            jConfirm('Are you sure you wish to delete this command?', 'Delete Quick Command', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Deleting Command ...</h1>'
                    });
                    $('#quick').load(getDomain() + '/' + gsc.controller + '/deleteQuickRcon/' + serverId + '/' + commandId);
                }
            });
        },
        
        loadContent: function(element, url){
        
            if ($('#serverdetails')) {
                $('#serverdetails').stopTime();
            }
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Loading ...</h1>'
            });
            
            $('#' + element).load(getDomain() + url, {}, function(){
                doInitInHomePage();
            });
        },
        
        loadElement: function(element, url, blockMessage){
        
            if (typeof blockMessage != 'undefined') {
                $('#' + element).block({
                    message: '<h2><img src="/img/ajax.gif" /> ' + blockMessage + ' </h2>'
                });
            }
            
            $('#' + element).load(getDomain() + url, {}, function(){
                if (typeof blockMessage != 'undefined') {
                    $('#' + element).unblock();
                }
            });
        },
        
        doRconCommand: function(serverId, controller){
            var rconCommand = $('#rconcommand').val();
            
            $('#rconresultcontainer').block({
                message: '<h2><img src="/img/ajax.gif" /> Sending ...</h2>'
            });
            
            $.post(getDomain() + '/' + controller + '/doRconCommand/' + serverId, {
                command: rconCommand
            }, function(data){
                var response = data || "Server did not provide any response";
                
                $('#rconresult').val(response);
                
                $('#rconresultcontainer').unblock();
            });
        },
        
        clearRconCommand: function(){
            $('#rconcommand').val('');
            $('#rconresult').val('');
        },
        
        doQuickcommand: function(serverId, commandId){
            $('#rconresultcontainer').block({
                message: '<h2><img src="/img/ajax.gif" /> Sending ...</h2>'
            });
            
            $.post(getDomain() + '/' + gsc.controller + '/doQuickRconCommand/' + serverId + '/' + commandId, {}, function(data){
                $('#rconresultcontainer').unblock();
                if (data) {
                    $('#rconresult').val(data);
                }
            });
        },
        
        newRcon: function(serverId, clearDialog){
            showRconDialog(serverId, clearDialog);
        },
        
        editRcon: function(serverId, commandId){
            $.getJSON(getDomain() + '/' + gsc.controller + '/getQuickRconCommand/' + serverId + '/' + commandId, {}, function(data){
                if (data) {
                    $('#txtDescription').val(data.description);
                    $('#txtCommand').val(data.command);
                    $('#txtId').val(data.id);
                    $('#cbShow').attr('checked', data.showresult == 1 ? true : false);
                    showRconDialog(data.server_id, false);
                }
            });
            
        },
        
        recoverPassword: function(){
            $('#forgotdialog').dialog('open');
        },
        
        changeName: function(){
            var first = $('#name_first').val();
            var last = $('#name_last').val();
            
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Changing Name ...</h1>'
            });
            
            $('#content').load(getDomain() + '/home/changeName', {
                name_first: first,
                name_last: last
            }, function(){
                doInitInHomePage();
            });
            
        },
        
        initHomepage: function(){
            $("#forgotdialog").dialog({
                autoOpen: false,
                resizable: false,
                modal: true,
                buttons: {
                    'Ok': function(){
                        $.post(getDomain() + '/users/sendResetEmail', {
                            email: 'agreenland@cromwells.co.uk'
                        }, function(data){
                            if (data) {
                            }
                        });
                        $(this).dialog('close');
                    }
                },
                width: 500
            });
            
            $('#hptabs').tabs({
                fx: {
                    opacity: 'toggle'
                }
            });
            $("#slider").easySlider({
                auto: false,
                continuous: true
            });
            
            $('#UserUsername').focus(function(){
                if (this.value == 'Username') {
                    this.value = '';
                }
                
            });
            
            $('#UserPassword').focus(function(){
                if (this.value == '******') {
                    this.value = '';
                }
                
            });
        },
        
        initInHomepage: function(){
            doInitInHomePage();
        },
        
        initAdminPage: function(){
            doInitAdmin();
        },
        
        initStaticPage: function(){
            $('#stabs').tabs({
                fx: {
                    opacity: 'toggle'
                }
            });
            if ($('#staticserverblock')) {
                $('#staticserverblock').easySlider({
                    vertical: true,
                    continuous: true,
                    controlsShow: false,
                    auto: true
                });
            }
        },
        
        showAddServer: function(){
            $.blockUI({
                message: '<h1><img src="/img/ajax.gif" /> Loading ...</h1>'
            });
            
            $('#content').load(getDomain() + '/home/add', {}, function(){
                doInitInHomePage();
            });
            
        },
        
        setAddForm: function(){
            var state = $('#servertype').val();
            
            if (state == 0) {
                $('#ip').attr('disabled', true);
                $('#port').attr('disabled', true);
                
                $('#serveradmin').attr('disabled', false);
                $('#adminemail').attr('disabled', false);
                $('#website').attr('disabled', false);
                $('#location').attr('disabled', false);
                $('#motd').attr('disabled', false);
                $('#privatepassword').attr('disabled', false);
                $('#serverpassword').attr('disabled', false);
                $('#slots').attr('disabled', false);
                $('#privateslots').attr('disabled', false);
                $('#map').attr('disabled', false);
                $('#baseconfig').attr('disabled', false);
                
            }
            else {
                $('#ip').attr('disabled', false);
                $('#port').attr('disabled', false);
                
                $('#serveradmin').attr('disabled', true);
                $('#adminemail').attr('disabled', true);
                $('#website').attr('disabled', true);
                $('#location').attr('disabled', true);
                $('#motd').attr('disabled', true);
                $('#privatepassword').attr('disabled', true);
                $('#serverpassword').attr('disabled', true);
                $('#slots').attr('disabled', true);
                $('#privateslots').attr('disabled', true);
                $('#map').attr('disabled', true);
                $('#baseconfig').attr('disabled', true);
                
            }
        },
        
        getAddForm: function(){
            var gameType = $('#gametype').val();
            
            if (gameType != '') {
                var temp = gameType.split('|');
                var gameType = temp[0];
                var gameId = temp[1];
                
                $.blockUI({
                    message: '<h1><img src="/img/ajax.gif" /> Please Wait ...</h1>'
                });
                $('.collba').load(getDomain() + '/' + gameType + '/getAddForm/' + gameId)
            }
        },
        
        switchmap: function(serverId, gameType){
        
            jConfirm('Are you sure you wish to switch the Map?', 'Switch Map', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Switching Map ...</h1>'
                    });
                    
                    var mapName = $('#map').val();
                    $('#content').load(getDomain() + '/' + gameType + '/switchMap/' + serverId, {
                        mapName: mapName
                    }, function(){
                        doInitInHomePage();
                    });
                }
            });
        },
        
        setGameType: function(serverId, gameType){
            jConfirm('Are you sure you wish to switch the gametype?', 'Switch Game Type', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Switching Gametype ...</h1>'
                    });
                    
                    var newGameType = $('#gametype').val();
                    $('#content').load(getDomain() + '/' + gameType + '/switchGameType/' + serverId + '/' + newGameType, {}, function(){
                        doInitInHomePage();
                    });
                }
            });
        },
        
        fastRestartMap: function(gameType, serverId){
            jConfirm('Are you sure you wish to fast restart the Map?', 'Restart Map', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Restarting Map ...</h1>'
                    });
                    
                    $('#content').load(getDomain() + '/' + gameType + '/fastRestart/' + serverId, {}, function(){
                        doInitInHomePage();
                    });
                }
            });
            
        },
        
        restartMap: function(serverId, gameType){
            jConfirm('Are you sure you wish to restart the Map?', 'Restart Map', function(r){
                if (r) {
                    $.blockUI({
                        message: '<h1><img src="/img/ajax.gif" /> Restarting Map ...</h1>'
                    });
                    
                    var mapName = $('#map').val();
                    $('#content').load(getDomain() + '/' + gameType + '/restartMap/' + serverId + '/' + mapName, {}, function(){
                        doInitInHomePage();
                    });
                }
            });
            
        },
        
        loadFile: function(serverId, gameType, fileName){
        
            $('#configeditorcontainer').block({
                message: '<h3><img src="/img/ajax.gif" /> Loading </h3>'
            });
            
            $.post(getDomain() + '/' + gameType + '/getConfigFile/' + serverId, {
                fileName: fileName
            }, function(data){
                $('#fileeditor').removeAttr('disabled');
                $('#fileeditor').val(data);
                $('#configsave').removeClass('savebuttonoff');
                $('#clearconfig').removeClass('clearconfigoff');
                $('.configfiles li').removeClass('bold2');
                var id = fileName.replace('.', '')
                $('#' + id).attr('class', 'bold2');
                $('#configeditorcontainer').unblock();
            });
        },
        
        saveConfigFile: function(gameType, serverId){
            if ($('#configsave').hasClass('savebuttonoff') === false) {
                var elements = $('.configfiles li');
                var fileName = '';
                elements.each(function(i){
                    if ($(this).hasClass('bold2')) {
                        fileName = $(this).attr('filename');
                    }
                });
                
                if (fileName != '') {
                    $('#configeditorcontainer').block({
                        message: '<h3><img src="/img/ajax.gif" /> Saving </h3>'
                    });
                    $.post(getDomain() + '/' + gameType + '/saveFile/' + serverId, {
                        fileName: fileName,
                        fileData: $('#fileeditor').val()
                    }, function(data){
                        $('#configeditorcontainer').unblock();
                    })
                }
                else {
                    $('#errortext').html('An error has occured. Please login again and retry the operation');
                    $('#errordialog').dialog('open');
                }
                
            }
        },
        
        clearConfigEditor: function(){
            if ($('#clearconfig').hasClass('clearconfigoff') === false) {
                $('.configfiles li').removeClass('bold2');
                $('#fileeditor').val('');
                $('#fileeditor').attr('disabled', true);
                $('#clearconfig').addClass('clearconfigoff');
                $('#configsave').addClass('savebuttonoff');
                $('#fileeditor').val('');
            }
        },
        
        newConfigFile: function(gameType, serverId){
            $('#newfile').data('params', {
                serverId: serverId,
                gameType: gameType
            });
            $('#txtFilename').val('');
            $('#newfile').dialog('open');
        },
        
        deleteConfigFile: function(gameType, serverId, fileName){
            jConfirm('Are you sure you wish to delete this config file?', 'Delete Config File', function(r){
                if (r) {
                    $('#configfilescontainer').block({
                        message: '<h3><img src="/img/ajax.gif" /> Deleting </h3>'
                    });
                    $('#configfilescontainer').load(getDomain() + '/' + gameType + '/deleteFile/' + serverId, {
                        fileName: fileName
                    }, function(data){
                        $('#configfilescontainer').unblock();
                    });
                    
                    
                }
            });
        },
        
        doAcCommand: function(gameType, serverId, command, element){
            $('#' + element).block({
                message: '<h3><img src="/img/ajax.gif" /> Loading ... </h3>'
            });
            $('#' + element).load(getDomain() + '/' + gameType + '/doACCommand/' + serverId, {
                command: command
            }, function(data){
            
            });
        },
        
        screenshotPlayer: function(serverId, playerId, gameType){
            $('#pbresult').load(getDomain() + '/' + gameType + '/doACCommand/' + serverId, {
                command: 'screenshotplayer',
                playerid: playerId
            }, function(data){
            });
        },
        
        changeOption: function(gameType, serverId, command, value){
            $('#basic').block({
                message: '<h3><img src="/img/ajax.gif" /> Loading ... </h3>'
            });
            $.post(getDomain() + '/' + gameType + '/' + command + '/' + serverId, {
                value: value
            }, function(data){
                $('#basic').unblock();
            });
        },
		
		stats : function(gameType,serverId,range) {

			$('#statscontent').load(getDomain() + '/'+gameType+'/stats/' + serverId, {}, function(data){
            	gsc.Main.updateGraph(gameType,serverId,range);
            });			
		},
		
		updateGraph : function(gameType,serverId,range) {
            if (typeof range == 'undefined') {
				range='week';
			}
			var offset = (new Date()).getTimezoneOffset();

			$.ajax({ url: getDomain() + '/'+gameType+'/getstats/' + serverId + '/' + range + '/'+ offset,
          		dataType: "json",
          		success: function(result) {				
					var thisgraph = new GSMGraph(result,{overview:true,zoom:true,mainGraph:'statsgraph',overviewGraph:'overview'},{},{});
					thisgraph.plot();
          		}
      		}); 			
		}
        
    };
};


$(document).ready(function(){
    gsc.Games = {};
	gsc.Main = new gscMain();
	if (typeof gscCod != 'undefined') {
		gsc.Games.CallofDuty = new gscCod();
	}
	
});
