// JavaScript Document

// Main menu and dropdown hover scripts


$(document).ready(function() { 
 
    $('#btn-submit').click(function() {  
 
        $(".error").hide();
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
        var emailaddressVal = $("#UserEmail").val();
        if(emailaddressVal == '') {
            $("#UserEmail").after('<span class="error">Skriv venligst din email adresse.</span>');
            hasError = true;
        }
 
        else if(!emailReg.test(emailaddressVal)) {
            $("#UserEmail").after('<span class="error">Skriv venligst en valid email adresse.</span>');
            hasError = true;
        }
 
        if(hasError == true) { return false; }
 
    });
});		
		
		
		



(function ($) {
   $.fn.extend({
      slideshow: function (options) {
         var defaults = {
            displaytime: 7000,
            fadespeed: 1000,
            clickfadespeed: 300,
            width: 954,
            height: 400,
            styleWrapper: true,
            navigation: true,
            navPosition: 'br',
            effect: 'rotate',
            startimage: '0',
            related: ''
         };
         var options = $.extend(defaults, options);

         return this.each(function () {
            var obj = $(this);
            var o = options;
            var current = 0;
            var total = 0;
            var images;
            var slidenav;
            var clicked = false;
            setup();

            function setup() {
               images = $('img', obj);
               total = images.length - 1;
               obj.css({
                  'display': 'block',
                  'position': 'relative',
                  'overflow': 'visible',
                  'background': 'transparent',
                  'width': o.width + 'px',
                  'height': o.height + 'px'
               });
               obj.append('<div id="slidenav" class="' + o.navPosition + '"></div>');
               slidenav = $('#slidenav');
               if (o.startimage == 'random') {
                  startindex = Math.floor(Math.random() * (total + 1));
               } else {
                  startindex = 0;
               }
               images.each(function (index) {

                  $(this).css({
                     'position': 'absolute',
                     'top': '0',
                     'left': '0',
                     'display': (index == startindex) ? 'block' : 'none'
                  }).attr('data-ref', index);

                  if (typeof ($(this).attr('url')) != 'undefined' && $(this).attr('url') != '') {
                     $(this).css({ 'cursor': 'pointer' }).click(function () {
                        if ($(this).attr('url').substring(0, 7) == 'http://' || $(this).attr('url').substring(0, 8) == 'https://') {
                           window.open($(this).attr('url'));
                        } else {
                           window.location = $(this).attr('url');
                        }
                     });
                  }

                  if (o.navigation == true) {
                     if (index == startindex) {
                        slidenav.append('<label data-for="' + index + '" class="active">' + (index + 1) + '</label>');
                     } else {
                        slidenav.append('<label data-for="' + index + '">' + (index + 1) + '</label>');
                     }
                  }
               });
               slidenav.find('label').click(function () {
                  if (!clicked) {
                     clicked = true;
                     navigateTo($(this).attr('data-for'));
                  }
               });
               initiateInterval();
            }

            function initiateInterval() {
               timer = setInterval(function () {
                  switch (o.effect) {
                     case 'rotate': rotate(); break;
                     case 'slideleft': slideleft(); break;
                     default: break;
                  }
               }, o.displaytime);
            }

            function rotate() {
               if (current < (total)) { current++ } else { current = 0 }

               obj.find('img[data-ref!=' + current + ']').css({ 'z-index': '1' });
               obj.find('img[data-ref=' + current + ']').css({ 'z-index': '10' }).fadeIn(o.fadespeed, function () {
                  obj.find('img[data-ref!=' + current + ']').hide();
               });

               if (o.related != '') {
                  //$(o.related + '[data-ref!=' + current + ']').css({ 'z-index': '1' });
                  //$(o.related + '[data-ref=' + current + ']').css({ 'z-index': '10' }).fadeIn(o.fadespeed, function () {
                     //$(o.related + '[data-ref!=' + current + ']').hide();
                  //});
				  
			   	$(o.related).each(function (){
					if($(this).hasClass('data' + current)){
						$(this).show();
					}else{
						$(this).hide();
					}
				});
               }
               slidenav.find('label[data-for!=' + current + ']').removeClass('active');
               slidenav.find('label[data-for=' + current + ']').addClass('active');
            }

            function navigateTo(index) {
               clearInterval(timer);
               obj.find('img[data-ref!=' + index + ']').css({ 'z-index': '1' });
               obj.find('img[data-ref=' + index + ']').css({ 'z-index': '10' }).fadeIn(o.clickfadespeed, function () {
                  obj.find('img[data-ref!=' + index + ']').hide();
                  clicked = false;
               });
               slidenav.find('label[data-for!=' + index + ']').removeClass('active');
               slidenav.find('label[data-for=' + index + ']').addClass('active');
			   
			   	$(o.related).each(function (){
					if($(this).hasClass('data' + index)){
						$(this).show();
					}else{
						$(this).hide();
					}
				});
			   	//$(o.related + '[data-ref=' + index + ']').show();
				//$(o.related + '[data-ref!=' + index + ']').hide();
			   
               current = index;
               initiateInterval();
            }
         });
      }
   });
})(jQuery);

   $(function () {
         $('#slideshow').slideshow({width:675,height:214,related:'.slide-text'});
      });
	  
	  
	  // Textsize up/down
	  
$(document).ready(function() {
	if($('.textsizearea').length > 0){
 
	$('.fs-up a').click(
		function () {$('.textsizearea').addClass('sizeup');return false;}
	);
	$('.fs-dwn a').click(
		function () {$('.textsizearea').removeClass('sizeup');return false;}
	);
	}
});

jQuery(function(){      $(".img-swap").hover(           function(){this.src = this.src.replace("-off","-on");},           function(){this.src = this.src.replace("-on","-off");      }); }); 





	/* Search
	/*-------------------------------------------------------------------*/
	$(function () {
		/* Search inputs */
		$('#SiteSearchField').focus(function ()
		{
			var defaultValue = $(this).attr('title');
			if($(this).val() == defaultValue)
			{
				$(this).val('');
			}
		});
		$('#SiteSearchField').blur(function ()
		{
			var defaultValue = $(this).attr('title');
			var theText = $.trim( $(this).text() );
			if(theText == '')
			{
				$(this).val(defaultValue);
			}
		});
		$('#SiteSearchField').keypress(function (e)
		{
			var returnValue = true;
			if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
			{
				var theText = $.trim( $(this).text() );
				if(theText != '')
				{
					$('#SiteSearchForm').submit();
					returnValue = false;
				}
			}
			return returnValue;
		});
	});




	/*-------------------------------------------------------------------*/
	/* Timeline
	/*-------------------------------------------------------------------*/
	$(function () {
		$('#timeline ul li').hover(
			function () {
				$(this).addClass('hover');
			},
			function () {
				$(this).removeClass('hover');
			}
		);
		$('#timeline ul li').click(function () {
			$('#timeline ul li').removeClass('active');
			$(this).addClass('active');
			$('#timelinetext div.tbox').hide();
			$('#' + $(this).attr('rel')).show();
		});
	});


