(function () {
	var app = angular.module("app");
	app.controller('HeaderController', Controller);
	Controller.$inject = ['$scope', '$timeout', '$http'];

	function Controller($scope, $timeout, $http) {
		var vm = this;
		vm.activeLanguage = "en";
		vm.hideLanguageDropdownIntgrtn = false;

		if (window.location.pathname.split("/")[1].length != 2 && window.location.pathname.split("/")[1].length != 0) {
			vm.customLocationPrefix = '/' + window.location.pathname.split("/")[1] + '/';
		}
		var waitIntgrtn = setInterval(function () {
			if (!window.intgrtn) {
				return false;
			}
			clearInterval(waitIntgrtn);
			if (window.intgrtn.lookup("hideLanguageDropdown", true)) {
				vm.hideLanguageDropdownIntgrtn = true;
				$scope.$applyAsync();
			}
			var reversedLocationPathArray = window.location.pathname.split("/").reverse();
			vm.activeLanguage = reversedLocationPathArray[0] != "lp.php" ? reversedLocationPathArray[1] : "en";
			$scope.$applyAsync();
		}, 10);

		vm.languages = [
			{
				name: "English",
				flagPath: "images/flags/gb.png?v=2",
				locationPrefix: vm.customLocationPrefix ? vm.customLocationPrefix : "/",
				code: 'en',
				locationText: 'EXCLUSIVE EXPOSURE FOR',
			},
			{
				name: "Swedish",
				flagPath: "images/flags/se.png",
				locationPrefix: "se/",
				code: "se",
				locationText: 'EXKLUSIV EXPONERING FÖR',
			},
			{
				name: "Deutsch",
				flagPath: "images/flags/de.png",
				locationPrefix: "de/",
				code: "de",
				locationText: 'EXKLUSIVE AUSGABE FÜR',
			},
			{
				name: "Spanish",
				flagPath: "images/flags/es.png",
				locationPrefix: "es/",
				code: "es",
				locationText: 'EXPOSICIÓN EXCLUSIVA PARA',
			},
			{
				name: "Portuguese",
				flagPath: "images/flags/pt.png",
				locationPrefix: "pt/",
				code: "pt",
				locationText: 'EXPOSIÇÃO EXCLUSIVA PARA',
			},
			{
				name: "Norwegian",
				flagPath: "images/flags/no.png",
				locationPrefix: "no/",
				code: "no",
				locationText: 'EKSKLUSIV TILGANG FOR',
			},
			{
				name: "Italian",
				flagPath: "images/flags/it.png",
				locationPrefix: "it/",
				code: "it",
				locationText: 'OFFERTA ESCLUSIVA PER',
			},
			{
				name: "Dutch",
				flagPath: "images/flags/nl.png",
				locationPrefix: "nl/",
				code: "nl",
				locationText: 'OFFERTA ESCLUSIVA PER',
			},
			{
				name: "Russian",
				flagPath: "images/flags/ru.png",
				locationPrefix: "ru/",
				code: "ru",
				locationText: 'ЭКСКЛЮЗИВНО ДЛЯ',
			},
			{
				name: "Finnish",
				flagPath: "images/flags/fi.png",
				locationPrefix: "fl/",
				code: "fl",
				locationText: 'EKSKLUSIIVISIA ASEMIA',
			},
			{
				name: "Danish",
				flagPath: "images/flags/dk.png",
				locationPrefix: "dk/",
				code: "dk",
				locationText: 'EKSKLUSIV EKSPONERING FOR',
			},
			{
				name: "French",
				flagPath: "images/flags/fr.png",
				locationPrefix: "fr/",
				code: "fr",
				locationText: 'EXPOSITION EXCLUSIVE POUR',
			},
			{
				name: "Arabic",
				flagPath: "images/flags/ae.png",
				locationPrefix: "gcc/",
				code: "gcc",
				locationText: 'اعلان حصري لسكان',
			}
		];
	}
}());