<commit_before>Object.size = function (obj)
{
	var size = 0,
		key;
	for (key in obj)
	{
		if (obj.hasOwnProperty(key)) size++;
	}
	return size;
};

function roundNumber(num, dec)
{
	var result = String(Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec));
	if (result.indexOf('.') < 0)
	{
		result += '.';
	}
	while (result.length - result.indexOf('.') <= dec)
	{
		result += '0';
	}
	return result;
}

/**
* @constructor
*/
jQuery.fn.flash = function( color, duration )
{
		if( typeof this.data('flashing') =='undefined' )
		{
			this.data('flashing', false);
		}
		
		if( this.data('flashing') == true )
		{
			return;
		}
    var current = this.css( 'background-color' );

	this.data('flashing', true)
    this.animate( { backgroundColor: color }, duration / 2 );
    
    var $this = this;
    this.animate( { backgroundColor: current }, duration / 2, function() { $this.data('flashing', false); } );
}

jQuery.fn.fadeOutFlash = function( color, duration )
{
		if( typeof this.data('flashing') =='undefined' )
		{
			this.data('flashing', false);
		}
		
		if( this.data('flashing') == true )
		{
			return;
		}
    var current = this.css( 'background-color' );

	this.data('flashing', true)
    this.css( 'background-color', color )
    
    var $this = this;
    this.animate( { backgroundColor: current }, duration, function() { $this.data('flashing', false); } );
}

new function() {
		$.browser.eveIGB = false;
		if( navigator.appVersion.indexOf('EVE-IGB') != -1 )
		{
				$.browser.eveIGB = true;
		}
}();


function setCookie(name,value,days) {
		if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}
			
			

function CountUp(initDate,selector)
{
	this.beginDate = new Date(initDate);
	this.container = $(selector);
	this.calculate();
	this.timeout = null;
}			

CountUp.prototype.destroy = function()
{
	clearTimeout(this.timeout);
	this.container = null;
	delete this.beginDate;
}


CountUp.prototype.addLeadingZero = function (value)
{
	return value < 10 ? ('0' + value) : value;
}

CountUp.prototype.calculate = function ()
{
	if( this.container == null )
	{
		return;
	}

	var currDate = new Date();
	var prevDate = this.beginDate;
	
	dd = currDate - prevDate;
    this.days = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
    this.hours = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
    if( this.days < 2 )
    {
		this.minutes = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
		this.seconds = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
		
		this.seconds = this.addLeadingZero(this.seconds);
		this.minutes = this.addLeadingZero(this.minutes);
	}
	this.hours = this.addLeadingZero(this.hours);
	
	if( this.days == 0 )
	{
		this.container.text(this.hours + ":" + this.minutes + ":" + this.seconds);
	}
	else
	{
		this.container.text(this.days + "d " + this.hours + "h");
	}
	
	if( this.days < 2 )
	{
		var self = this;
		this.timeout = setTimeout(function ()
		{
			self.calculate();
		}, 1000);
	}
	delete currDate;
	currDate = null;
}
			

function pad(number, length)
{
	var str = '' + number;
	while (str.length < length)
	{
		str = '0' + str;
	}

	return str;
}

//first key is wh class, second is just unique for mag in the class
var magsLookup = {
	1: {
		0: "",
		1: "Forgotten Perimeter Coronation Platform",
		2: "Forgotten Perimeter Power Array"
	},
	2: {
		0: "",
		1: "Forgotten Perimeter Gateway",
		2: "Forgoten Perimeter Habitation Coils"
	},
	3: {
		0: "",
		1: "Forgotten Frontier Quarantine Outpost",
		2: "Forgotten Frontier Recursive Depot"
	},
	4: {
		0: "",
		1: "Forgotten Frontier Conversion Module",
		2: "Forgotten Frontier Evacuation Center"
	},
	5: {
		0: "",
		1: "Forgotten Core Data Field",
		2: "Forgotten Core Information Pen"
	},
	6: {
		0: "",
		1: "Forgotten Core Assembly Hall",
		2: "Forgotten Circuitry Disassembler"
	},
	7: {
		0: ""
	},
	8: {
		0: ""
	},
	9: {
		0: ""
	}
};

var radarsLookup = {
	1: {
		0: "",
		1: "Unsecured Perimeter Amplifier",
		2: "Unsecured Perimeter Information Center"
	},
	2: {
		0: "",
		1: "Unsecured Perimeter Comms Relay",
		2: "Unsecured Transponder Farm"
	},
	3: {
		0: "",
		1: "Unsecured Frontier Database",
		2: "Unsecured Frontier Receiver"
	},
	4: {
		0: "",
		1: "Unsecured Frontier Digital Nexus",
		2: "Unsecured Frontier Trinary Hub"
	},
	5: {
		0: "",
		1: "Unsecured Frontier Enclave Relay",
		2: "Unsecured Frontier Server Bank"
	},
	6: {
		0: "",
		1: "Unsecured Core Backup Array",
		2: "Unsecured Core Emergence"
	},
	7: {
		0: ""
	},
	8: {
		0: ""
	},
	9: {
		0: ""
	}
};

var gravsLookup = {
	0: "",
	1: "Average Frontier Deposit",
	2: "Unexceptional Frontier Deposit",
	3: "Common Perimeter Deposit",
	4: "Exceptional Core Deposit",
	5: "Infrequent Core Deposit",
	6: "Unusual Core Deposit",
	7: "Rarified Core Deposit",
	8: "Ordinary Perimeter Deposit",
	9: "Uncommon Core Deposit",
	10: "Isolated Core Deposit"
};

var ladarsLookup = {
	0: "",
	1: "Barren Perimeter Reservoir",
	2: "Minor Perimeter Reservoir",
	3: "Ordinary Perimeter Reservoir",
	4: "Sizable Perimeter Reservoir",
	5: "Token Perimeter Reservoir",
	6: "Bountiful Frontier Reservoir",
	7: "Vast Frontier Reservoir",
	8: "Instrumental Core Reservoir",
	9: "Vital Core Reservoir"
};

var whLookup = {
	1: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "H121 (to C1)",
		8: "C125  (to C2)",
		9: "O883 (to C3)",
		10: "  (to C4)",
		11: "L614 (to C5)",
		12: "S804 (to C6)",
		13: "Z060 (to Nullsec)",
		14: "J244 (to Lowsec)",
		15: "N110 (to Highsec)"
	},
	2: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z647 (to C1)",
		8: "D382 (to C2)",
		9: "O477 (to C3)",
		10: "Y683 (to C4)",
		11: "N062 (to C5)",
		12: "R474 (to C6)",
		13: "E545 (to Nullsec)",
		14: "A239 (to Lowsec)",
		15: "B274 (to Highsec)"
	},
	3: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "V301 (to C1)",
		8: "I182 (to C2)",
		9: "N968 (to C3)",
		10: "T405 (to C4)",
		11: "N770 (to C5)",
		12: "A982 (to C6)",
		13: "K346 (to Nullsec)",
		14: "U210 (to Lowsec)",
		15: "D845 (to Highsec)"
	},
	4: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "P060 (to C1)",
		8: "N766 (to C2)",
		9: "C247 (to C3)",
		10: "X877 (to C4)",
		11: "H900 (to C5)",
		12: "U574 (to C6)",
		13: " (to Nullsec)",
		14: "  (to Lowsec)",
		15: "  (to Highsec)"
	},
	5: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Y790 (to C1)",
		8: "D364 (to C2)",
		9: "M267 (to C3)",
		10: "E175 (to C4)",
		11: "H296 (to C5)",
		12: "V753 (to C6)",
		13: "Z142 (to Nullsec)",
		14: "C140 (to Lowsec)",
		15: "D792 (to Highsec)"
	},
	6: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Q317  (to C1)",
		8: "G024 (to C2)",
		9: "L477 (to C3)",
		10: "Z457 (to C4)",
		11: "V911 (to C5)",
		12: "W237 (to C6)",
		13: "Z142 (to Nullsec)",
		14: "C140 (to Lowsec)",
		15: "D792  (to Highsec)"
	},
	7: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z971 (to C1)",
		8: "R943 (to C2)",
		9: "X702 (to C3)",
		10: " (to C4)",
		11: "M555 (to C5)",
		12: "  (to C6)",
		13: " (to Nullsec)",
		14: " (to Lowsec)",
		15: "A641 (to Highsec)"
	},
	8: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: " (to C1)",
		8: "  (to C2)",
		9: "X702 (to C3)",
		10: "  (to C4)",
		11: "N432 (to C5)",
		12: "  (to C6)",
		13: "  (to Nullsec)",
		14: "  (to Lowsec)",
		15: "  (to Highsec)"
	},
	9: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z971 (to C1)",
		8: "R943 (to C2)",
		9: "X702 (to C3)",
		10: "  (to C4)",
		11: "N432 (to C5)",
		12: "  (to C6)",
		13: "S199 (to Nullsec)",
		14: "N944 (to Lowsec)",
		15: "B449 (to Highsec)"
	}
};

