/////////////////////
// Tooltip.js
// Contains all tooltip information and stuff
// (C) 2010 SnapperTheTwig AKA Liam Twigger

/////////
// Variables
var TT = new Array();
var mouseX = 0;
var mouseY = 0;
X_OFF = 16;
Y_OFF = 16;

/////////////////////////
// Tooltip text strings

//UNIT STATS
US_GA = 1;	//Ground Attack
US_AA = 2;	//Air Attack
US_AP = 3;	//Armour Attack
US_DM = 4;	//Defence Multiplier
US_SP = 5;	//Shield Attack
US_AR = 6;	//Armour
US_S  = 7;	//Speed
US_R  = 8;	//Range
US_MR = 9;	//Min-Range
US_RT = 10;	//Reload Time
US_TC = 11;	//Transport Capacity
US_OR = 12;	//Operational range
US_SI = 20;	//Unit Size
US_SH = 21; //Unit Shield
US_IA = 22; //Unit Shield
US_LO = 23; //Unit Shield
US_LS = 24; //Line of sight
US_CP = 25; //Contingency Plan
US_AS = 26; //Poised to assist in
US_UL = 27; //Unit unlock
US_UJ = 28; //Unit jump
US_FA = 29; //Unit flags
US_EX = 30; //unit exp

TT[US_GA] = 'Ground Attack: How much damage this unit can dish out to ground units when it fires its weapons. Sea units are also classed within this category';
TT[US_AA] = 'Air Attack: How much damage this unit can dish out to air units when it fires its weapons. Spacecraft are also classed within this category.';
TT[US_AP] = 'Armour Attack: What percentage of this units attack is used to attack armour.';
TT[US_DM] = 'Defence multiplier for this unit. I.e., a value of "2x" will mean that this unit receives half damage.';
TT[US_SP] = 'Shield Attack: What percentage of this units attack is used to attack shields.';
TT[US_AR] = 'Armour Rating: How armoured is this unit? Armour will protect against regular damage, but will make it more vulnerable to armour Attack';
TT[US_S ] = 'Speed of the unit, in kilometres per hour.';
TT[US_R ] = 'Range of the unit in metres. Units must lower their distance to their target to this value in order to attack it.';
TT[US_MR] = 'Minimum range of this unit, in meters. If its target is too close, it will be unable to attack it.';
TT[US_RT] = 'How many minutes must this unit idle between attacks.';
TT[US_TC] = 'How many units can this unit carry on-board.';
TT[US_SI] = 'Unit size/HP. For units with only one member, this is refereed to as HP. This units fighting ability is scaled by its size. I.e., a unit with 50% of its total size/HP will fight at 50% efficiency. If this value reaches zero, the unit is destroyed.';
TT[US_SH] = 'Energy shields on the unit. Energy shields prevent damage from hitting the unit. The effectiveness of energy shields is scaled by shield strength and unit strength. I.e., a unit with its shields at 50% at 100% strength will block 50% of damage, a unit with shields at 20% at 40% strength will also block 50% of damage.';
TT[US_OR] = 'How far can this air unit travel. I.e., an air unit that can fly 3 tiles can move attack targets 3 provinces away from where its based. Air units can also rebase to provinces 3 times this distance away.';
TT[US_IA] = 'Installation Attack: How much damage this unit can do to infrastructure, resource extraction and anti-air installations in a province.';
TT[US_LO] = 'How many slots on does this unit consume of a transport/airbase.'; 
TT[US_LS] = 'How far away an approaching unit has to be in order to be spotted. Your units will target and engage enemy units in a normal defending battle when an approaching unit enters any of your units\' line of sight.';
TT[US_CP] = 'What this unit will do when its morale reaches zero in a defensive battle.';
TT[US_AS] = 'What province this unit will assist in if an ally launches a mission on it.';
TT[US_UL] = 'When you order a mission on a unit it will become locked for a period of time. When it becomes unlocked you will be able conduct other missions with it.';
TT[US_UJ] = 'When you perform a hyperspace jump with a unit it will become unable to perform another jump for a period of time. When it becomes unlocked you will be able to perform more hyperspace jumps with it.';
TT[US_FA] = 'Flags set for this unit.';
TT[US_EX] = 'Experience points for this unit. Units gain exp during combat and level up accordingly. Units gain an atk/def bonus dependent on their level.';

//UNIT FLAGS
UF_KA = 101;
UF_HS = 102;
UF_ST = 103;
UF_BI = 104;
UF_HE = 105;
UF_SD = 106;
UF_CC = 107;
UF_4D = 108;
UF_DH = 109;

