$(document).ready(function() {

    // CampaignMonitor subscribtion: 
    //Check for valid email
    $('.rf_newsletterSubscription form').submit(function() {
      var regex = new RegExp(/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i);                          
      if($('.rf_newsletterSubscription input.validEmail').val().match(regex)) {
        return true;
      } else {
        alert($('.rf_newsletterSubscription input.validEmail').attr('title'));
        $('.rf_newsletterSubscription input.validEmail').focus();
        return false;
      }                                                                                     
  
    });   
  
  
  // jQuery Cycle
  $('.cycle').cycle({
      timeout: 8000,
      delay: 1000,
      pager: '.cPager',
      activePagerClass: 'activeSlide',
      pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return 'ol.cPager li:eq(' + idx + ') a'; 
    }
  });

  /* Fancybox on images */	
  $("a[rel=fancybox]").fancybox({
  	'transitionIn'		: 'none',
  	'transitionOut'		: 'none',
  	'titlePosition' 	: 'over',
  	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
  		return '<span id="fancybox-title-over">' + title + '</span>';
  	}
  });

  // Fancybox iframe
	$("#fancyboxIframeNewsletterSubscription").fancybox({
		'width'				: 400,
		'height'			: 350,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	
	
	
	
 /* Forum */
    /*
    $('.postHeadline_li input').change(function() {
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      $('.title_li input').val( twoDigit(year) + '-' + twoDigit(month) + '-' + twoDigit(day) + ': ' + $('.postHeadline_li input').val() );
    });
    */
    
    
    
    
    
  /* Form validation */    
  $("#Form1").validate();
  
  $.extend($.validator.messages, {
        required: "Feltet ovenfor skal udfyldes",
        email: "Angiv venligst en gyldig e-mail-adresse i feltet ovenfor",
        digits: "Angiv venligst kun tal i feltet ovenfor",
    		digits: "Angiv venligst kun tal i feltet ovenfor",
    		maxlength: $.validator.format("Feltet ovenfor må maks. indeholde {0} tegn."),
    		minlength: $.validator.format("Feltet ovenfor skal indeholde mindst {0} tegn."),
    });
  
  if( $(".title_li input").length != 0 ) {
    $(".title_li input").rules("add", {
      required: true,
      minlength: 2,
    });  
  }
  if( $(".postBodytext_li textarea").length != 0 ) {
    $(".postBodytext_li textarea").rules("add", {
      required: true,
      minlength: 10,
    }); 
  }
  if( $(".name_li input").length != 0 ) {
    $(".name_li input").rules("add", {
      required: true,
      minlength: 2,
    });  
  }
  if( $(".confirmationEmail_li input").length != 0 ) {
    $(".confirmationEmail_li input").rules("add", {
     required: true,
     email: true, 
    }); 
  }
  if( $(".lng_li input").length != 0) {
    $(".lng_li input").rules("add", {
     required: true 
    }); 
  }
	


});



$(window).load(function() {

  // Resize content area to make sticky footer
  var fixedElementsHeight = $(".header").height() + $(".footer").height() + 13;
  if( $(".content").height() < ($(window).height() - fixedElementsHeight) ) {
    $(".content").height( ($(window).height() - fixedElementsHeight) );
    //console.info("$(\".contentWrapper\").height( ($(window).height()="+$(window).height()+" - fixedElementsHeight="+fixedElementsHeight+") );");
  }
  $(window).resize(function() { 
    var fixedElementsHeight = $(".header").height() + $(".footer").height() + 13;
     if( $(".content").height() < ($(window).height() - fixedElementsHeight) ) $(".content").height( ($(window).height() - fixedElementsHeight ) );  
     //console.info("$(\".contentWrapper\").height( ($(window).height()="+$(window).height()+" - fixedElementsHeight="+fixedElementsHeight+") );");   
  }); 
   


  
});