var blackHoleEffects = {
	1: [
		['Inertia', '+25%'],
		['Targeting Range', '-10%'],
		['Falloff', '-10%'],
		['Missile Velocity', '-10%'],
		['Ship Velocity', '+25%'],
		['Drone control Range', '-10%']
	],
	2: [
		['Inertia', '+44%'],
		['Targeting Range', '-19%'],
		['Falloff', '-19%'],
		['Missile Velocity', '-19%'],
		['Ship Velocity', '+44%'],
		['Drone control Range', '-19%']
	],
	3: [
		['Inertia', '+55%'],
		['Targeting Range', '-27%'],
		['Falloff', '-27%'],
		['Missile Velocity', '-27%'],
		['Ship Velocity', '+55%'],
		['Drone control Range', '-27%']
	],
	4: [
		['Inertia', '+68%'],
		['Targeting Range', '-34%'],
		['Falloff', '-34%'],
		['Missile Velocity', '-34%'],
		['Ship Velocity', '+68%'],
		['Drone control Range', '-34%']
	], 
	5: [
		['Inertia', '+85%'],
		['Targeting Range', '-41%'],
		['Falloff', '-41%'],
		['Missile Velocity', '-41%'],
		['Ship Velocity', '+85%'],
		['Drone control Range', '-41%']
	],
	6: [
		['Inertia', '+100%'],
		['Targeting Range', '-50%'],
		['Falloff', '-50%'],
		['Missile Velocity', '-50%'],
		['Ship Velocity', '+100%'],
		['Drone control Range', '-50%']
	]
};

var wolfRayetEffects = {
	1: [
		['Armor Resists', '+10%'],
		['Shield Resists', '-10%'],
		['Small Weapon Damage', '+25%'],
		['Signature Size', '-10%']
	],
	2: [
		['Armor Resists', '+18%'],
		['Shield Resists', '-18%'],
		['Small Weapon Damage', '+44%'],
		['Signature Size', '-19%']
	],
	3: [
		['Armor Resists', '+22%'],
		['Shield Resists', '-22%'],
		['Small Weapon Damage', '+55%'],
		['Signature Size', '-27%']
	],
	4: [
		['Armor Resists', '+27%'],
		['Shield Resists', '-27%'],
		['Small Weapon Damage', '+68%'],
		['Signature Size', '-34%']
	], 
	5: [
		['Armor Resists', '+34%'],
		['Shield Resists', '-34%'],
		['Small Weapon Damage', '+85%'],
		['Signature Size', '-41%']
	],
	6: [
		['Armor Resists', '+50%'],
		['Shield Resists', '-50%'],
		['Small Weapon Damage', '+100%'],
		['Signature Size', '-50%']
	]
};

var redGiantEffects = {
	1: [
		['Heat Damage', '+10%'],
		['Overheat Bonus', '+25%'],
		['Smart Bomb Range', '+25%'],
		['Smart Bomb Damage', '+25%']
	],
	2: [
		['Heat Damage', '+18%'],
		['Overheat Bonus', '+44%'],
		['Smart Bomb Range', '+44%'],
		['Smart Bomb Damage', '+44%']
	],
	3: [
		['Heat Damage', '+22%'],
		['Overheat Bonus', '+55%'],
		['Smart Bomb Range', '+55%'],
		['Smart Bomb Damage', '+55%']
	],
	4: [
		['Heat Damage', '+27%'],
		['Overload Bonus', '+68%'],
		['Smart Bomb Range', '+68%'],
		['Smart Bomb Damage', '+68%']
	], 
	5: [
		['Heat Damage', '+34%'],
		['Overheat Bonus', '+85%'],
		['Smart Bomb Range', '+85%'],
		['Smart Bomb Damage', '+85%']
	],
	6: [
		['Heat Damage', '+50%'],
		['Overheat Bonus', '+100%'],
		['Smart Bomb Range', '+100%'],
		['Smart Bomb Damage', '+100%']
	]
};

var catacylsmicEffects = {
	1: [
		['Armor Repair', '-10%'],
		['Shield Boost', '-10%'],
		['Shield Transfer', '+25%'],
		['Remote Repair', '+25%'],
		['Capacitor capacity', '+25%'],
		['Capacitor recharge time', '+25%']
	],
	2: [
		['Armor Repair', '-19%'],
		['Shield Boost', '-19%'],
		['Shield Transfer', '+44%'],
		['Remote Repair', '+44%'],
		['Capacitor capacity', '+44%'],
		['Capacitor recharge time', '+44%']
	],
	3: [
		['Armor Repair', '-27%'],
		['Shield Boost', '-27%'],
		['Shield Transfer', '+55%'],
		['Remote Repair', '+55%'],
		['Capacitor capacity', '+55%'],
		['Capacitor recharge time', '+55%']
	],
	4: [
		['Armor Repair', '-34%'],
		['Shield Boost', '-34%'],
		['Shield Transfer', '+68%'],
		['Remote Repair', '+68%'],
		['Capacitor capacity', '+68%'],
		['Capacitor recharge time', '+68%']
	], 
	5: [
		['Armor Repair', '-41%'],
		['Shield Boost', '-41%'],
		['Shield Transfer', '+85%'],
		['Remote Repair', '+85%'],
		['Capacitor capacity', '+85%'],
		['Capacitor recharge time', '+85%']
	],
	6: [
		['Armor Repair', '-50%'],
		['Shield Boost', '-50%'],
		['Shield Transfer', '+100%'],
		['Remote Repair', '+100%'],
		['Capacitor capacity', '+100%'],
		['Capacitor recharge time', '+100%']
	]
};

