﻿jQuery("html").addClass("js");
jQuery.noConflict();

// Format date
(function($){
$.fn.formaterDato = function() {
	return this.each(function() {
		var dato = new Date($(this).text());
		$(this).empty().append(pad2(dato.getDate())+"-"+(pad2(dato.getMonth() +1 ))+"-"+dato.getFullYear());
	});
};})(jQuery);

function pad2(number) {
   return (number < 10 ? '0' : '') + number
}

/*
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* http://cherne.net/brian/resources/jquery.hoverIntent.html
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});

jQuery(function ($) {
	Engine = {
		fixes: {
			dates: function() {
				$('#press span.date').formaterDato();
// $('#press span.date, #content span.date').formaterDato();
			}
		},
		ui: {
			searchBox: function() {
				$("#q")
					.attr( "value", $("#q").attr("title"))
					.focus(function() {
						if (this.value == $('#q').attr("title")) {
							this.value = "";
						}
					})
					.blur(function() {
						if (this.value == "") {
							this.value = $("#q").attr("title");
						}
					});
			},
			menu: function() {
				$('#navi-main ul li:first').hoverIntent(function(){
            	$(this).find("ul:first")
            		.stop(true,true)
            		.slideDown(500, "easeOutExpo");
            },function(){
            	$(this).find("ul:first")
            		.stop(true,true)
            		.slideUp(300, "easeOutExpo");
            });
			},
			tabs: function() {
				var tabContainers = $('div.tabs > div');
				tabContainers.hide().filter(':first').show();
            
				$('div.tabs ul.tabNavigation a').click(function () {
	 				tabContainers.hide();
	 				tabContainers.filter(this.hash).show();
	 				$('div.tabs ul.tabNavigation a').removeClass('selected');
	 				$(this).addClass('selected');
	 				return false;
				}).filter(':first').click();
			},
			print: function() {
				$("#print")
					.html("<a href='#' title='Udskriv (CTRL + P)'><span>Udskriv</span></a>")
					.click(function() {window.print();return false;});
			}
		
		}
	}
});

/*	On DOM loaded */
jQuery(document).ready(function ($) {
	Engine.ui.menu();
	Engine.ui.searchBox();
	Engine.ui.tabs();
	Engine.ui.print();
	
});

/*	On WINDOW loaded */
jQuery(window).load(function ($) {
	Engine.fixes.dates();
});



/*
	From DWscript.js
*/
function isRadioButtonChecked(theOption, theForm){ 
	if (theForm.elements[theOption].checked){
		return true;
	}
	else{
		for (i=0;i < theForm.elements[theOption].length;i++) {
			if (theForm.elements[theOption][i].checked) {
				return true;
			}
		}
	}
	return false;
}
function validateEmail( email ){
  var regExp = /^[\w\-_]+(\.[\w\-_]+)*@[\w\-_]+(\.[\w\-_]+)*\.[a-z]{2,4}$/i;
  return regExp.test( email );
}
      