TT[UF_KA] = 'Does this unit take losses every time it attacks another unit?';
TT[UF_HS] = 'Can this unit make Hyperspace Jumps? Hyperspace jumps allow the unit to move instantaneously from one place to another.';
TT[UF_ST] = 'Stealth units are invisible to other players on the map. No in-battle effect.';
TT[UF_BI] = 'Is this unit made of people/other biological organisms? Some units are more effective against others due to this property.';
TT[UF_HE] = 'Can this unit self-heal? If so, it will recover losses every update.';
TT[UF_SD] = 'Can this unit detect stealth units in its or adjacent provinces? Displays discovered units on the map. No in-battle effect.';
TT[UF_CC] = 'Can this unit be Rebased to an Aircraft Carrier?';
TT[UF_4D] = 'Does this unit get a 4x defence bonus when defending a city or base?';
TT[UF_DH] = 'If this unit can repair/self-heal, then this unit\'s natural regeneration rate is doubled.';

UF_DNRP = 151;
UF_DNRC = 152;
UF_PIRP = 153;
UF_PIRC = 154;
UF_ACAW = 156;
UF_IAPT = 157;

TT[UF_DNRP] = 'A unit with Do Not Repair checked will not use repair docks to repair, but will self heal if possible.';
TT[UF_DNRC] = 'A unit with Do Not Recharge checked will not use shield rechargers to recharge energy shields, but will self-recharge them over time.';
TT[UF_PIRP] = 'A unit with Prioritised Repair checked will use repair docks in preference to other units.';
TT[UF_PIRC] = 'A unit with Prioritised Recharge checked will use shield rechargers in preference to other units.';
TT[UF_ACAW] = 'A unit with Allied Control Allowed checked will be usable by allies, providing that they have the permissions to use allied units.';
TT[UF_IAPT] = 'Is this unit conducting an air patrol mission? Note that you can\'t set this flag explicitly, this is for informative purposes only.';

////////////////////
// Production
PR_WI = 201; //Working ind
PR_BI = 202; //Base ind
PR_PS = 203; //Production slots
PR_PA = 204; //Pause
PR_CA = 205; //Cancel
PR_FC = 206; //Force completion

TT[PR_WI] = 'Working Industry: how many levels of production your factories can create an update, after modifiers. These levels are split evenly amongst all production runs in the city. The number in brackets is the working industry before technology bonuses.';
TT[PR_BI] = 'Base Industry: How many levels of industry are in this city?';
TT[PR_PS] = 'How many runs can you have in this city simultaneously? The number of production slots a city has is based on the city\'s base industry.';
TT[PR_PA] = 'Pause: If a run is paused then it will not receive any levels on update. Levels are diverted to other runs.';
TT[PR_CA] = 'Cancel: You may cancel a run. You will be refunded all the manpower spent of the run, but only part of the money spent on it.';
TT[PR_FC] = 'Prioritise run. All levels will be spent on prioritised runs in preference to other runs.';

////////////////////
// Diplomacy

//Country stuff
CY_AL = 801; 	//Alliance
CY_CC = 802;	//Capital City
CY_GV = 803;	//Government
CY_FA = 804;	//Faction
CY_PR = 805;	//Prestige
CY_KA = 806;	//Karma
CY_MU = 807;	//MU
CY_BB = 808;	//MU
TT[CY_AL] = 'Alliance: Which alliance is this country a member of?';
TT[CY_CC] = 'Capital City of this country. Has no function in-game.';
TT[CY_GV] = 'Government type of this country. Has no function in-game.';
TT[CY_FA] = 'Which faction (Gamer, Evil or Republic) does this country belong to? Different factions produce different kinds of units.';
TT[CY_PR] = 'Prestige: How much influence the country has in terms of might. Determined by how much territory this country holds. For ranking purposes only.';
TT[CY_KA] = 'Karma: How popular a country is with the international community. Aggressive acts lower karma, being peaceful raises it. Negative karma will affect dissent in the cities.';
TT[CY_MU] = 'Military Units: How many units this country has, and its unit cap. Countries that are over their unit cap suffer severe attacking and defending penalties.';
TT[CY_BB] = 'Bases Built: How many bases you are have built and how many you are allowed to build.';

//Alliance stuff
AL_PW = 1001;
AL_LE = 1002;
TT[AL_PW] = 'Alliance Password: Alliances work like tree-houses. If you know the password, you can come in.';
TT[AL_LE] = 'Alliance Leader: The alliance leader can kick members, view/change the password and description and set the permissions of members.';