var magnetarEffects = {
	1: [
		['Damage', '+25%'],
		['Missile Explosion Velocity', '-10%'],
		['Drone Velocity', '-10%'],
		['Targeting Range', '-10%'],
		['Targeting Speed', '-10%']
	], 
	2: [
		['Damage', '+44%'],
		['Missile Explosion Velocity', '-19%'],
		['Drone Velocity', '-19%'],
		['Targeting Range', '-19%'],
		['Targeting Speed', '-19%']
	], 
	3: [
		['Damage', '+55%'],
		['Missile Explosion Velocity', '-27%'],
		['Drone Velocity', '-27%'],
		['Targeting Range', '-27%'],
		['Targeting Speed', '-27%']
	],
  4: [
		['Damage', '+68%'],
		['Missile Explosion Velocity', '-34%'],
		['Drone Velocity', '-34%'],
		['Targeting Range', '-34%'],
		['Targeting Speed', '-34%']
  ], 
  5: [
		['Damage', '+85%'],
		['Missile Explosion Velocity', '-41%'],
		['Drone Velocity', '-41%'],
		['Targeting Range', '-41%'],
		['Targeting Speed', '-41%']
  ], 
  6 :[
		['Damage', '+100%'],
		['Missile Explosion Velocity', '-50%'],
		['Drone Velocity', '-50%'],
		['Targeting Range', '-50%'],
		['Targeting Speed', '-50%']
  ]
};

var pulsarEffects = {
	1: [
		['Shield HP', '+25%'],
		['Armor Resists', '-10%'],
		['Capacitor recharge time', '-10%'],
		['Targeting Range', '+25%'],
		['Signature Size', '+25%']
	], 
	2: [
		['Shield HP', '+44%'],
		['Armor Resists', '-18%'],
		['Capacitor recharge time', '-19%'],
		['Targeting Range', '+44%'],
		['Signature Size', '+44%']
	], 
	3: [
		['Shield HP', '+58%'],
		['Armor Resists', '-22%'],
		['Capacitor recharge time', '-27%'],
		['Targeting Range', '+58%'],
		['Signature Size', '+58%']
	], 
	4: [
		['Shield HP', '+68%'],
		['Armor Resists', '-27%'],
		['Capacitor recharge time', '-34%'],
		['Targeting Range', '+68%'],
		['Signature Size', '+68%']
	], 
	5: [
		['Shield HP', '+85%'],
		['Armor Resists', '-34%'],
		['Capacitor recharge time', '-41%'],
		['Targeting Range', '+85%'],
		['Signature Size', '+85%']
	], 
	6: [
		['Shield HP', '+100%'],
		['Armor Resists', '-50%'],
		['Capacitor recharge time', '-50%'],
		['Targeting Range', '+100%'],
		['Signature Size', '+100%']
	]
}

//when opened with system in url
if (typeof(CCPEVE) != "undefined")
{
	CCPEVE.requestTrust('http://siggy.borkedlabs.com/*');
}


jQuery.extend(
{
	scope: function (fn, scope)
	{
		return function ()
		{
			return fn.apply(scope, arguments);
		}
	}
});



/**
* @constructor
*/
function siggymain( options )
{
	this.fatalError = false;
	this.ajaxErrors = 0;


	this.systemID = 0;
	this.systemClass = 9;
	this.systemName = '';
	this.systemStats = [];
	this.freezeSystem = 0;
	this.lastUpdate = 0;
	this.sigData = {};
	this.editingSig = false;
	this.sigClocks = {};
	this.systemList = {};
	this.forceUpdate = true;
	this._updateTimeout = null;
	this.publicMode = false;
	this.map = null;
	this.acsid = 0;
	this.acsname = '';
	
	//collasped sysInfo
	this.sysInfoCollasped  = 0;
	this.statsOpened = 0;
	
	//afk stuff
	this.idleMax = 10*60;
	this.idleTimeout = 0;
	this.afked = false;
	
	//gnotes
	this.globalNotesEle = null;
	this._blinkNotesInterval = null;
	this.lastGlobalNotesUpdate = 0;
	this.globalNotes = '';
	this.editingGlobalNotes = false;
	
	this.defaults = {
      baseUrl: '',
      initialSystemID: 0,
      initialSystemName: '',
			showSigSizeCol: false,
			sessionID: '',
			map: {
              jumpTrackerEnabled: true
            }
	};
	
	this.settings = $.extend(this.defaults, options);
}

siggymain.prototype.getCurrentTime = function ()
{
	var date = new Date();
	var time = pad(date.getUTCHours(), 2) + ':' + pad(date.getUTCMinutes(), 2) + ':' + pad(date.getUTCSeconds(), 2);

	delete date;

	return time;
}

siggymain.displayTimeStamp = function (unixTimestamp)
{
	var date = new Date(unixTimestamp * 1000);
	var time = pad(date.getUTCDate(), 2) + '/' + pad(date.getUTCMonth() + 1, 2) + ' ' + pad(date.getUTCHours(), 2) + ':' + pad(date.getUTCMinutes(), 2) + ':' + pad(date.getUTCSeconds(), 2);

	delete date;

	return time;
}

siggymain.prototype.update = function ()
{
/*
	if( this.idleTimeout >= this.idleMax )
	{
		if( !this.afked )
		{
			$.blockUI({message: "Please move your mouse to reactivate siggy."});
			this.afked = true;
		}
		
		var silentRequest = {
			acsid: this.acsid, 
			acsname: this.acsname 
		}
		var that = this;
		$.ajax({
			url: this.baseUrl + 'updateSilent',
			data: silentRequest,
			beforeSend : function(xhr, opts){
				if(that.fatalError == true) //just an example
				{
					xhr.abort();
				}
			},
			success: function (data)
			{
				if( data != null )
				{
					if( parseInt( data.acsid ) != 0 )
					{
						that.acsid = data.acsid;
					}
					if( data.acsname != '' )
					{
						that.acsname = data.acsname;
					}
				}
			},
			dataType: 'json'
			});
		
		this._updateTimeout = setTimeout(function (thisObj)
		{
			thisObj.update(0)
		}, 20000, this);
		return;
	}*/

	var request = {
		systemID: this.systemID,
		lastUpdate: this.lastUpdate,
		lastGlobalNotesUpdate: this.lastGlobalNotesUpdate,
		systemName: this.systemName,
		freezeSystem: this.freezeSystem,
		acsid: this.acsid,
		acsname: this.acsname,
		mapOpen: this.map.isMapOpen(),
		mapLastUpdate: this.map.lastUpdate,
		forceUpdate: this.forceUpdate,
		sessionID: this.settings.sessionID
	};

	var that = this;
	$.ajax({
		url: this.settings.baseUrl + 'update',
		data: request,
		dataType: 'json',
		beforeSend : function(xhr, opts){
			if(that.fatalError == true) //just an example
			{
				xhr.abort();
			}
		},
		success: function (data)
			{
				if( data.redirect != undefined )
				{
					window.location = this.settings.baseUrl + data.redirect;
					return;
				}
			
			
				if( parseInt( data.acsid ) != 0 )
				{
					that.acsid = data.acsid;
				}
				if( data.acsname != '' )
				{
					that.acsname = data.acsname;
					$('#acsname b').text(that.acsname);
				}
				if (data.systemUpdate)
				{
					that.updateSystemInfo(data.systemData);
					that.updateSystemOptionsForm(data.systemData);
				}
				if (data.sigUpdate)
				{
					var flashSigs = ( data.systemUpdate ? false : true );
					that.updateSigs(data.sigData, flashSigs);
				}
				if (data.systemListUpdate)
				{
					that.systemList = data.systemList;
					that.updateSystemList(that.systemList);
				}
				if (data.globalNotesUpdate)
				{
					if (!that.editingGlobalNotes)
					{
						
						if( getCookie('notesUpdate') != null )
						{
							var nlu = parseInt(getCookie('notesUpdate'));
						}				
						else
						{
							var nlu = that.lastGlobalNotesUpdate;
						}
						
						//console.log('nlu:'+nlu);
						if( !that.globalNotesEle.is(':visible') && data.lastGlobalNotesUpdate > nlu && nlu != 0 )
						{
							that.blinkNotes();
						}
						
						that.lastGlobalNotesUpdate = data.lastGlobalNotesUpdate;
						
						setCookie('notesUpdate', data.lastGlobalNotesUpdate, 365);
						
						that.globalNotes = data.globalNotes;
						$('#thegnotes').html(that.globalNotes.replace(/\n/g, '<br />'));
						$('#gNotesTime').text( siggymain.displayTimeStamp(that.lastGlobalNotesUpdate) );
					}
				}
				
				if( that.map.isMapOpen()  )
				{
					if( data.mapUpdate )
					{
						that.map.update(data.chainMap.lastUpdate, data.chainMap.systems, data.chainMap.wormholes);
					}
					if( typeof(data.chainMap) != 'undefined' && typeof(data.chainMap.actives) != '' )
					{
						that.map.updateActives(data.chainMap.actives);
					}
				}

				that.lastUpdate = data.lastUpdate;
				//  $.unblockUI();
				
				delete data;
			}
		});
	


	this.forceUpdate = false;
	$('span.updateTime').text(this.getCurrentTime());
	
	this._updateTimeout = setTimeout(function (thisObj)
	{
		thisObj.update(0)
	}, 10000, this);
	
	return true;
}


