﻿var common =
{
	show: false,

	init: function() {

		//Hides the dropdownlist "Se alla Resor" and moves the image over in it´s place
		$(".allaResorCover").removeClass("transparent");
		$(".allaResor").addClass("transparent");
		// MouseClick Återförsäljar-Login
		$("#header-right-bottom img").click(function() {
			$("#af-login").css("display", "block");
		});
		$("#af-login").mouseleave(function() {
			$("#af-login").css("display", "none");
		});

		//Print Link

		$(".print a").click(function() {
			window.print();
		});

		$(".right-image").click(function() {

			var src = $(this).attr("src");
			$(".left-image").attr("src", src);
		});


		//Check if cookie is saved

		/*
		if (document.cookie.length > 0) 
		{
		var c_start = document.cookie.indexOf("content=");
		if (c_start != -1) {
		var c_end = document.cookie.indexOf(";", c_start);

                if (c_end == -1) {
		c_end = document.cookie.length;
		}

                var value = document.cookie.substring(c_start, c_end).split("=");
		var access = value[value.length - 1];

                $("#" + thatID + " .module-middle-wide").addClass("NotVisible");

            }
        
		var c_start = document.cookie.indexOf("menuchoice=");
		if (c_start != -1) {
		var c_end = document.cookie.indexOf(";", c_start);

                if (c_end == -1) {
		c_end = document.cookie.length;
		}

                var value = document.cookie.substring(c_start, c_end).split("=");
		var id = value[value.length - 1];

                var a = $("a#" + id).parent().parent().attr("id");


		$("#" + a + " a").removeClass("active");
		$("a#" + id).addClass("active");


		$("." + id).removeClass("NotVisible");
		}  
		}
		*/


		$(".fast-menu-links a").click(function() {
			var id = $(this).attr("class");
			var a = $("a#" + id).parent().parent().attr("id");
			if (a == "program") {
				$("#" + a + " a").removeClass("active");
				$("a#" + id).addClass("active");
				var thatID = $("a#" + id).attr("accesskey");
				$("#" + thatID + " .module-middle").addClass("NotVisible");
				$("." + id).removeClass("NotVisible");

			}

			//Set Cookie
			//document.cookie = "menuchoice=" + escape(id);
			//document.cookie = "content=" + escape(thatID);
		});

		$(".travelsite-menu a").click(function() {

			var id = $("#" + this.id).parent().parent().attr("id");
			var thisID = this.id;
			$("#" + id + " a").removeClass("active");
			$(this).addClass("active");

			var thatID = $(this).attr("accesskey");
			$("#" + thatID + " .module-middle-wide").addClass("NotVisible");
			$("#" + thatID + " .module-middle").addClass("NotVisible");
			
			thisID += "Div";
			$("#" + thisID).removeClass("NotVisible");
						
			//Set Cookie
			//document.cookie = "menuchoice=" + escape(this.id);
			//document.cookie = "content=" + escape(thatID);
		});

		//var position = $(".top-navigation .selected").position();

		$(".sub-nav-div").css("position", "absolute");
		//$(".sub-nav-div").css("left", position.left + "px");
		//$(".sub-nav-div").css("display", "none");

		$(".top-menu-choice").mouseover(function() {
			var id = this.id;
			var currentWidth = 200;

			$("#" + id).addClass("selected");
			$("#div-" + this.id).css("display", "block");
			$("#img-" + id).removeClass("NotVisible");

			// The wider column menu for våra resor			
			if (id == 926 || id == 18 || id == 905) {
				currentWidth = $(".menu-middle").width();
				//$("#div-" + id + " li").addClass("usesColumn");
			}
			$("#div-" + id).width(currentWidth);
			$(".middlemenu").width(currentWidth + 23);
			// Makes sure the full gradient is displayed
			$(".clearTopMenu").height("0px");
			var height79 = $('#div-' + id).height();

			if (height79 < 79)
				$(".clearTopMenu").height(79 - height79);
			else
				$(".clearTopMenu").height(10);

			//Mouseover på diven
			$("#div-" + this.id).mouseover(function() {

				$("#" + id).addClass("selected");
				$("#div-" + id).css("display", "block");
				$("#img-" + id).removeClass("NotVisible");

				//Mouseout på diven
				$("#div-" + this.id).mouseout(function() {

					$("#div-" + id).css("display", "none");
					$("#" + id).removeClass("selected");
					$("#img-" + id).addClass("NotVisible");
				});
			});

			//Mouseout knappen
			$("#" + this.id).mouseout(function() {


				$("#div-" + id).css("display", "none");
				$("#" + id).removeClass("selected");
				$("#img-" + id).addClass("NotVisible");
			});

		});

	},

	getUrlEncodedKey: function(key, query) {
		if (!query)
			query = window.location.search;
		var re = new RegExp("[?|&]" + key + "=(.*?)&");
		var matches = re.exec(query + "&");
		if (!matches || matches.length < 2)
			return "";
		return decodeURIComponent(matches[1].replace("+", " "));
	},

	setUrlEncodedKey: function(key, value, query) {

		query = query || window.location.search;
		var q = query + "&";
		var re = new RegExp("[?|&]" + key + "=.*?&");
		if (!re.test(q))
			q += key + "=" + encodeURI(value);
		else
			q = q.replace(re, "&" + key + "=" + encodeURIComponent(value) + "&");
		q = q.trimStart("&").trimEnd("&");
		return q[0] == "?" ? q : q = "?" + q;
	}




}


window.onload = common.init;



