document.write('<style type="text/css">.jsshow { display: block; } .jshide { display: none; } .headline { visibility: hidden; } .headline .cufon { visibility: visible; }</style>');

function c(text) { console.log(text); }

// default easing
jQuery.easing.def = 'easeOutQuad';

// disable selection of text (used on tabs)
$.extend($.fn.disableTextSelect = function() {
	return this.each(function(){
		if ($.browser.mozilla) {
			$(this).css('MozUserSelect', 'none');
		} else if ($.browser.msie) {
			$(this).bind('selectstart', function() { return false; });
		} else {
			$(this).mousedown(function() { return false; });
		}
	});
});

var IMPLEMENT = {
  utils: {
    ie: false,
    init: function(funcs) {
      for (var i = funcs.length; i--;) {
        if (typeof funcs[i] !== 'undefined') {
          funcs[i].init();
        }
      }
    }
  },
  init: function() {
	var pdf;

    if ($.browser.msie) {
      this.utils.ie = parseInt($.browser.version, 10);
    }
    
    this.utils.init([
			this.frontFlash,
      this.targets,
			//this.relatedMaterial,
			this.videos,
			this.misc
    ]);
    
  },
	frontFlash: {
		init: function() {
			$('div.mFrontFlash').each(function() {
				var $this = $(this),
						meta = $.metadata.get(this);
						
				$this.flash({
					src: '/flash/slideshow.swf',
					width: 646,
					height: 230,
					allowfullscreen: true,
					wmode: "opaque",
					flashvars: { xmlPath: meta.xml }
				},{
					version: '8',
					update: false
				});
				
				if(!$this.hasClass('flash-replaced')) {
					$this.find('img').show();
				}
				
			});
		}
	},
	targets: {
    init: function() {
      $('.target').live('click', function(e) {
        if (e.button === 0) {
          var $link = $(this).find('a:last');
          if ($link.length > 0) {
            var href = $link.attr('href');
            if (href) {          
              if ($link.attr('target') === '_blank') {
                window.open(href);
              } else {
                document.location = href;
              }
              return false;
            }
          }
        }
      });      
    }
  },
/*	relatedMaterial: {
		init: function() {
			$('div.mRelatedMaterial h3').disableTextSelect().mousedown(function() {
				var $li = $(this).parents('li:first');
				
				if($li.hasClass('active')) {
					$li.removeClass('active').find('div.content').slideUp(200);
				} else {
					$li.addClass('active').find('div.content').slideDown(300);
					$li.siblings('li.active').removeClass('active').find('div.content').slideUp(200);
				}
			}).find('a').mousedown(function() { return false; });
		}
	},*/
	videos: {
		init: function() {
			$('div.mVideoplayer').each(function() {
				var $this = $(this),
						meta = $.metadata.get(this);
				
				$this.find('div.bd').flash({
					src: '/flash/dwarfplayer.swf',
					width: 466,
					height: meta.height,
					allowfullscreen: true,
					flashvars: { streamPath: meta.flv, streamImagePath: meta.img, stageHeight: meta.height, enableAutoPlay: meta.autoplay }
				},{
					version: '8',
					update: false
				});
						
			});
		}
	},
	misc: {
		init: function() {
			$('span.value').each(function() {
        var $this = $(this),
            $label = $this.find('label'),
            $inp = $this.find('input');

        if($inp.val() !== '') { $label.hide(); }
        $label.mousedown(function() { $inp.parents('fieldset:first').find('input').blur().end().end().focus(); });
        $inp.bind('focus change keydown', function() { $label.hide(); });
        $inp.blur(function() { if($inp.val() === '') { $label.show(); }});
      });

		// print
      $('.print').click(function() {
        window.print();
      }).disableTextSelect();
	  
/******* Sidebar contact images *******/

	$('#rightbar .person img ').attr('width', 68);
	$('#rightbar .person img ').attr('height', 68);
	  
		/*$('#nav li').find('.menuArrow').each(function(){
			if($(this).parent().hasClass('active') || $(this).parent().hasClass('firstactive'))
				$(this).css('background', 'url("/images/backgrounds/arrow_down_orange.png") no-repeat');
			
			if($(this).parent().hasClass('first')) {
				$(this).css('left', $(this).siblings('a').width() + 2 + 'px');			
			} else {
				$(this).css('left', $(this).siblings('a').width() + 6 + 'px');
			}
			$(this).css('visibility', 'visible');		
		});*/	  
		
		}
	}
};