siggymain.prototype.sortSystemListInUse = function (a, b)
{
	if (a[1] > b[1])
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

siggymain.prototype.sortSystemListLastActive = function (a, b)
{
	if (a[2] > b[2])
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

siggymain.prototype.sortSystemList = function (a, b)
{
	if (a[1] == b[1])
	{
		if (a[2] > b[2])
		{
			return -1;
		}
		else
		{
			return 1;
		}
	}
	//if 1 and 0
	else if (a[1] > b[1])
	{
		return -1;
	}
	else if (a[1] < b[1])
	{
		return 1;
	}
}

siggymain.prototype.updateSystemList = function (systemList)
{
	var sortable = [];
	for (var i in systemList)
	{
		sortable.push([i, systemList[i].inUse, systemList[i].lastActive]);
	}
	sortable.sort(this.sortSystemList);

	var listContainer = $('#systemList ul');
	listContainer.empty();
	for (var i in sortable)
	{
		var key = sortable[i][0];
		var sysClass = Number(systemList[key].sysClass);
		switch (sysClass)
		{
		case 1:
		case 2:
		case 3:
			var colorClass = 'classUnknown';
			break;
		case 4:
		case 5:
			var colorClass = 'classDangerous';
			break;
		case 6:
			var colorClass = 'classDeadly';
			break;
		case 7:
			var colorClass = 'classHigh';
			sysClass = 'H';
			break;
		case 8:
			var colorClass = 'classLow';
			sysClass = 'L';
			break;
		case 9:
			var colorClass = 'classNull';
			sysClass = 'N';
			break;
		default:
			var colorClass = 'classUnknown';
			break;
		}
		//  var that = this;
		var displayName = '';
		if (systemList[key].displayName != "")
		{
			displayName = systemList[key].displayName;
		}
		else
		{
			displayName = systemList[key].name;
		}

		var item = $('<li>').text(displayName).prepend($('<span>').addClass('sysClass').addClass(colorClass).text(sysClass));
		this.registerSwitchHandler(item, systemList[key].systemID, systemList[key].name);
		if (systemList[key].name == this.systemName)
		{
			item.addClass('sysSelected');
		}

		if (systemList[key].inUse == 1)
		{
			item.addClass('inUse');
		}
		else
		{
			item.addClass('notInUse');
		}
		listContainer.append(item);
	}
}

siggymain.prototype.registerSwitchHandler = function (item, systemID, systemName)
{
	var that = this;
	item.click(function ()
	{
		//$.blockUI({ message: '<h1 style="font-size:1.2em;"><strong>Loading...</strong></h1>' }); 
		that.switchSystem(systemID, systemName);

	});
}

siggymain.prototype.updateNow = function()
{
	clearTimeout(this._updateTimeout);
	return this.update();
	
}

siggymain.prototype.switchSystem = function(systemID, systemName)
{
	this.setSystemID(systemID);
	this.systemName = systemName;
	this.forceUpdate = true;
	this.freeze();
	clearTimeout(this._updateTimeout);
	for(var i in this.sigClocks)
	{
		this.sigClocks[i].destroy();
		delete clock;
	}
	$("#sigTable tbody").empty();
	this.editingSig = false;
	this.sigData = {};
	
	
	$('#sigAddBox select[name=type]').val(0);
  //$('#sigAddBox select[name=site]').replaceWith(this.generateSiteSelect(this.systemClass, 0, 0).attr('name', 'site'));
	this.updateSiteSelect('#sigAddBox select[name=site]',this.systemClass, 0, 0);
	
	if( this.updateNow() )
	{
			$(document).trigger('siggy.switchSystem', systemID );
	}
}

siggymain.prototype.updateSigs = function (sigData, flashSigs)
{
	for (var i in this.sigData)
	{
		if (typeof(sigData[i]) !== undefined && typeof(sigData[i]) != "undefined" && sigData[i] !== null)
		{
			sigData[i].exists = true;
			if (!this.sigData[i].editing)
			{
				this.sigData[i] = sigData[i];
				this.updateSigRow(this.sigData[i], flashSigs);
			}
		}
		else
		{
			if (this.sigData[i].editing)
			{
				continue;
			}
			this.removeSigRow(this.sigData[i]);
			delete this.sigData[i];
		}
	}

	for (var i in sigData)
	{
		if (sigData[i].exists != true)
		{
			// console.log(sigData);
			this.addSigRow(sigData[i],flashSigs);
			this.sigData[i] = sigData[i];
		}
	}
	//this.colorizeSigRows();
	$('#sigTable').trigger('update');
}

siggymain.prototype.updateSystemInfo = function (systemData)
{
	$('#region').text(systemData.regionName);
	$('#constellation').text(systemData.constellationName);
	$('#planetsmoons').text(systemData.planets + "/" + systemData.moons + "/" + systemData.belts);
	$('#truesec').text(systemData.truesec.substr(0,8));
	$('#radius').text(systemData.radius + ' AU');
	
	var hubJumpsStr = '';
	var count = 0;
	for(var index in systemData.hubJumps)
	{
        var hub = systemData.hubJumps[index];
        hubJumpsStr += hub.destination_name + " (" + hub.num_jumps + " jumps) &nbsp;&nbsp&nbsp;&nbsp;";
        
        if( ++count > 1 )
        {
            count = 0;
            hubJumpsStr += "<br />";
        }
	}
	$('#hubJumps').html(hubJumpsStr);

	var collaspedInfoEffectStatic = $('#collaspedInfoEffectStatic');
	collaspedInfoEffectStatic.empty();
	$('#systemInfo-collasped p.spacer').hide();
	
	//effect info
	$('#systemEffect').empty();
	
	
	var effectTitle = $("<p>").text(systemData.effectTitle);
	var effect = $('#systemEffect').append(effectTitle);
	var effectInfo = '';
	
	var collaspedEffectTitle = $("<span>").text( (systemData.effectTitle == 'None' ? '': systemData.effectTitle) );
	
	if( systemData.effectTitle != 'None' )
	{
		effectInfo += '<b>Class '+systemData.sysClass+' Effects</b><br /><br />';
		
		if( systemData.effectTitle == 'Black Hole' )
		{	
			var effData = blackHoleEffects[systemData.sysClass];
		}<commit_msg>Added costs page. Added getting siggy page. Fixed auth system not doing remember me correctly due to assignment. Changed cost formula to be lienar model. Fixed reset password. Disabled php session cookies.<commit_after>Object.size = function (obj)
{
	var size = 0,
		key;
	for (key in obj)
	{
		if (obj.hasOwnProperty(key)) size++;
	}
	return size;
};

function roundNumber(num, dec)
{
	var result = String(Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec));
	if (result.indexOf('.') < 0)
	{
		result += '.';
	}
	while (result.length - result.indexOf('.') <= dec)
	{
		result += '0';
	}
	return result;
}

/**
* @constructor
*/
jQuery.fn.flash = function( color, duration )
{
		if( typeof this.data('flashing') =='undefined' )
		{
			this.data('flashing', false);
		}
		
		if( this.data('flashing') == true )
		{
			return;
		}
    var current = this.css( 'background-color' );

	this.data('flashing', true)
    this.animate( { backgroundColor: color }, duration / 2 );
    
    var $this = this;
    this.animate( { backgroundColor: current }, duration / 2, function() { $this.data('flashing', false); } );
}

jQuery.fn.fadeOutFlash = function( color, duration )
{
		if( typeof this.data('flashing') =='undefined' )
		{
			this.data('flashing', false);
		}
		
		if( this.data('flashing') == true )
		{
			return;
		}
    var current = this.css( 'background-color' );

	this.data('flashing', true)
    this.css( 'background-color', color )
    
    var $this = this;
    this.animate( { backgroundColor: current }, duration, function() { $this.data('flashing', false); } );
}

new function() {
		$.browser.eveIGB = false;
		if( navigator.appVersion.indexOf('EVE-IGB') != -1 )
		{
				$.browser.eveIGB = true;
		}
}();


function setCookie(name,value,days) {
		if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}
			
			

function CountUp(initDate,selector)
{
	this.beginDate = new Date(initDate);
	this.container = $(selector);
	this.calculate();
	this.timeout = null;
}			

CountUp.prototype.destroy = function()
{
	clearTimeout(this.timeout);
	this.container = null;
	delete this.beginDate;
}


CountUp.prototype.addLeadingZero = function (value)
{
	return value < 10 ? ('0' + value) : value;
}

CountUp.prototype.calculate = function ()
{
	if( this.container == null )
	{
		return;
	}

	var currDate = new Date();
	var prevDate = this.beginDate;
	
	dd = currDate - prevDate;
    this.days = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
    this.hours = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
    if( this.days < 2 )
    {
		this.minutes = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
		this.seconds = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
		
		this.seconds = this.addLeadingZero(this.seconds);
		this.minutes = this.addLeadingZero(this.minutes);
	}
	this.hours = this.addLeadingZero(this.hours);
	
	if( this.days == 0 )
	{
		this.container.text(this.hours + ":" + this.minutes + ":" + this.seconds);
	}
	else
	{
		this.container.text(this.days + "d " + this.hours + "h");
	}
	
	if( this.days < 2 )
	{
		var self = this;
		this.timeout = setTimeout(function ()
		{
			self.calculate();
		}, 1000);
	}
	delete currDate;
	currDate = null;
}
			

function pad(number, length)
{
	var str = '' + number;
	while (str.length < length)
	{
		str = '0' + str;
	}

	return str;
}

//first key is wh class, second is just unique for mag in the class
var magsLookup = {
	1: {
		0: "",
		1: "Forgotten Perimeter Coronation Platform",
		2: "Forgotten Perimeter Power Array"
	},
	2: {
		0: "",
		1: "Forgotten Perimeter Gateway",
		2: "Forgoten Perimeter Habitation Coils"
	},
	3: {
		0: "",
		1: "Forgotten Frontier Quarantine Outpost",
		2: "Forgotten Frontier Recursive Depot"
	},
	4: {
		0: "",
		1: "Forgotten Frontier Conversion Module",
		2: "Forgotten Frontier Evacuation Center"
	},
	5: {
		0: "",
		1: "Forgotten Core Data Field",
		2: "Forgotten Core Information Pen"
	},
	6: {
		0: "",
		1: "Forgotten Core Assembly Hall",
		2: "Forgotten Circuitry Disassembler"
	},
	7: {
		0: ""
	},
	8: {
		0: ""
	},
	9: {
		0: ""
	}
};

var radarsLookup = {
	1: {
		0: "",
		1: "Unsecured Perimeter Amplifier",
		2: "Unsecured Perimeter Information Center"
	},
	2: {
		0: "",
		1: "Unsecured Perimeter Comms Relay",
		2: "Unsecured Transponder Farm"
	},
	3: {
		0: "",
		1: "Unsecured Frontier Database",
		2: "Unsecured Frontier Receiver"
	},
	4: {
		0: "",
		1: "Unsecured Frontier Digital Nexus",
		2: "Unsecured Frontier Trinary Hub"
	},
	5: {
		0: "",
		1: "Unsecured Frontier Enclave Relay",
		2: "Unsecured Frontier Server Bank"
	},
	6: {
		0: "",
		1: "Unsecured Core Backup Array",
		2: "Unsecured Core Emergence"
	},
	7: {
		0: ""
	},
	8: {
		0: ""
	},
	9: {
		0: ""
	}
};

var gravsLookup = {
	0: "",
	1: "Average Frontier Deposit",
	2: "Unexceptional Frontier Deposit",
	3: "Common Perimeter Deposit",
	4: "Exceptional Core Deposit",
	5: "Infrequent Core Deposit",
	6: "Unusual Core Deposit",
	7: "Rarified Core Deposit",
	8: "Ordinary Perimeter Deposit",
	9: "Uncommon Core Deposit",
	10: "Isolated Core Deposit"
};

var ladarsLookup = {
	0: "",
	1: "Barren Perimeter Reservoir",
	2: "Minor Perimeter Reservoir",
	3: "Ordinary Perimeter Reservoir",
	4: "Sizable Perimeter Reservoir",
	5: "Token Perimeter Reservoir",
	6: "Bountiful Frontier Reservoir",
	7: "Vast Frontier Reservoir",
	8: "Instrumental Core Reservoir",
	9: "Vital Core Reservoir"
};

var whLookup = {
	1: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "H121 (to C1)",
		8: "C125  (to C2)",
		9: "O883 (to C3)",
		10: "  (to C4)",
		11: "L614 (to C5)",
		12: "S804 (to C6)",
		13: "Z060 (to Nullsec)",
		14: "J244 (to Lowsec)",
		15: "N110 (to Highsec)"
	},
	2: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z647 (to C1)",
		8: "D382 (to C2)",
		9: "O477 (to C3)",
		10: "Y683 (to C4)",
		11: "N062 (to C5)",
		12: "R474 (to C6)",
		13: "E545 (to Nullsec)",
		14: "A239 (to Lowsec)",
		15: "B274 (to Highsec)"
	},
	3: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "V301 (to C1)",
		8: "I182 (to C2)",
		9: "N968 (to C3)",
		10: "T405 (to C4)",
		11: "N770 (to C5)",
		12: "A982 (to C6)",
		13: "K346 (to Nullsec)",
		14: "U210 (to Lowsec)",
		15: "D845 (to Highsec)"
	},
	4: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "P060 (to C1)",
		8: "N766 (to C2)",
		9: "C247 (to C3)",
		10: "X877 (to C4)",
		11: "H900 (to C5)",
		12: "U574 (to C6)",
		13: " (to Nullsec)",
		14: "  (to Lowsec)",
		15: "  (to Highsec)"
	},
	5: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Y790 (to C1)",
		8: "D364 (to C2)",
		9: "M267 (to C3)",
		10: "E175 (to C4)",
		11: "H296 (to C5)",
		12: "V753 (to C6)",
		13: "Z142 (to Nullsec)",
		14: "C140 (to Lowsec)",
		15: "D792 (to Highsec)"
	},
	6: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Q317  (to C1)",
		8: "G024 (to C2)",
		9: "L477 (to C3)",
		10: "Z457 (to C4)",
		11: "V911 (to C5)",
		12: "W237 (to C6)",
		13: "Z142 (to Nullsec)",
		14: "C140 (to Lowsec)",
		15: "D792  (to Highsec)"
	},
	7: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z971 (to C1)",
		8: "R943 (to C2)",
		9: "X702 (to C3)",
		10: " (to C4)",
		11: "M555 (to C5)",
		12: "  (to C6)",
		13: " (to Nullsec)",
		14: " (to Lowsec)",
		15: "A641 (to Highsec)"
	},
	8: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: " (to C1)",
		8: "  (to C2)",
		9: "X702 (to C3)",
		10: "  (to C4)",
		11: "N432 (to C5)",
		12: "  (to C6)",
		13: "  (to Nullsec)",
		14: "  (to Lowsec)",
		15: "  (to Highsec)"
	},
	9: {
		0: "Unstable Wormhole",
		1: "K162 (from Unknown)",
		2: "K162 (from Dangerous unknown)",
		3: "K162 (from Deadly unknown)",
		4: "K162 (from Nullsec)",
		5: "K162 (from Lowsec)",
		6: "K162 (from Highsec)",
		7: "Z971 (to C1)",
		8: "R943 (to C2)",
		9: "X702 (to C3)",
		10: "  (to C4)",
		11: "N432 (to C5)",
		12: "  (to C6)",
		13: "S199 (to Nullsec)",
		14: "N944 (to Lowsec)",
		15: "B449 (to Highsec)"
	}
};

