jQuery.noConflict();

jQuery(document).ready(function($) {
	//  MSIE 6 only
	var IE6 = false;
	if($.browser.msie){
		if ($.browser.version < 7) {
			IE6 = true;
		}
		// IE stuff
		if(Object.prototype.toString.call(self.JSON) === "[object JSON]"){
			// IE8 stuff
		} else {
			// IE < 8 stuff
			$(".frontpage .cols .col5_5 .image ul li a").each(function() {
				$(this).text("\u00BB\u0020"+$(this).text());
			})
		}
/*
		$(document).not(":input,a").keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents('form').submit();
				return false;
			}
		});
*/
	}

	// nav tab animation  
	var navDuration = 150; //time in miliseconds
	var navJumpHeight = "2px";
	$('#level-1 li a').not(".selected")
		.bind("mouseenter focus", function(e) {
			$(this).stop().animate({ top: "-=" + navJumpHeight }, navDuration);
		})
		.bind("mouseleave blur", function(e) {
			$(this).stop().animate({ top: "5px" }, navDuration);
		})

	// Tabpanel		
	$("#tabs div.tab").hide(); // Hide all divs
	$("#tabs div.tab:first").show(); // Show the first div
	$("#tabs ul.navi li:first").addClass("active"); // Set the class of the first link to active
	$("#tabs ul.navi li a").click(function() { //When any link is clicked
		$("#tabs ul.navi li").removeClass("active"); // Remove active class from all links
		$(this).parent().addClass("active"); //Set clicked link class to active
		var currentTab = $(this).attr("href"); // Set variable currentTab to value of href attribute of clicked link
		$("#tabs div.tab").hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
	//	moreContentMenu
	var moreContentHeight = $("#moreContent > ul").height();
	$("#moreContent > ul").hide();
	var moreContentTimeout = null;
	var showMoreContentMenu = function() {
		clearTimeout(moreContentTimeout);
		if ($("#moreContent > ul").css("display") == "none") {
			$("#moreContent > ul").css({ height: "0" }).show().animate({ height: moreContentHeight }, 300);
		} else {
			$("#moreContent > ul").show();
		}
		if (IE6) {
			$("#page").addClass("hideSelects");
		}
	};
	var hideMoreContentMenu = function() {
		$("#moreContent >ul").fadeOut('fast');
		if (IE6) {
			$("#page").removeClass("hideSelects");
		}
		clearTimeout(moreContentTimeout);
	};
	// Events
	$("#moreContent > a").bind("mouseenter focus", function() {
		showMoreContentMenu();
	});
	$("#moreContent > ul").bind("mouseenter focus", function() {
		clearTimeout(moreContentTimeout);
		$("#moreContent > ul").show();
	});
	$("#moreContent > a, #moreContent > ul").bind("mouseleave blur", function() {
		moreContentTimeout = setTimeout(function() { hideMoreContentMenu() }, 500);
	});

	//  Search box
	if ($("#search input.text").length) {
		$("#search input.text")
		    .attr("value", $(".search input.text").attr("title"))
		    .focus(function() {
		    	if (this.value == this.title) {
		    		this.value = "";
		    	}
		    	$(this).addClass("active");
		    })
		    .blur(function() {
		    	if (this.value == "") {
		    		this.value = this.title;
		    	}
		    	$(this).removeClass("active");
		    });
	}

	// Select Box Jumper
	$("select.goto").selectJumper();

	$("#tools_textsize").click(function() {
		document.getElementsByTagName('body')[0].style.fontSize = '100%';
		return false;
	})

	// IE
	if ($.browser.msie) {
		$("body").append("<div id='tooltip'></div>");
		var bLang = navigator.browserLanguage;
		if (bLang != "da") {
			$("#tools_print").tooltip({ text: "<p>Således udskrives siden:</p><ol><li>Klik på browserens udskrifts ikon<br> (<strong>CTRL</strong> + <strong>P</strong>)</li></ol>" });
			$("#tools_textsize").tooltip({ text: "<p>Sådan ændres tekststørrelsen på en webside:</p><ol><li>Åbn menuen 'Vis' øverst i Internet Explorer (<strong>ALT</strong> + <strong>S</strong>)</li><li>Vælg 'Tekststørrelse' (<strong>T</strong>)</li><li>Klik på den ønskede størrelse, f.eks. <em>Mellem</em> eller <em>Større</em>.</li></ol><p>Alternativ genvej  <strong>CTRL</strong> + <strong>PLUS</strong> eller <strong>MINUS</strong>" });
			if (IE6) {
				$("#tools_sendlink").tooltip({ text: "<p>Således sender du et link til denne side via dit email-program.</p><ol><li>Klik på 'Filer' i menubjælken (<strong>ALT</strong>+<strong>F</strong>)</li><li>Vælg 'Send...' (<strong>S</strong>)</li><li>Vælg 'Hyperlink med e-mail...' (<strong>H</strong>)</li></ol>" });
			} else {
				$("#tools_sendlink").tooltip({ text: "<p>Således sender du et link til denne side via dit email-program.</p><ol><li>Klik på 'Side' i menubjælken (<strong>ALT</strong>+<strong>I</strong>)</li><li>Vælg 'Send hyperlink med e-mail...' (<strong>H</strong>)</li></ol>" });
			}
		}

		// Find last child for IE6 + 7
		$(".col_row :last-child").addClass("last-child");

		// IE6
		if (IE6) {
			// Find first child for IE6
			$(".col_row :first-child").addClass("first-child");

			var w = parseInt($("#page").width());
			if ((w > 731) && (w <= 812)) {	// Smaller
				$("#search").css({ top: 26 });
				$("body").prepend("<div id='ie6msg'></div>");
				$("#ie6msg")
					.html("Din tekststørrelse i browseren er sat til '<strong>mindre</strong>', hvilket kan gøre teksten på denne hjemmeside svær at læse. ")
					.animate({ top: 0 }, 1500)
					.animate({ top: 0 }, 10000)
					.animate({ top: -100 }, 1500);
			} else if (w <= 731) {				// Smallest
				$("body").prepend("<div id='ie6msg'></div>");
				$("#ie6msg")
					.html("Din tekststørrelse i browseren er sat til '<strong>mindst</strong>', hvilket desværre bryder layoutet på denne hjemmeside. <br>I menubjælken klik på 'Vis' og 'Tekststørrelse' og derefter vælg en der er større.")
					.animate({ top: 0 }, 1500)
					.animate({ top: 0 }, 10000)
					.animate({ top: -100 }, 1500);
			}
		}
	}
});

(function($) {
	$.fn.tooltip = function(option) {
		return this.each(function() {
//  MSIE 6 only
			var IE6 = false;
			if ($.browser.msie && $.browser.version < 7) { 
		        IE6 = true;
			}
			var el = $(this);
			var config = {
				title:	el.attr( "title" ),
				text:		el.attr( "title" ),
				xOffset:	-100,
				yOffset:	-25
			}
			var el = $(this).removeAttr("title").children().removeAttr("alt");
			config = $.extend(config, option);
			
			if (config.text == "") return;

			var showTooltip = function (e) {

				$("#tooltip")
					.html(config.text)
					.css("top",(e.pageY - config.yOffset) + "px")
					.css("left",(e.pageX + config.xOffset) + "px")
					.show();		
				if (IE6) {
					$("#page").addClass("hideSelects");
				}	
			};
			var hideTooltip = function () {
				$("#tooltip").hide();
				if (IE6) {
					$("#page").removeClass("hideSelects");
				}
			};
			
			$(this).bind("mouseenter", function(e) {
				showTooltip(e);
			});
			$(this).bind("mouseleave", function() {
				hideTooltip();
			});
	
			$(this).bind("mousemove", function(e) {
				//if ($("#tooltip").html()=="") return;
				$("#tooltip")
					.css("top",(e.pageY - config.yOffset) + "px")
					.css("left",(e.pageX + config.xOffset) + "px");
			});			

	  });
	};
})(jQuery);

(function($) {
	$.fn.selectJumper = function(option) {
		return this.each(function() {
			var el = $(this);
			el.changed = false;
			el.focus(function() {
				el.initValue = el.val();
			})			
			el.change(function() {
				if((this).selectedIndex == 0) return false;
			
				if (!el.changed)
				{
					return false;
				} else {
					window.location.href = el.val();
					return false;
				}
			})			
			el.keydown(function(event) {
				if (((event.keyCode == 9) || (event.keyCode == 13)) && (el.val() != el.initValue)) {
					el.changed = true;
					el.change();
				} else if (event.keyCode == 27) {
					(this).selectedIndex = 0;
				} else {
					el.changed = false;
				}
			})			
			el.click(function() {
				el.changed = true;
			})			
		});
	}
})(jQuery);

(function($) {
	slideSwitch = function () {
		var $active = $('.slider img.active');

		if ( $active.length == 0 ) $active = $('.slider img:last');

		// use this to pull the images in the order they appear in the markup
		var $next =  $active.next().length ? $active.next()
			: $('.slider img:first');

		// uncomment the 3 lines below to pull the images in random order
	    
		// var $sibs  = $active.siblings();
		// var rndNum = Math.floor(Math.random() * $sibs.length );
		// var $next  = $( $sibs[ rndNum ] );

		$active.addClass('last-active');

		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}

	$(function() {
	    var $active = $('.slider');
	    if($active.length) setInterval( "slideSwitch()", 5000 );
	});
})(jQuery);