$(function() {
  IMPLEMENT.init();
});

$(document).ready(function() {

/******* Multilist person *******/
	$('#content .multilist li.person:nth-child(odd)').css('margin-right', '20px');

/****** Infobox target *******/			

	$('.mInfoBox').find('.target').hover(function(){
		$(this).children('h4').css('color', '#D53E03');
	}, function(){
		$(this).children('h4').css('color', '#514642');		
	});
	
/****** Colorbox *******/	
	
	$(".colorboxMention").colorbox({
		width:"auto", 
		height:"auto",
		inline:true, 
		href:"#videoMentionOverlay"
	});
	
	//Video overlay cbs - dualplayer
	$('.dualPlayer, .videoPlayer').each(function() { 
		var att = $(this).find('a:first').attr('class');
		
		$(this).next('div').find('.videoOverlay').attr('id', 'ol-'+att);

		$('.'+att).colorbox({
			width: 'auto', 
			height: 'auto',
			inline: true, 
			href:'#ol-'+att
		});	
	});
	
	//Video overlay cbs - single player
	/*$('.videoPlayer').each(function() { 
		var att = $(this).find('a:first').attr('class');
		
		$(this).next('div').find('.videoOverlay').attr('id', 'ol-'+att);
		$('.videoOverlayLink').colorbox({
			width: 'auto', 
			height: 'auto',
			inline: true, 
			href:'.videoOverlay'
		});	
	});	*/
	
/****** Downloads & newsletter *******/	
	if ($('.mDownload').length != 0) {
			
		$('.mDownload').find('.mDownloadLink').click(function(){
			pdf = $(this).next().attr('href');
			$('.mDownload').find('.linklist').css('display', 'none');
			$('.mDownload').find('.popup').slideDown('slow');
		});
		
		$('.mDownload').find('.newsletterNo').click(function(){
			$('.mDownload').find('.newsletterYes').removeAttr('checked');
			$(this).attr('checked', 'checked');
		});
		$('.mDownload').find('.newsletterYes').click(function(){
			$('.mDownload').find('.newsletterNo').removeAttr('checked');
			$(this).attr('checked', 'checked');
		});

	}
	
	$('.mNewsletter .readmore').click(function(){
		$(this).css('display', 'none');
		$(this).next('form').slideDown('slow');
	});
	
/**** Clear input fields on focus ****/	
	
		$('.clear-input').each(function(index){
		var temp = Array();
		temp[index]= $(this).val();
		
		$(this).focus(function(){ if($(this).val() == temp[index]) { $(this).val(''); }});
		$(this).blur(function(){ if($(this).val() == '') { $(this).val(temp[index]); }});
	}); 
	
	/**** Event signup validation with jQuery plugin ****/
	
	$("#eventSignupForm").validate({
	  rules: {
	    company: { required: true },
	    responsible: { required: true },
	    firstname: { required: true },
	    lastname: { required: true },
	    email: { required: true, email: true }
	  },
    messages: {
      company: { required: 'Udfyld venligst firma' },
      responsible: { required: 'Udfyld venligst ansvarlig' },
      firstname: { required: 'Udfyld venligst fornavn' },
      lastname: { required: 'Udfyld venligst efternavn' },
      email: { required: 'Udfyld venligst email', email: 'Emailadressen er ikke gyldig' }
    },
    errorPlacement: function(error, element) {
      $(error).appendTo($(element).parent());
   }  
  });

  $("#eventSignupAddPersonForm").validate({
    rules: {
      subFirstname: { required: true },
      subLastname: { required: true },
      subEmail: { required: true, email: true } 
    },
    messages: {
      subFirstname: { required: 'Udfyld venligst fornavn' },
      subLastname: { required: 'Udfyld venligst efternavn' },
      subEmail: { required: 'Udfyld venligst email', email: 'Emailadressen er ikke gyldig' }
    },
    errorPlacement: function(error, element) {
     error.appendTo( element.parent("span"));
   } 
  });

/**************************************** SHARED CONSULTING & ILI *********************************************/

/**** MENU FUNCTIONS ****/

	var menuFunc = {
		init :  function() {
			$('#nav ul li').each(function(){
				$this = $(this);
				$($this).find('.outer').css('min-width', $($this).outerWidth(true)-10);
			});
		}
	}
	
	menuFunc.init();
  
/************************************************ ILI start ***************************************************/

$('.mSignupCourse #courseSelect').change(function() {
	location.href="./tilmeld_dig.html?type_id="+$(this).val()+"";	
});

/**** Frontpage main carousell ****/

	(function ($) {
	//Carousel
	  var frontpageCarousell = {

	  //function(dom element, time between trans, transtime) 
		init : function (_sel, _time, _transTime) { 
			if(_sel.length != 0) {
				this.sel = _sel;
				this.time = _time;
				this.transTime = _transTime;
				this.objNums = jQuery(this.sel).find('li').length; 
				this.currentPage = 0;
				this.timer = 0;
				_fc = this;
				  
				//Sets first li visible and its siblings hidden
				$(_sel).find('li:eq(0)').css('z-index', '5').siblings().css(
				{
					'opacity': '0',
					'zIndex' : '4',
					'display' : 'none'
				});				  
				  
				//Only rotate if more than 1 li
				if(this.objNums > 1) {
					// Setup the navigation
					_fc.setupNav(); 
					// Setup the mousehover
					_fc.hoverFunc();
					//If time var is 0 then do not rotate otherwise it calls timeout func
					if(this.time != 0) { _fc.timeout(); } 
				}
			}
		},
		//Clears the timer & and instantiate a new and calls interval func
		timeout : function() {
			clearTimeout(_fc.timer);
			_fc.timer = setTimeout(function() { _fc.interval(); }, _fc.time);
		},
		//Gives the timer an interval and calls rotate func
		interval : function() {
			_fc.timer = setInterval(function() { _fc.rotate(_fc.currentPage+1, false); }, _fc.time);
		},
		//Controls the fading and nav 
		rotate : function (cp, nav) {
			//If a nav button has been pressed then reset the timer
			if(nav == true) { 
				clearTimeout(_fc.timer);
				//_fc.timer = setInterval(function() { _fc.rotate(_fc.currentPage+1, false); }, _fc.time);
			}
			
			//If the rotator is on the last image then reset the current page (cp)
			if(_fc.currentPage == (_fc.objNums-1) && nav == false) { 
				cp = 0; 
			}
			
			//if the current page is not the same as the active page then animate
			if(cp != _fc.currentPage) {
				$(_fc.sel).find('.nav').children('span:eq(' + _fc.currentPage + ')').removeClass('active');
				$(_fc.sel).find('.nav').children('span:eq(' + cp + ')').addClass('active');

				$(_fc.sel).find('li:eq(' + (_fc.currentPage) + ')').css('zIndex', '4').stop().animate({ opacity: 0 }, _fc.transTime, function() { $(this).css('display', 'none'); });
				$(_fc.sel).find('li:eq(' + cp + ')').css('zIndex', '5').css('display', 'block').stop().animate({ opacity: 1 }, _fc.transTime);
			}

		_fc.currentPage = cp;
		},
		//Sets up  the navigation buttons
		setupNav: function () {
			for(var i=0; i < _fc.objNums; i++) {
				if(i==0)
					$(_fc.sel).find('.nav').append('<span class="active">' + (i+1) + '</span>');
				else 
					$(_fc.sel).find('.nav').append('<span>' + (i+1) + '</span>');
			}
			
			//Checks which nav buttons are clicked
			$(_fc.sel).find('.nav span').click(function() {
				var index = $('span').index(this);
				_fc.rotate(index, true);
			});
		},
		hoverFunc: function () {
			$('.mFrontpageCarousel').hover(function(){
				clearTimeout(_fc.timer);
			},
			function(){
				_fc.timeout();
			});
		}
	}
	  
		//(dom element, time between slides - 0 for no auto transition, transTime)
		frontpageCarousell.init($('.mFrontpageCarousel'), 4000, 1000);

	})(jQuery);


/*** Frontpage statements carousel ***/

	(function ($) {
	//Carousel
	  var fadeRotator = {

	  //function(dom element, time between trans, transtime) 
		init : function (_sel, _time, _transTime) { 
		if(_sel.length != 0) {
			  this.sel = _sel;
			  this.time = _time;
			  this.transTime = _transTime;
			  this.objNums = jQuery(this.sel).find('li').length; 
			  this.currentPage = 0;
			  this.timer = 0;
			  _fr = this;
			  
				if(this.time != 0) {  
					_fr.timeout(); 
				}
			}
		},
		timeout : function() {
			clearTimeout(_fr.timer);
			timer = setTimeout(function() {
			_fr.interval();
			}, _fr.time);
		  },
		  interval : function() {
			_fr.timer = setInterval(function() {
			  _fr.rotate();
			}, _fr.time);
		  },
		rotate : function () {
		  $(_fr.sel).find('li').eq(_fr.currentPage).stop().animate({ opacity: 0 }, _fc.transTime, function() { });
		  
		  if((_fr.currentPage+2) > _fr.objNums) {  
			_fr.currentPage = 0;
			$(_fr.sel).find('li').eq(_fr.currentPage).stop().animate({ opacity: 1 }, _fc.transTime, function() { });
		  } else { 
			$(_fr.sel).find('li').eq(_fr.currentPage+1).stop().animate({ opacity: 1 }, _fc.transTime, function() { });  
			_fr.currentPage++;
		  }
		}
	  }
	  
		//(dom element, time between transitions - 0 for no auto transition, transTime)
		fadeRotator.init($('.mStatements '), 5000, 1000);

	})(jQuery);

/****Course signup functions ****/

	(function ($) {
		//Slider
		  var slideRotator = {
		  //function(dom element, slidedistance, time between trans, transtime) 
			init : function (_sel, _slideDis, _time, _transTime, _leftNav, _rightNav) { 
				if(_sel.length != 0) {
					  this.sel = _sel;
					  this.slideDis = _slideDis;
					  this.leftNav = _leftNav;
					  this.rightNav = _rightNav;
					  this.time = _time;
					  this.transTime = _transTime;
					  this.objNums = jQuery(this.sel).find('li').length; 
					  this.currentPage = 1;
					  this.timer = 0;
					  sr = this;
					
					if(this.objNums > 1) {
						$(this.leftNav).css('display', 'block');
						//$(this.rightNav).css('display', 'block');
						sr.mouseInit();
					} 
				}
			},
			mouseInit : function() {
				$(sr.leftNav).click(function(){
					//c('currentPage: ' + sr.currentPage + ' - ' + 'objNum: ' + sr.objNums)
					if(sr.currentPage < sr.objNums) { 
						$(sr.sel).find('ul').stop().animate({ marginLeft: -((sr.currentPage)*sr.slideDis)+'px' }, sr.transTime, function() { 
							$(sr.rightNav).css('display', 'block');
						});
						sr.currentPage++;
						
						if(sr.currentPage == sr.objNums)
							$(sr.leftNav).css('display', 'none');
					}				
				}); 
				$(sr.rightNav).mousedown(function() {
					$(sr.sel).find('ul').stop().animate({ marginLeft: -((sr.currentPage-2)*sr.slideDis)+'px' }, sr.transTime, function() { 
						$(sr.leftNav).css('display', 'block');
					});
					sr.currentPage--;
					
					if(sr.currentPage == 1)
						$(sr.rightNav).css('display', 'none');
					
				});		
			}
		}

		//(dom element, slidedistance, time between transitions - 0 for no auto transition, transTime, dom element for left nav, dom element for right nav)
		slideRotator.init($('.mSignupCourse .dateSelect'), 500, 0, 1000, $('.mSignupCourse #prevCourses'), $('.mSignupCourse #nextCourses'));
	
		// Radiobuttons
		var signupRadioBtns = {
			init : function () { 
				$('.mSignupCourse .dateSelect .dates, .mSignupCourse .dateSelect .hotel').click(function(){

					var tempInput = $(this).siblings('.radioBtn').children('input');
					
					if( !$(tempInput).is(':checked')  && !$(tempInput).attr('disabled')) {					
						$(tempInput).attr('checked', 'checked');
						$('.dateSelect input').not($(tempInput)).attr('checked', ''); 
					}
				});
			
				$('.mSignupCourse .dateSelect .radioBtn input').change(function() {
					$('.dateSelect input').not($(this)).attr('checked', ''); 
				});
			}
		}
		
		signupRadioBtns.init();
  	
		// Add more participants, delete participants, edit participants, save participants
		var participantFuncs = {
			init : function () {
				$this = this;
				this.edit = false; 
				this.participant = 0; 
				this.signupParticipant();
				this.saveParticipant();
				this.closeParticipant();
				this.deleteParticipant();
				this.editParticipant();
			},
			
			signupParticipant : function() {
				$('.mSignupCourse #addParticipant').click(function(){
					$this.edit = false; //Sets whether it's a new participant or and edit
					$(this).css('display', 'none'); //removes add btn
					$('#privateNameExtra, #privatePhoneExtra, #privateEmailExtra, #privateJobtitleExtra ').val(''); // Clears form field values
					//$('.mSignupCourse #participantsList').css('display', 'block');
					$('#extraParticipantForm').find('input').removeClass('error').end().find('label.error').remove(); //Clears form field errors
					$('#extraParticipantForm').slideDown('slow'); //Shows extra form
				});			
			},
			
			saveParticipant : function() {
				$('.mSignupCourse #saveParticipant').click(function(){

					if($("#extraForm").valid()) {
						var PartiCount = $('#participantsList .participant').length; // Number of participants so far
						var name = $('#extraParticipantForm #privateNameExtra').val();
						var phone = $('#extraParticipantForm #privatePhoneExtra').val();
						var email = $('#extraParticipantForm #privateEmailExtra').val();
						var jobTitle = $('#extraParticipantForm #privateJobtitleExtra').val();
						
						if(!$this.edit) { //If this is NOT editmode, but a new participant
							if(PartiCount!=0)
								var cssClass = 'participant';
							else 
								var cssClass = 'participant first'; //First participant gets extra class
								
							$('#participantsList').append('<div class="'+cssClass+'"><h6>Deltager '+ (PartiCount+1) +'</h6><p>'+ name +'</p><span class="edit">Ret informationer</span><span class="last delete">Slet deltager</span></div>') //Add a new participant
							$('#participantsList .participant:last').append('<input type="hidden" value="'+name+'" name="participant_name_'+(PartiCount+1)+'" class="hiddenName" />') //Adds hidden fields to new participant
																	.append('<input type="hidden" value="'+phone+'" name="participant_phone_'+(PartiCount+1)+'" class="hiddenPhone" />')
																	.append('<input type="hidden" value="'+email+'" name="participant_email_'+(PartiCount+1)+'" class="hiddenEmail" />')
																	.append('<input type="hidden" value="'+jobTitle+'" name="participant_jobTitle_'+(PartiCount+1)+'" class="hiddenJob" />');
						} else { //If this IS editmode
							$('#participantsList .participant:eq('+$this.participant+')').find('p').html(name) //Change relevant fields
								.end().find('.hiddenName').val(name)
								.end().find('.hiddenPhone').val(phone)
								.end().find('.hiddenEmail').val(email)
								.end().find('.hiddenJob').val(jobTitle);
						}
						
						$('#extraParticipantForm').css('display', 'none'); // Removes the extra form
						$('.mSignupCourse #addParticipant').css('display', 'block'); // Displays add btn
					} 
				});			
			},
		 	closeParticipant : function() {
                                $('.mSignupCourse #closeParticipant').click(function(){
						
					$('.mSignupCourse #extraParticipantForm').css('display','none');
					$('.mSignupCourse #addParticipant').css('display', 'block');

				});
                        },	
			deleteParticipant : function() {
				$('.mSignupCourse .participant .delete').live('click', function(){
					if($(this).parent().hasClass('first')) 
						$(this).parent().next('.participant').addClass('first'); //If first participant gets deleted, move class 'first' to next participant
					
					$(this).parent().remove(); //Remove participant
					$('#extraParticipantForm').css('display', 'none'); // Removes the extra form
					$('.mSignupCourse #addParticipant').css('display', 'block'); // Displays add btn
					
					/*if($('.mSignupCourse .participant').length == 0) { //Removes headline if no extra participants are present
						$('#participantsList').css('display', 'none');
					}*/

				});					
			},
			
			editParticipant : function() {
				$('.mSignupCourse .participant .edit').live('click', function(){
					$('#extraParticipantForm').find('input').removeClass('error').end().find('label.error').remove(); //Clears form field errors
					$this.edit = true; //Sets whether it's a new participant or and edit
					$this.participant = $('.participant').index($(this).parent()); //Sets the item being edited

					$('.mSignupCourse #addParticipant').css('display', 'none'); //removes add btn
					$('#privateNameExtra').val($(this).siblings('.hiddenName').val());
					$('#privatePhoneExtra').val($(this).siblings('.hiddenPhone').val());
					$('#privateEmailExtra').val($(this).siblings('.hiddenEmail').val());
					$('#privateJobtitleExtra').val($(this).siblings('.hiddenJob').val());
					$('#extraParticipantForm').slideDown('slow'); //Shows extra form
				});
			}
		}

		participantFuncs.init();
	
		// Submit button control
		var submitCourseForm = {
			init : function () {
				$('.mSignupCourse .signupBtn').click(function() {
					var billing = $('.mSignupCourse #billingAddress .field .radioBtn input#secondary:checked').length;
					if (billing == 1) {
						if ($(".mSignupCourse .signupForm").valid() && $('#billingAddress').valid()) { //if the form is valid then submit it
							// get alternative billing data
							var address = $('.mSignupCourse #billingAddress #bAddress').val();
							var zip = $('.mSignupCourse #billingAddress #bZip').val();
							var city = $('.mSignupCourse #billingAddress #bCity').val();

							// set alternative billing data to fields
							$('#billingData #address').val(address);
							$('#billingData #zip').val(zip);
							$('#billingData #city').val(city);

							$(".mSignupCourse .signupForm").submit();
						} else {
							return false;
						}
					} else if (billing == 0) {
						if ($(".mSignupCourse .signupForm").valid()) { //if the form is valid then submit it
							$(".mSignupCourse .signupForm").submit();
						} else {
							return false;
						}
					}
				});
			}
		}	

		submitCourseForm.init();
		// billing
		$('.mSignupCourse #billingAddress .field .radioBtn input').click(function() {
			var btn = $('.mSignupCourse #billingAddress .field .radioBtn input#secondary:checked').length;
			
			if(btn == "1") {
				$('.mSignupCourse #billing').slideDown();
			} else if (btn ==0) {
				$('.mSignupCourse #billing').css('display', 'none');
			}
			
		});	
		// select course listener
			if(!$('.mSignupCourse .dateSelect .radioBtn input:first').attr('disabled')) {
			  	$('.mSignupCourse .dateSelect .radioBtn input:first').attr('checked', 'checked');
			}
		
	})(jQuery);  
  
  
/************ Course signup validation with jQuery plugin *************/
	
	var courseValidator = {
		validateMainForm : function() {
			$('.primaryForm').validate({
				rules: {
					course: { required: true},
					privateName: { required: true },
					privatePhone: { required: true, digits: true, minlength: 8 },
					privateEmail: { required: true, email: true },
					privateJobtitle: { required: true },
					companyName: { required: true },
					companyAddress: { required: true },
					companyAreaCode: { required: true, digits: true },
					companyCity: { required: true }
				},
				messages: {
					course: { required: 'Vælg kursus'},
					privateName: { required: this.isEnglish ? 'Please fill out name' : 'Udfyld venligst navn' },
					privatePhone: {
						required: this.isEnglish ? 'Please fill out phone' : 'Udfyld venligst telefonnummer',
						digits: this.isEnglish ? 'Only numbers are allowed' : 'M&aring; kun indeholde tal',
						minlength: this.isEnglish ? 'Must contain at least 8 numbers' : 'Skal indeholde minimum 8 tal' },
					privateEmail: {
						required: this.isEnglish ? 'Please fill out email' : 'Udfyld venligst email',
						email: this.isEnglish ? 'Email address is invalid' : 'Email-adresse er ugyldig' },
					privateJobtitle: { required: this.isEnglish ? 'Please fill out job title' : 'Udfyld venligst job titel' },
					companyName: { required: this.isEnglish ? 'Please fill out the name of your company' : 'Udfyld venligst navnet p&aring; virksomheden' },
					companyAddress: { required: this.isEnglish ? 'Please fill out the address of your company' : 'Udfyld venligst adressen p&aring; virksomheden' },
					companyAreaCode: {
						required: this.isEnglish ? 'Please fill out the zipcode of your company' : 'Udfyld venligst postnr p&aring; virksomheden',
						digits: this.isEnglish ? 'Only numbers are allowed' : 'M&aring; kun indeholde tal' },
					companyCity: { required: this.isEnglish ? 'Please fill out the city of your company' : 'Udfyld venligst virksomhedens by' }
				},
				errorPlacement: function(error, element) {
					$(error).appendTo($(element).siblings('.errorCon'));
				} 
			});		
		}, 
		
		validateExtraForm : function() {
			$('#extraForm').validate({
				rules: {
					privateNameExtra: { required: true },
					privatePhoneExtra: { required: true, digits: true, minlength: 8 },
					privateEmailExtra: { required: true, email: true },
					privateJobtitleExtra: { required: true }
				},
				messages: {
					privateNameExtra: { required: this.isEnglish ? 'Please fill out name' : 'Udfyld venligst navn' }, 
					privatePhoneExtra: {
						required: this.isEnglish ? 'Please fill out phone' : 'Udfyld venligst telefonnummer',
						digits: this.isEnglish ? 'Only numbers are allowed' : 'M&aring; kun indeholde tal',
						minlength: this.isEnglish ? 'Must contain at least 8 numbers' : 'Skal indeholde minimum 8 tal' },
					privateEmailExtra: {
						required: this.isEnglish ? 'Please fill out email' : 'Udfyld venligst email',
						email: this.isEnglish ? 'Email address is invalid' : 'Email-adresse er ugyldig' },
					privateJobtitleExtra: { required: this.isEnglish ? 'Please fill out job title' : 'Udfyld venligst job titel' }
				},
				errorPlacement: function(error, element) {
					$(error).appendTo($(element).siblings('.errorCon'));
				} 
			});				
		},
		validateBillingForm : function() {
			$('#billingAddress').validate({
				rules: {
					bAddress: { required: true },
					bZip: { required: true, digits: true, minlength: 4 },
					bCity: { required: true }
				},
				messages: {
					bAddress: { required: this.isEnglish ? 'Please fill out address' : 'Udfyld venligst adresse' },
					bZip: {
						required: this.isEnglish ? 'Please fill out zipcode' : 'Udfyld venligst postnr.',
						digits: this.isEnglish ? 'Only numbers are allowed' : 'M&aring; kun indeholde tal',
						minlength: this.isEnglish ? 'Must contain at least 4 numbers' : 'Skal indeholde minimum 4 tal' },
					bCity: { required: this.isEnglish ? 'Please fill out city' : 'Udfyld venligst by' }
				},
				errorPlacement: function(error, element) {
					$(error).appendTo($(element).siblings('.errorCon'));
				}
			});
		} 
  }

	if ($('.mSignupCourse').length != 0) {
		courseValidator.isEnglish = $('#lang_is_english').length != 0;
		courseValidator.validateMainForm(); 
		courseValidator.validateExtraForm();
		courseValidator.validateBillingForm();
	}
 	

	// mTeachers - view profile
	$('.mTeachers .bd .person .viewprofile').click(function () {
		$(this).parent().parent().find('.profile').slideDown();
		$(this).css('display','none');
	});
	// mTeachers - hide profile
	$('.mTeachers .bd .person .profile .hideprofile').click(function () {
		$(this).parent().slideUp();
		$(this).parent().parent().find('.content').find('.viewprofile').css('display','block');
	});
	
	
	if ($('.mPictureFeature').length != 0) {
	
		$('.mPictureFeature').each(function(){
			var temp = $(this).attr('id');
			
			$('#'+temp+' ul').cycle({
				pager:      '#' + temp + ' .bullet',
				pagerEvent: 'click',
				pause:         0,
				pauseOnPagerHover: 0,
				requeueTimeout: 4000, 
				timeout:       4000,
				fastOnEvent:   4000,
				pagerAnchorBuilder: pagerFactory
			});			
		
			$('#' + temp + ' .bullet a').click(function() {
				$('#' + temp + ' ul').cycle('resume');
			}, function () {
				$('#' + temp + ' ul').cycle('pause');
			});
		});
	}

	function pagerFactory(idx, slide) {
			//var s = idx > 2 ? ' style="display:none"' : '';
			//return '<div'+s+'><a href="#">&#9679;</a></div>';
			return '<div><a href="#">&#9679;</a></div>';
	};
	
	/**** Calendar functions ****/

	(function ($) {
		//Slider
		  var calendarRotator = {
		
		  //function(dom element, slidedistance, time between trans, transtime) 
			init : function (_sel, _slideDis, _time, _transTime, _leftNav, _rightNav) { 
				if(_sel.length != 0) {
					sr = this;
					this.sel = _sel;
					this.slideDis = _slideDis;
					this.leftNav = _leftNav;
					this.rightNav = _rightNav;
					this.time = _time;
					this.transTime = _transTime;
					this.objNums = jQuery(this.sel).find('li').length; 
					this.currentPage = 1;
					this.timer = 0;
					this.initalHeight = jQuery(this.sel).find('li:first-child').height();
					
					//Finds the li with the active child class
					var activePage = ($(this.sel).find('li').index($(this.sel).find('li .active').parent('li'))+1);
					//var initalHeight = $(this.sel).find('li:first:child').height();
					$(this.sel).find('ul').css('height', (this.initalHeight)+'px' )
					
					//If more than one li then set up interactivity
					if(this.objNums > 1) {
						
						if(activePage != this.objNums) { $(this.leftNav).css('display', 'block'); }
						
						//if the active page is not the first
						if(activePage > 1) {
							this.currentPage = activePage;
							$(this.sel).find('ul').css('margin-left', -((this.currentPage-1)*sr.slideDis)+'px');
							$(this.rightNav).css('display', 'block');
							
						}
						
						sr.mouseInit();
					} 
				}
			},
			mouseInit : function() {
				
				$(sr.leftNav).click(function(){
					//c('currentPage: ' + sr.currentPage + ' - ' + 'objNum: ' + sr.objNums)
					if(sr.currentPage < sr.objNums) { 
						$(sr.sel).find('ul').stop().animate({ marginLeft: -((sr.currentPage)*sr.slideDis)+'px' }, sr.transTime, function() { 
							$('.mCalendar ul li').each(function (i) {
                                                		var height = $(this).height();
                                                		var page = i+1;
                                                		if(sr.currentPage == page)
														$('.mCalendar ul').css('height', height+"px");
                                        		});
        
							$(sr.rightNav).css('display', 'block');
						});
						sr.currentPage++;
						
						if(sr.currentPage == sr.objNums)
							$(sr.leftNav).css('display', 'none');
					}				
				}); 
				$(sr.rightNav).mousedown(function() {
					$('.mCalendar ul li').each(function (i) {
                                                var height = $(this).height();
						var page = i+2; 
                                                if(sr.currentPage == page)
												$('.mCalendar ul').css('height', height+"px");
                                        });

					$(sr.sel).find('ul').stop().animate({ marginLeft: -((sr.currentPage-2)*sr.slideDis)+'px' }, sr.transTime, function() { 
						$(sr.leftNav).css('display', 'block');
					});
					sr.currentPage--;
					
					if(sr.currentPage == 1)
						$(sr.rightNav).css('display', 'none');
					
				});		
			}
		}

		//(dom element, slidedistance, time between transitions - 0 for no auto transition, transTime, dom element for left nav, dom element for right nav)
		calendarRotator.init($('.mCalendar'), 790, 0, 1000, $('.mCalendar .nav .nextMonths'), $('.mCalendar .nav .lastMonths'));

	})(jQuery);


	// Course form leaving confirmation
	(function($) {
		var bound = false;
		$inputs = $('.mSignupCourse :text');
		$inputs.change(function() {
			var bind = false;
			$inputs.each(function() {
				if ($(this).val()) {
					bind = true;
				}
			});
			if (bind) {
				if (!bound) {
					$(window).bind('beforeunload', function(event) {
						event.preventDefault();
					});
					bound = true;
				}
			} else {
				if (bound) {
					$(window).unbind('beforeunload');
					bound = false;
				}
			}
		});
	})(jQuery);
});