var blackHoleEffects = {
	1: [
		['Inertia', '+25%'],
		['Targeting Range', '-10%'],
		['Falloff', '-10%'],
		['Missile Velocity', '-10%'],
		['Ship Velocity', '+25%'],
		['Drone control Range', '-10%']
	],
	2: [
		['Inertia', '+44%'],
		['Targeting Range', '-19%'],
		['Falloff', '-19%'],
		['Missile Velocity', '-19%'],
		['Ship Velocity', '+44%'],
		['Drone control Range', '-19%']
	],
	3: [
		['Inertia', '+55%'],
		['Targeting Range', '-27%'],
		['Falloff', '-27%'],
		['Missile Velocity', '-27%'],
		['Ship Velocity', '+55%'],
		['Drone control Range', '-27%']
	],
	4: [
		['Inertia', '+68%'],
		['Targeting Range', '-34%'],
		['Falloff', '-34%'],
		['Missile Velocity', '-34%'],
		['Ship Velocity', '+68%'],
		['Drone control Range', '-34%']
	], 
	5: [
		['Inertia', '+85%'],
		['Targeting Range', '-41%'],
		['Falloff', '-41%'],
		['Missile Velocity', '-41%'],
		['Ship Velocity', '+85%'],
		['Drone control Range', '-41%']
	],
	6: [
		['Inertia', '+100%'],
		['Targeting Range', '-50%'],
		['Falloff', '-50%'],
		['Missile Velocity', '-50%'],
		['Ship Velocity', '+100%'],
		['Drone control Range', '-50%']
	]
};