/////////////////
// MISC
SY_LA = 1101;
TT[SY_LA] = 'Player has been active in the last ten minutes.';

/////////////////
// Battle/Mission icons
MI_START = 2000;
MI_AK = 2000;	//Attack
MI_EK = 2001;	//Enemy Attack
MI_IN = 2002;	//Information
MI_AL = 2003;	//Alert
MI_FL = 2004;	//Flee
MI_TA = 2005; 	//Target
MI_CI = 2006;	//Closed In
MI_AP = 2007;	//Position
MI_EP = 2008;	//Enemy position

TT[MI_AK] = 'Your units attacked the enemy.';
TT[MI_EK] = 'Enemy units attacked us.';
TT[MI_IN] = 'Information.';
TT[MI_AL] = 'Alert!';
TT[MI_TA] = 'A unit has targeted another unit, and will peruse and engage it.';
TT[MI_CI] = 'A unit is now in firing range of its target.';
TT[MI_AP] = 'The positions of all your units.';
TT[MI_EP] = 'The positions of enemy units.';

//////////////////
// Clawtab flags
CT_FM = 301;
CT_FA = 302;
CT_TC = 303;
CT_TA = 304;
CT_MS = 305;

CT_AA = 306;
CT_IN = 307;
CT_RE = 308;
CT_DF = 309;

TT[CT_FM] = 'Force Move';
TT[CT_FA] = 'Force Attack';
TT[CT_TC] = 'Take Control';
TT[CT_TA] = 'Target All';
TT[CT_MS] = 'Multistage Move - This job was automatically scheduled through a move mission.';

TT[CT_AA] = 'Targeting AA';
TT[CT_IN] = 'Targeting Infrastructure';
TT[CT_RE] = 'Targeting Resources';
TT[CT_DF] = 'Targeting DFGs';
		
////////////////
// City Stuff
CI_WP = 401;
CI_JB = 402;
CI_EM = 403;
CI_UE = 404;
CI_IN = 405;
CI_CM = 406;
CI_IF = 407;
CI_IL = 408;
CI_DI = 409;

CI_AB = 410;
CI_DO = 411;
CI_AL = 412;
CI_SD = 413;
CI_CC = 414;
CI_LA = 417;
CI_RD = 415;
CI_SR = 416;

TT[CI_WP] = 'Size of the workforce in this city';
TT[CI_JB] = 'Number of jobs in the city, provided by industry and commerce. Each level of industry or commerce provides 1,000 jobs.';
TT[CI_EM] = 'Number of people employed city.';
TT[CI_UE] = 'Number of people unemployed in this city. High levels of unemployment hurt the productivity of the city, and a labour shortage will mean that industry and commerce will not be fully utilised.';
TT[CI_IN] = 'Base level of industry in the city, before modifiers. Industry consumes material and produces goods. Industry also builds things.';
TT[CI_CM] = 'Base level of commerce in the city, before modifiers. Commerce consumes goods and produces money.';
TT[CI_IF] = 'Level of infrastructure in the city (Current/Base). Infrastructure is required for maximum efficiency, it can be damaged by others in attacks, and automatically repairs when damaged.';
TT[CI_IL] = 'Amount of infrastructure the city requires.';
TT[CI_DI] = 'Level of dissent in the city.';

TT[CI_AB] = 'Airbase level (Current/Base). Different air units use different amounts of airbase capacity. The formula for the current level is BASE * INFRA / INFRA_LOAD, so one can effectively disable airbases by destroying infra.';
TT[CI_DO] = 'Does this city have docks? Docks are required for sea units to be built here.';
TT[CI_AL] = 'How loaded the airbases are in this city. Different air units require different loads.';
TT[CI_SD] = 'Number of supply docks in the city. Supplies convert goods into supplies for your units.';
TT[CI_CC] = 'Number of command centres in the city. Command centres increase your unit cap.';
TT[CI_LA] = 'Number of Labs in the city. Labs produce tech points, which can be spent on research.';
TT[CI_RD] = 'Number of repair docks in the city. Repair docks heal units in proportion the the number of production levels needed to make the unit.';
TT[CI_SR] = 'Number of shield rechargers in the city. Shield rechargers recharge energy shields on units.';

PP_FOS = 501;
PP_BJ = 502;
PP_FIS = 503;
PP_FUS = 504;
PP_SOL = 505;

