scripted_gui = {

	rival_country_gui = {
		context_type = selected_country_context
		window_name = "rival_country_gui"
		parent_window_token = selected_country_view_info

		visible = {
			THIS = { has_variable = rival_country }
		}

		effects = {
			flag_frame_click = {
				clear_variable = ppcostaddrival
				clear_variable = ppcostaddrival1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button = 1 }
					subtract_from_temp_variable = { show_button = show_rivals_button }
					set_variable = { show_rivals_button = show_button }
					clear_array = Root.potential_rivals_array
					clear_array = Root.potential_rivals_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 8
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
								var = this.score_array_position_var
								value = 16
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 16
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								AND = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
				}
			}
			add_rival_button_click = {
				clear_variable = ppcostaddrival
				clear_variable = ppcostaddrival1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button = 1 }
					subtract_from_temp_variable = { show_button = show_rivals_button }
					set_variable = { show_rivals_button = show_button }
					clear_array = Root.potential_rivals_array
					clear_array = Root.potential_rivals_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 8
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 16
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								AND = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
				}
			}
		}

		dynamic_lists = {
		}
		properties = {
			flag = { image = "[?rival_country.GetFlag]" }
		}

		triggers = {
			add_rival_button_visible = {
				NOT = {
					has_variable = rival_country
				}
			}
			flag_visible = {
				has_variable = rival_country
			}
			flag_frame_visible = {
				has_variable = rival_country
			}
		}

		ai_enabled = {
			always = no
		}
	}
	rival_country_gui_lar = {
		context_type = selected_country_context
		window_name = "rival_country_gui_lar"
		parent_window_name = rivals_and_favours_container

		visible = {
			THIS = { has_variable = rival_country }
			#has_dlc = "la Resistance"
		}

		effects = {
			flag_frame_click = {
				clear_variable = ppcostaddrival
				clear_variable = ppcostaddrival1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button = 1 }
					subtract_from_temp_variable = { show_button = show_rivals_button }
					set_variable = { show_rivals_button = show_button }
					clear_array = Root.potential_rivals_array
					clear_array = Root.potential_rivals_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 8
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 16
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								AND = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
				}
			}
			add_rival_button_click = {
				clear_variable = ppcostaddrival
				clear_variable = ppcostaddrival1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button = 1 }
					subtract_from_temp_variable = { show_button = show_rivals_button }
					set_variable = { show_rivals_button = show_button }
					clear_array = Root.potential_rivals_array
					clear_array = Root.potential_rivals_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 8
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 16
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								AND = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
								}
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_rivals_array = This.id }
							add_to_array = {
								array = Root.potential_rivals_check_array
								index = Root.potential_rivals_array
								value = 0
							}
						}
					}
				}
			}
		}

		dynamic_lists = {
		}
		properties = {
			flag = { image = "[?rival_country.GetFlag]" }
		}

		triggers = {
			add_rival_button_visible = {
				NOT = {
					has_variable = rival_country
				}
			}
			flag_visible = {
				has_variable = rival_country
			}
			flag_frame_visible = {
				has_variable = rival_country
			}
		}

		ai_enabled = {
			always = no
		}
	}

	rival_country3_gui = {
		context_type = player_context
		window_name = "rival_country3_gui"
		#parent_window_token = selected_country_view_info

		visible = {
			check_variable = { show_rivals_button > 0 }
		}

		effects = {
			flag_click = {
				clear_variable = ppcostaddrival
				clear_variable = ppcostaddrival1
				set_variable = { ppcostaddrival = -200 }
				if = {
					limit = {
						var:potential_rivals_array^i = {
							any_owned_state = {
								OR = {
									is_claimed_by = ROOT.ROOT
									is_core_of = ROOT
								}
							}
						}
					}
					add_to_variable = { ppcostaddrival = 50 }
				}
				set_variable = { ppcostaddrival1 = ppcostaddrival }
				multiply_variable = { ppcostaddrival1 = -1 }
				set_temp_variable = { index = i }
				for_each_loop = {
					array = Root.potential_rivals_array

					set_variable = { Root.potential_rivals_check_array^i = 0 }
				}
				set_variable = { Root.potential_rivals_check_array^index = 1 }
				#set_variable = { rival_country = v }
			}
			confirm_click = {
				add_political_power = var:ppcostaddrival
				set_country_flag = eoanbdiplomacy_rival_cooldown
					country_event = {
						id = eoanbdiplomacy.1
						days = 1825
					}
				if = {
					limit = {
						has_variable = rival_country
					}
					meta_effect = {
						text = {
							remove_opinion_modifier = {
								target = [RIVAL]
								modifier = rival_country
							}
						}
						RIVAL = "[?rival_country.GetTag]"
					}
				}
				set_variable = { rival_country =  Root.potential_rivals_array^i }
				meta_effect = {
					text = {
						add_opinion_modifier = {
							target = [RIVAL]
							modifier = rival_country
						}
					}
					RIVAL = "[?rival_country.GetTag]"
				}
			}
			close_button_click = {
				set_temp_variable = { show_button = 1 }
				subtract_from_temp_variable = { show_button = show_rivals_button }
				set_variable = { show_rivals_button = show_button }
			}
		}

		dynamic_lists = {
			show_grid = {
				array = Root.potential_rivals_array
				entry_container = show_entry_potential_rivals
			}
		}
		properties = {
			flag = { image = "[?Root.potential_rivals_array^i.GetFlag]" }
		}

		triggers = {
			confirm_visible = {
				var:potential_rivals_array^i  = {
					check_variable = { Root.potential_rivals_check_array^i = 1 }
				}
			}
			confirm_click_enabled = {
				ROOT = {
				  	NOT = {
						has_country_flag = eoanbdiplomacy_rival_cooldown
					}
					has_political_power > var:ppcostaddrival1
				}
				var:potential_rivals_array^i = {
					NOT = {
						OR = {
							has_non_aggression_pact_with = ROOT
							is_in_faction_with = ROOT
							has_guaranteed = ROOT
							is_puppet_of = ROOT
							is_subject_of = ROOT
							has_opinion = {
								target = ROOT
								value > 9
							}
						}
					}
				}
			}
		}

		ai_enabled = {
			always = no
		}
	}

	favourite_country_gui = {
		context_type = selected_country_context
		window_name = "favoured_country_gui"
		parent_window_token = selected_country_view_info

		visible = {
			THIS = { has_variable = most_favoured_country }
		}

		effects = {
			flag_frame2_click = {
				clear_variable = ppcostaddmostfavoured
				clear_variable = ppcostaddmostfavoured1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button2 = 1 }
					subtract_from_temp_variable = { show_button2 = show_most_favoured_button }
					set_variable = { show_most_favoured_button = show_button2 }
					clear_array = Root.potential_most_favoured_array
					clear_array = Root.potential_most_favoured_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 8
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 16
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								is_neighbor_of = ROOT
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
				}
			}
		   add_most_favoured_button_click = {
				clear_variable = ppcostaddmostfavoured
				clear_variable = ppcostaddmostfavoured1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button2 = 1 }
					subtract_from_temp_variable = { show_button2 = show_most_favoured_button }
					set_variable = { show_most_favoured_button = show_button2 }
					clear_array = Root.potential_most_favoured_array
					clear_array = Root.potential_most_favoured_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 8
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 16
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								is_neighbor_of = ROOT
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
				}
			}
		}

		dynamic_lists = {
		}
		properties = {
			flag2 = { image = "[?This.most_favoured_country.GetFlag]" }
		}

		triggers = {
			add_most_favoured_button_visible = {
				NOT = {
					has_variable = most_favoured_country
				}
			}
			flag2_visible = {
				has_variable = most_favoured_country
			}
			flag_frame2_visible = {
				has_variable = most_favoured_country
			}
		}

		ai_enabled = {
			always = no
		}

		ai_weights = {
		}
	}

	favourite_country_gui_lar = {
		context_type = selected_country_context
		window_name = "favoured_country_gui_lar"
		parent_window_name = rivals_and_favours_container

		visible = {
			THIS = { has_variable = most_favoured_country }
		}

		effects = {
			flag_frame2_click = {
				clear_variable = ppcostaddmostfavoured
				clear_variable = ppcostaddmostfavoured1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button2 = 1 }
					subtract_from_temp_variable = { show_button2 = show_most_favoured_button }
					set_variable = { show_most_favoured_button = show_button2 }
					clear_array = Root.potential_most_favoured_array
					clear_array = Root.potential_most_favoured_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 8
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 16
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								is_neighbor_of = ROOT
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
				}
			}
		   add_most_favoured_button_click = {
				clear_variable = ppcostaddmostfavoured
				clear_variable = ppcostaddmostfavoured1
				if = {
					limit = {
						check_variable = { This.id = Root.id }
					}
					set_temp_variable = { show_button2 = 1 }
					subtract_from_temp_variable = { show_button2 = show_most_favoured_button }
					set_variable = { show_most_favoured_button = show_button2 }
					clear_array = Root.potential_most_favoured_array
					clear_array = Root.potential_most_favoured_check_array
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 8
								compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 8
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  8 }
							check_variable = {
							var = this.score_array_position_var
							value = 16
							compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								OR = {
									check_variable = {
										var = this.score_array_position_var
										value = 16
										compare = less_than_or_equals
									}
									is_neighbor_of = ROOT
								}
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = { this.score_array_position_var >  16 }
							check_variable = {
							   	var = this.score_array_position_var
								value = 40
							 	compare = less_than_or_equals
							}
						}
						every_country = {
							limit = {
								check_variable = {
									var = this.score_array_position_var
									value = 40
									compare = less_than_or_equals
								}
								is_neighbor_of = ROOT
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
					if = {
						limit = {
							check_variable = {
								var = this.score_array_position_var
								value = 40
								compare = greater_than
							}
						}
						every_country = {
							limit = {
								NOT = {
									OR = {
										is_puppet = yes
										is_subject = yes
										check_variable = { This.id = Root.id }
										check_variable = { This.id = Root.rival_country }
										check_variable = { This.id = Root.most_favoured_country }
									}
								}
								is_neighbor_of = ROOT
							}
							add_to_array = { Root.potential_most_favoured_array = This.id }
							add_to_array = {
								array = Root.potential_most_favoured_check_array
								index = Root.potential_most_favoured_array
								value = 0
							}
						}
					}
				}
			}
		}

		dynamic_lists = {
		}
		properties = {
			flag2 = { image = "[?This.most_favoured_country.GetFlag]" }
		}

		triggers = {
			add_most_favoured_button_visible = {
				NOT = {
					has_variable = most_favoured_country
				}
			}
			flag2_visible = {
				has_variable = most_favoured_country
			}
			flag_frame2_visible = {
				has_variable = most_favoured_country
			}
		}

		ai_enabled = {
			always = no
		}

		ai_weights = {
		}
	}

	favourite_country3_gui = {
		context_type = player_context
		window_name = "favoured_country3_gui"
		#parent_window_token = selected_country_view_info

		visible = {
			check_variable = { show_most_favoured_button > 0 }
		}

		effects = {
			flag_click = {
				clear_variable = ppcostaddmostfavoured
				clear_variable = ppcostaddmostfavoured1
				set_variable = { ppcostaddmostfavoured = -200 }
				if = {
					limit = {
						var:potential_most_favoured_array^i = {
							any_owned_state = {
								OR = {
									is_claimed_by = ROOT.ROOT
									is_core_of = ROOT
								}
							}
						}
					}
					add_to_variable = { ppcostaddmostfavoured = 50 }
				}
				set_variable = { ppcostaddmostfavoured1 = ppcostaddmostfavoured }
				multiply_variable = { ppcostaddmostfavoured1 = -1 }
				set_temp_variable = { index = i }
				for_each_loop = {
					array = Root.potential_most_favoured_array

					set_variable = { Root.potential_most_favoured_check_array^i = 0 }
				}
				set_variable = { Root.potential_most_favoured_check_array^index = 1 }
				#set_variable = { rival_country = v }
			}
			confirm_click = {
				add_political_power = var:ppcostaddmostfavoured
				set_country_flag = eoanbdiplomacy_most_favoured_cooldown
					country_event = {
						id = eoanbdiplomacy.3
						days = 1825
					}
				if = {
					limit = {
						has_variable = most_favoured_country
					}
					meta_effect = {
						text = {
							remove_opinion_modifier = {
								target = [MOST_FAVOURED]
								modifier = most_favoured_country
							}
						}
						MOST_FAVOURED = "[?most_favoured_country.GetTag]"
					}
				}
				set_variable = { most_favoured_country =  Root.potential_most_favoured_array^i }
				meta_effect = {
					text = {
						add_opinion_modifier = {
							target = [MOST_FAVOURED]
							modifier = most_favoured_country
						}
					}
					MOST_FAVOURED = "[?most_favoured_country.GetTag]"
				}
			}
			close_button_click = {
				set_temp_variable = { show_button2 = 1 }
				subtract_from_temp_variable = { show_button2 = show_most_favoured_button }
				set_variable = { show_most_favoured_button = show_button2 }
			}
		}

		dynamic_lists = {
			show_grid = {
				array = Root.potential_most_favoured_array
				entry_container = show_entry_potential_most_favoured
			}
		}
		properties = {
			flag = { image = "[?Root.potential_most_favoured_array^i.GetFlag]" }
		}

		triggers = {
			confirm_visible = {
				var:potential_most_favoured_array^i  = {
					check_variable = { Root.potential_most_favoured_check_array^i = 1 }
				}
			}
			confirm_click_enabled = {
				ROOT = {
				  	NOT = {
						has_country_flag = eoanbdiplomacy_most_favoured_cooldown
					}
					has_political_power > var:ppcostaddmostfavoured1
				}
				var:potential_most_favoured_array^i = {
					OR = {
						has_non_aggression_pact_with = ROOT
						is_in_faction_with = ROOT
						has_guaranteed = ROOT
						is_puppet_of = ROOT
						is_subject_of = ROOT
 						has_opinion = {
							target = ROOT
							value > 9
						}
					}
				}
			}
		}

		ai_enabled = {
			always = no
		}
	}

	#topbar_modded_tension = { # Spits an error
	#    context_type = player_context
	#	window_name = "topbar_tension_modded"
	#	parent_window_name = "topbar"
	#
	#	visible = {
	#	    is_ai = no
	#	}
	#
	#	effects = {
	#	}
	#
	#	dynamic_lists = {
	#	}
	#	properties = {
	#	}
	#
	#	triggers = {
	#	}
#
	#	ai_weights = {
	#	}
	#	ai_enabled = {
	#	    always = no
	#	}
	#}

	# justify_wargoal_gui = {
		# context_type = selected_country_context
		# window_name = "justify_wargoal"

		# visible = {
			# check_variable = {
				# show_justify_war_var > 0
			# }
		# }

		# effects = {
			# # enemies_button1_click = {
				# # THIS = {
					# # set_temp_variable = { show_button^i = 2 }
					# # subtract_from_temp_variable = { show_button^i = show_enemies_button_1^i }
					# # set_variable = { show_enemies_button_1^i = show_button^i }
					# # add_to_array = { enemies_array_call_temp = Root.enemies^i }
				# # }
			# # }
		# }

		# dynamic_lists = {
			# show_grid = {
				# array = This.wargoals_temp_array
				# entry_container = show_entry_war_goals
			# }
		# }
		# properties = {
			# # flag = { image = "[?Root.enemies^i.GetFlag]" }
			# # enemies_button1 = { frame = show_enemies_button_1^i }
		# }

		# triggers = {
		# }

		# ai_weights = {
		# }
		# ai_enabled = {
			# always = no
		# }
	# }
}