var wolfRayetEffects = {
	1: [
		['Armor Resists', '+10%'],
		['Shield Resists', '-10%'],
		['Small Weapon Damage', '+25%'],
		['Signature Size', '-10%']
	],
	2: [
		['Armor Resists', '+18%'],
		['Shield Resists', '-18%'],
		['Small Weapon Damage', '+44%'],
		['Signature Size', '-19%']
	],
	3: [
		['Armor Resists', '+22%'],
		['Shield Resists', '-22%'],
		['Small Weapon Damage', '+55%'],
		['Signature Size', '-27%']
	],
	4: [
		['Armor Resists', '+27%'],
		['Shield Resists', '-27%'],
		['Small Weapon Damage', '+68%'],
		['Signature Size', '-34%']
	], 
	5: [
		['Armor Resists', '+34%'],
		['Shield Resists', '-34%'],
		['Small Weapon Damage', '+85%'],
		['Signature Size', '-41%']
	],
	6: [
		['Armor Resists', '+50%'],
		['Shield Resists', '-50%'],
		['Small Weapon Damage', '+100%'],
		['Signature Size', '-50%']
	]
};

var redGiantEffects = {
	1: [
		['Heat Damage', '+10%'],
		['Overheat Bonus', '+25%'],
		['Smart Bomb Range', '+25%'],
		['Smart Bomb Damage', '+25%']
	],
	2: [
		['Heat Damage', '+18%'],
		['Overheat Bonus', '+44%'],
		['Smart Bomb Range', '+44%'],
		['Smart Bomb Damage', '+44%']
	],
	3: [
		['Heat Damage', '+22%'],
		['Overheat Bonus', '+55%'],
		['Smart Bomb Range', '+55%'],
		['Smart Bomb Damage', '+55%']
	],
	4: [
		['Heat Damage', '+27%'],
		['Overload Bonus', '+68%'],
		['Smart Bomb Range', '+68%'],
		['Smart Bomb Damage', '+68%']
	], 
	5: [
		['Heat Damage', '+34%'],
		['Overheat Bonus', '+85%'],
		['Smart Bomb Range', '+85%'],
		['Smart Bomb Damage', '+85%']
	],
	6: [
		['Heat Damage', '+50%'],
		['Overheat Bonus', '+100%'],
		['Smart Bomb Range', '+100%'],
		['Smart Bomb Damage', '+100%']
	]
};

var catacylsmicEffects = {
	1: [
		['Armor Repair', '-10%'],
		['Shield Boost', '-10%'],
		['Shield Transfer', '+25%'],
		['Remote Repair', '+25%'],
		['Capacitor capacity', '+25%'],
		['Capacitor recharge time', '+25%']
	],
	2: [
		['Armor Repair', '-19%'],
		['Shield Boost', '-19%'],
		['Shield Transfer', '+44%'],
		['Remote Repair', '+44%'],
		['Capacitor capacity', '+44%'],
		['Capacitor recharge time', '+44%']
	],
	3: [
		['Armor Repair', '-27%'],
		['Shield Boost', '-27%'],
		['Shield Transfer', '+55%'],
		['Remote Repair', '+55%'],
		['Capacitor capacity', '+55%'],
		['Capacitor recharge time', '+55%']
	],
	4: [
		['Armor Repair', '-34%'],
		['Shield Boost', '-34%'],
		['Shield Transfer', '+68%'],
		['Remote Repair', '+68%'],
		['Capacitor capacity', '+68%'],
		['Capacitor recharge time', '+68%']
	], 
	5: [
		['Armor Repair', '-41%'],
		['Shield Boost', '-41%'],
		['Shield Transfer', '+85%'],
		['Remote Repair', '+85%'],
		['Capacitor capacity', '+85%'],
		['Capacitor recharge time', '+85%']
	],
	6: [
		['Armor Repair', '-50%'],
		['Shield Boost', '-50%'],
		['Shield Transfer', '+100%'],
		['Remote Repair', '+100%'],
		['Capacitor capacity', '+100%'],
		['Capacitor recharge time', '+100%']
	]
};