TT[PP_FOS] = 'Fossil Power plants generate power and consume fossil.';
TT[PP_BJ] = 'Bogan Juice reactors generate power and consume goods.';
TT[PP_FUS] = 'Fusion Power plants generate power and consume material.';
TT[PP_FIS] = 'Fission Power plants generate power and consume material.';
TT[PP_SOL] = 'Solar cells generate power and consume nothing.';

CIM_I = 420;
CIM_D = 421;
CIM_P = 422;
CIM_L = 423;
CIM_A = 424;
CIM_O = 430;

TT[CIM_I] = 'Infrastructure Modifier = INFRA / INFRA_LOAD';
TT[CIM_D] = 'Dissent Modifier =  1 - DISSENT / 100%';
TT[CIM_P] = 'Power Modifier = POWER_PRODUCTION / POWER_CONSUMPTION. Note that this may be inaccurate, as a city that is low on power may drain power from the National Grid.';
TT[CIM_L] = 'The employment modifier simulates the effect of unemployment or a labour shortage on production. <br>Employment Modifier = { <br> (Jobs - 1000) / People, if (Jobs - 1000) &gt; People <br> (People - 1000) / Jobs, if (People - 1000) &gt; Jobs <br> 1, Otherwise <br>}';
TT[CIM_A] = 'The asymmetry modifier simulates the effect of a FIRE based economy (too commercially focused) or an over industrialised economy. <br>Asymmetry Modifier = { <br> Max((Com * 2),1) / Ind, if Ind > 2 * Com <br> Max((Ind * 2),1) / Com, if Com > 2 * Ind <br> 1, Otherwise <br>}';
TT[CIM_O] = 'Overall = Product of all modifiers';

/////////////////
// The function
function dtt(INDEX,OVERRIDE) {
	//Check that the index is valid
	if (TT[INDEX] == undefined && INDEX != -1)
		return 0;

	//Find the element
	ttElement = document.getElementById('tooltip');
	
	//If the element does not exist, create it!
	if (ttElement == undefined || ttElement == null) {
		ttElement = document.createElement('div');
		ttElement.setAttribute('id','tooltip');
		ttElement.setAttribute('class','tooltip');
		
		//Provide an onclick destruction mechanism
		ttElement.onclick = htt;
		
		//Add it to the document
		document.body.appendChild(ttElement);
		}
		
	//Show the element!
	ttElement.style.display = "block";
	
	//Width
	ttElement.style.width = '300px';

	//Set Position
	setPos();
	
	//Set the innerHTML to the text
	if (INDEX != -1)
		ttElement.innerHTML = TT[INDEX];
	else
		ttElement.innerHTML = OVERRIDE;
	}
	
function setPos () {
	//Position
	ttElement = document.getElementById('tooltip');
	if (ttElement == undefined || ttElement == null)
		return 0;
	ttElement.style.left = '' + (mouseX+X_OFF) + 'px';
	ttElement.style.top	 = '' + (mouseY+Y_OFF) + 'px';
	}
	
function htt() {
	//Find the element
	ttElement = document.getElementById('tooltip');

	//Kill pointer
	document.body.style.cursor='auto';
	
	//Hide it
	if (ttElement) {
		ttElement.style.display = "none";
		}
	}
	
// A mouseover function
function mo(INDEX,OVERRIDE) {
	//Set pointer
	document.body.style.cursor='pointer';
	
	//Do thingy
	dtt(INDEX,OVERRIDE);
	}
	
//Get mouse coordinates function
document.onmousemove = getMousePosition;

function  getMousePosition(e) {
    mouseX = e.pageX
    mouseY = e.pageY
	setPos();
	return true;
	}
	
//Tooltip function - generates a mouseover span
function tt (_text,_tag) {
	if (TOOLTIPS != null && TOOLTIPS != undefined && TOOLTIPS)
		return '<span class="tt" onmouseover="mo('+_tag+',\'\')" onmouseout="htt()">'+_text+'</span>';
	else
		return _text;
	}
	
//Allows override with custom text
function ttc (_text,_mouseover) {
	if (TOOLTIPS != null && TOOLTIPS != undefined && TOOLTIPS)
		return '<span class="tt" onmouseover="mo(-1,\''+_mouseover+'\')" onmouseout="htt()">'+_text+'</span>';
	else
		return _text;
	}
	
//Same as the above, but without the dotted underline
function tti (_text,_tag) {
	/*
	if (TOOLTIPS != null && TOOLTIPS != undefined && TOOLTIPS)
		return '<span class="tti" onmouseover="mo('+$tag+')" onmouseout="htt()">'+$_text+'</span>';
	else
	*/
	return _text;
	}