var magnetarEffects = {
	1: [
		['Damage', '+25%'],
		['Missile Explosion Velocity', '-10%'],
		['Drone Velocity', '-10%'],
		['Targeting Range', '-10%'],
		['Targeting Speed', '-10%']
	], 
	2: [
		['Damage', '+44%'],
		['Missile Explosion Velocity', '-19%'],
		['Drone Velocity', '-19%'],
		['Targeting Range', '-19%'],
		['Targeting Speed', '-19%']
	], 
	3: [
		['Damage', '+55%'],
		['Missile Explosion Velocity', '-27%'],
		['Drone Velocity', '-27%'],
		['Targeting Range', '-27%'],
		['Targeting Speed', '-27%']
	],
  4: [
		['Damage', '+68%'],
		['Missile Explosion Velocity', '-34%'],
		['Drone Velocity', '-34%'],
		['Targeting Range', '-34%'],
		['Targeting Speed', '-34%']
  ], 
  5: [
		['Damage', '+85%'],
		['Missile Explosion Velocity', '-41%'],
		['Drone Velocity', '-41%'],
		['Targeting Range', '-41%'],
		['Targeting Speed', '-41%']
  ], 
  6 :[
		['Damage', '+100%'],
		['Missile Explosion Velocity', '-50%'],
		['Drone Velocity', '-50%'],
		['Targeting Range', '-50%'],
		['Targeting Speed', '-50%']
  ]
};

var pulsarEffects = {
	1: [
		['Shield HP', '+25%'],
		['Armor Resists', '-10%'],
		['Capacitor recharge time', '-10%'],
		['Targeting Range', '+25%'],
		['Signature Size', '+25%']
	], 
	2: [
		['Shield HP', '+44%'],
		['Armor Resists', '-18%'],
		['Capacitor recharge time', '-19%'],
		['Targeting Range', '+44%'],
		['Signature Size', '+44%']
	], 
	3: [
		['Shield HP', '+58%'],
		['Armor Resists', '-22%'],
		['Capacitor recharge time', '-27%'],
		['Targeting Range', '+58%'],
		['Signature Size', '+58%']
	], 
	4: [
		['Shield HP', '+68%'],
		['Armor Resists', '-27%'],
		['Capacitor recharge time', '-34%'],
		['Targeting Range', '+68%'],
		['Signature Size', '+68%']
	], 
	5: [
		['Shield HP', '+85%'],
		['Armor Resists', '-34%'],
		['Capacitor recharge time', '-41%'],
		['Targeting Range', '+85%'],
		['Signature Size', '+85%']
	], 
	6: [
		['Shield HP', '+100%'],
		['Armor Resists', '-50%'],
		['Capacitor recharge time', '-50%'],
		['Targeting Range', '+100%'],
		['Signature Size', '+100%']
	]
}

//when opened with system in url
if (typeof(CCPEVE) != "undefined")
{
	CCPEVE.requestTrust('http://siggy.borkedlabs.com/*');
}


jQuery.extend(
{
	scope: function (fn, scope)
	{
		return function ()
		{
			return fn.apply(scope, arguments);
		}
	}
});



/**
* @constructor
*/
function siggymain( options )
{
	this.fatalError = false;
	this.ajaxErrors = 0;


	this.systemID = 0;
	this.systemClass = 9;
	this.systemName = '';
	this.systemStats = [];
	this.freezeSystem = 0;
	this.lastUpdate = 0;
	this.sigData = {};
	this.editingSig = false;
	this.sigClocks = {};
	this.systemList = {};
	this.forceUpdate = true;
	this._updateTimeout = null;
	this.publicMode = false;
	this.map = null;
	this.acsid = 0;
	this.acsname = '';
	
	//collasped sysInfo
	this.sysInfoCollasped  = 0;
	this.statsOpened = 0;
	
	//afk stuff
	this.idleMax = 10*60;
	this.idleTimeout = 0;
	this.afked = false;
	
	//gnotes
	this.globalNotesEle = null;
	this._blinkNotesInterval = null;
	this.lastGlobalNotesUpdate = 0;
	this.globalNotes = '';
	this.editingGlobalNotes = false;
	
	this.defaults = {
      baseUrl: '',
      initialSystemID: 0,
      initialSystemName: '',
			showSigSizeCol: false,
			sessionID: '',
			map: {
              jumpTrackerEnabled: true
            }
	};
	
	this.settings = $.extend(this.defaults, options);
}

siggymain.prototype.getCurrentTime = function ()
{
	var date = new Date();
	var time = pad(date.getUTCHours(), 2) + ':' + pad(date.getUTCMinutes(), 2) + ':' + pad(date.getUTCSeconds(), 2);

	delete date;

	return time;
}

siggymain.displayTimeStamp = function (unixTimestamp)
{
	var date = new Date(unixTimestamp * 1000);
	var time = pad(date.getUTCDate(), 2) + '/' + pad(date.getUTCMonth() + 1, 2) + ' ' + pad(date.getUTCHours(), 2) + ':' + pad(date.getUTCMinutes(), 2) + ':' + pad(date.getUTCSeconds(), 2);

	delete date;

	return time;
}

siggymain.prototype.update = function ()
{
/*
	if( this.idleTimeout >= this.idleMax )
	{
		if( !this.afked )
		{
			$.blockUI({message: "Please move your mouse to reactivate siggy."});
			this.afked = true;
		}
		
		var silentRequest = {
			acsid: this.acsid, 
			acsname: this.acsname 
		}
		var that = this;
		$.ajax({
			url: this.baseUrl + 'updateSilent',
			data: silentRequest,
			beforeSend : function(xhr, opts){
				if(that.fatalError == true) //just an example
				{
					xhr.abort();
				}
			},
			success: function (data)
			{
				if( data != null )
				{
					if( parseInt( data.acsid ) != 0 )
					{
						that.acsid = data.acsid;
					}
					if( data.acsname != '' )
					{
						that.acsname = data.acsname;
					}
				}
			},
			dataType: 'json'
			});
		
		this._updateTimeout = setTimeout(function (thisObj)
		{
			thisObj.update(0)
		}, 20000, this);
		return;
	}*/

	var request = {
		systemID: this.systemID,
		lastUpdate: this.lastUpdate,
		lastGlobalNotesUpdate: this.lastGlobalNotesUpdate,
		systemName: this.systemName,
		freezeSystem: this.freezeSystem,
		acsid: this.acsid,
		acsname: this.acsname,
		mapOpen: this.map.isMapOpen(),
		mapLastUpdate: this.map.lastUpdate,
		forceUpdate: this.forceUpdate,
		sessionID: this.settings.sessionID
	};

	var that = this;
	$.ajax({
		url: this.settings.baseUrl + 'update',
		data: request,
		dataType: 'json',
		beforeSend : function(xhr, opts){
			if(that.fatalError == true) //just an example
			{
				xhr.abort();
			}
		},
		success: function (data)
			{
				if( data.redirect != undefined )
				{
					window.location = this.settings.baseUrl + data.redirect;
					return;
				}
			
			
				if( parseInt( data.acsid ) != 0 )
				{
					that.acsid = data.acsid;
				}
				if( data.acsname != '' )
				{
					that.acsname = data.acsname;
					$('#acsname b').text(that.acsname);
				}
				if (data.systemUpdate)
				{
					that.updateSystemInfo(data.systemData);
					that.updateSystemOptionsForm(data.systemData);
				}
				if (data.sigUpdate)
				{
					var flashSigs = ( data.systemUpdate ? false : true );
					that.updateSigs(data.sigData, flashSigs);
				}
				if (data.systemListUpdate)
				{
					that.systemList = data.systemList;
					that.updateSystemList(that.systemList);
				}
				if (data.globalNotesUpdate)
				{
					if (!that.editingGlobalNotes)
					{
						
						if( getCookie('notesUpdate') != null )
						{
							var nlu = parseInt(getCookie('notesUpdate'));
						}				
						else
						{
							var nlu = that.lastGlobalNotesUpdate;
						}
						
						//console.log('nlu:'+nlu);
						if( !that.globalNotesEle.is(':visible') && data.lastGlobalNotesUpdate > nlu && nlu != 0 )
						{
							that.blinkNotes();
						}
						
						that.lastGlobalNotesUpdate = data.lastGlobalNotesUpdate;
						
						setCookie('notesUpdate', data.lastGlobalNotesUpdate, 365);
						
						that.globalNotes = data.globalNotes;
						$('#thegnotes').html(that.globalNotes.replace(/\n/g, '<br />'));
						$('#gNotesTime').text( siggymain.displayTimeStamp(that.lastGlobalNotesUpdate) );
					}
				}
				
				if( that.map.isMapOpen()  )
				{
					if( data.mapUpdate )
					{
						that.map.update(data.chainMap.lastUpdate, data.chainMap.systems, data.chainMap.wormholes);
					}
					if( typeof(data.chainMap) != 'undefined' && typeof(data.chainMap.actives) != '' )
					{
						that.map.updateActives(data.chainMap.actives);
					}
				}

				that.lastUpdate = data.lastUpdate;
				//  $.unblockUI();
				
				delete data;
			}
		});
	


	this.forceUpdate = false;
	$('span.updateTime').text(this.getCurrentTime());
	
	this._updateTimeout = setTimeout(function (thisObj)
	{
		thisObj.update(0)
	}, 10000, this);
	
	return true;
}


siggymain.prototype.sortSystemListInUse = function (a, b)
{
	if (a[1] > b[1])
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

siggymain.prototype.sortSystemListLastActive = function (a, b)
{
	if (a[2] > b[2])
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

siggymain.prototype.sortSystemList = function (a, b)
{
	if (a[1] == b[1])
	{
		if (a[2] > b[2])
		{
			return -1;
		}
		else
		{
			return 1;
		}
	}
	//if 1 and 0
	else if (a[1] > b[1])
	{
		return -1;
	}
	else if (a[1] < b[1])
	{
		return 1;
	}
}

siggymain.prototype.updateSystemList = function (systemList)
{
	var sortable = [];
	for (var i in systemList)
	{
		sortable.push([i, systemList[i].inUse, systemList[i].lastActive]);
	}
	sortable.sort(this.sortSystemList);

	var listContainer = $('#systemList ul');
	listContainer.empty();
	for (var i in sortable)
	{
		var key = sortable[i][0];
		var sysClass = Number(systemList[key].sysClass);
		switch (sysClass)
		{
		case 1:
		case 2:
		case 3:
			var colorClass = 'classUnknown';
			break;
		case 4:
		case 5:
			var colorClass = 'classDangerous';
			break;
		case 6:
			var colorClass = 'classDeadly';
			break;
		case 7:
			var colorClass = 'classHigh';
			sysClass = 'H';
			break;
		case 8:
			var colorClass = 'classLow';
			sysClass = 'L';
			break;
		case 9:
			var colorClass = 'classNull';
			sysClass = 'N';
			break;
		default:
			var colorClass = 'classUnknown';
			break;
		}
		//  var that = this;
		var displayName = '';
		if (systemList[key].displayName != "")
		{
			displayName = systemList[key].displayName;
		}
		else
		{
			displayName = systemList[key].name;
		}

		var item = $('<li>').text(displayName).prepend($('<span>').addClass('sysClass').addClass(colorClass).text(sysClass));
		this.registerSwitchHandler(item, systemList[key].systemID, systemList[key].name);
		if (systemList[key].name == this.systemName)
		{
			item.addClass('sysSelected');
		}

		if (systemList[key].inUse == 1)
		{
			item.addClass('inUse');
		}
		else
		{
			item.addClass('notInUse');
		}
		listContainer.append(item);
	}
}

siggymain.prototype.registerSwitchHandler = function (item, systemID, systemName)
{
	var that = this;
	item.click(function ()
	{
		//$.blockUI({ message: '<h1 style="font-size:1.2em;"><strong>Loading...</strong></h1>' }); 
		that.switchSystem(systemID, systemName);

	});
}

siggymain.prototype.updateNow = function()
{
	clearTimeout(this._updateTimeout);
	return this.update();
	
}

siggymain.prototype.switchSystem = function(systemID, systemName)
{
	this.setSystemID(systemID);
	this.systemName = systemName;
	this.forceUpdate = true;
	this.freeze();
	clearTimeout(this._updateTimeout);
	for(var i in this.sigClocks)
	{
		this.sigClocks[i].destroy();
		delete clock;
	}
	$("#sigTable tbody").empty();
	this.editingSig = false;
	this.sigData = {};
	
	
	$('#sigAddBox select[name=type]').val(0);
  //$('#sigAddBox select[name=site]').replaceWith(this.generateSiteSelect(this.systemClass, 0, 0).attr('name', 'site'));
	this.updateSiteSelect('#sigAddBox select[name=site]',this.systemClass, 0, 0);
	
	if( this.updateNow() )
	{
			$(document).trigger('siggy.switchSystem', systemID );
	}
}

siggymain.prototype.updateSigs = function (sigData, flashSigs)
{
	for (var i in this.sigData)
	{
		if (typeof(sigData[i]) !== undefined && typeof(sigData[i]) != "undefined" && sigData[i] !== null)
		{
			sigData[i].exists = true;
			if (!this.sigData[i].editing)
			{
				this.sigData[i] = sigData[i];
				this.updateSigRow(this.sigData[i], flashSigs);
			}
		}
		else
		{
			if (this.sigData[i].editing)
			{
				continue;
			}
			this.removeSigRow(this.sigData[i]);
			delete this.sigData[i];
		}
	}

	for (var i in sigData)
	{
		if (sigData[i].exists != true)
		{
			// console.log(sigData);
			this.addSigRow(sigData[i],flashSigs);
			this.sigData[i] = sigData[i];
		}
	}
	//this.colorizeSigRows();
	$('#sigTable').trigger('update');
}

siggymain.prototype.updateSystemInfo = function (systemData)
{
	$('#region').text(systemData.regionName);
	$('#constellation').text(systemData.constellationName);
	$('#planetsmoons').text(systemData.planets + "/" + systemData.moons + "/" + systemData.belts);
	$('#truesec').text(systemData.truesec.substr(0,8));
	$('#radius').text(systemData.radius + ' AU');
	
	var hubJumpsStr = '';
	for(var index in systemData.hubJumps)
	{
        var hub = systemData.hubJumps[index];
        hubJumpsStr += "<div>"+hub.destination_name + " (" + hub.num_jumps + " jumps)</div>";
	}
	$('#hubJumps').html(hubJumpsStr);

	var collaspedInfoEffectStatic = $('#collaspedInfoEffectStatic');
	collaspedInfoEffectStatic.empty();
	$('#systemInfo-collasped p.spacer').hide();
	
	//effect info
	$('#systemEffect').empty();
	
	
	var effectTitle = $("<p>").text(systemData.effectTitle);
	var effect = $('#systemEffect').append(effectTitle);
	var effectInfo = '';
	
	var collaspedEffectTitle = $("<span>").text( (systemData.effectTitle == 'None' ? '': systemData.effectTitle) );
	
	if( systemData.effectTitle != 'None' )
	{
		effectInfo += '<b>Class '+systemData.sysClass+' Effects</b><br /><br />';
		
		if( systemData.effectTitle == 'Black Hole' )
		{	
			var effData = blackHoleEffects[systemData.sysClass];
		}
{'fraction_non_alphanumeric': 0.21246956226286878, 'fraction_numerical': 0.04973856579270249, 'mean_word_length': 3.302607000730935, 'pattern_counts': {'":': 4, '<': 48, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1575916', 'n_tokens_mistral': 24772, 'n_tokens_neox': 20698, 'n_words': 4866}