$(window).load(function(){

	// slider - adjust height according to first image
	 var sliderimage = $('#slider img');
	 $('#slider .container').css('height',sliderimage.height());

});

$(document).ready(function(){


// fix images in content

$("#content img[style*=left]").addClass('left');
$("#content img[style*=right]").addClass('right');

// contact

  $("#contactform").validate({
	
       submitHandler: function(form) {
       $.post("/base/Nordija/Contact.aspx", $("#contactform").serialize(), function(msg){
       
   			var temp = $(msg).find("value").text();

			if (temp == 'ERROR_CANTSENDEMAIL' )  {
				$("#contactform").hide();
	   			$("#contactthanks").show();
				$("#contactthanks").html("<p>For some reason the contactformular does not work. Please contact us by email or phone.</p>");	
				//	Send the event to Analytics
				_gaq.push(['_trackEvent', 'Contact', 'Result', 'ERROR_CANTSENDEMAIL']);
				
				
			}  
    		

			if (temp == 'OK' ) {
				
					$("#contactform").hide();
		   			$("#contactthanks").show();
					$("#contactthanks").html('<p>Thanks for contacting us. We promise to get back to you very shortly.</p>');
					//	Send the event to Analytics
					_gaq.push(['_trackEvent', 'Contact', 'Result', 'OK']);
					
			}
			

		});
    

		},

	rules: {

		namefrom: {required: true, minlength: 5},
		message: { required: true, minlength: 5 },
		emailfrom: { required: true, email: true },
		calcthis: { required: true, min: 16, max:16 }
	},
	messages: {
		message: { required: "Message is missing.", minlength: "Message is a bit short? " },
		namefrom: { required: "We need your name.", minlength: "Your name is too short." },
		emailfrom: { required: "Email address is missing", email: "Your email address seems wrong?"},
		calcthis: { required: "Please fill this in (we're just trying to avoid all the spambots)", min: "Try again, please", max: "Try again, please"}
	}


   });  


// slider - adjust for only one slide (jesper)

	 var a = $('#slider div div div');
	 if (a.length > 1)
	   $('#slider').loopedSlider();
         else 
	   a.css('display','block');

// signup form

$("#signup").submit(function(){  

      $("#signupbutton").attr('disabled', 'disabled');
      $("#signupbutton").attr('value', 'Wait!');


      $.post(  
              "/base/Nordija/Subscribe.aspx",  
             $("#signup").serialize(),  
                 function(data){  
                     var temp = $(data).find("value").text();
		    if (temp=="OK") {
			  $("#signup").hide();
                          $("#signupresponse").show();
		          $("#signupresponse").html("Thank you! Please check your email to confirm your subscription.");
			 _gaq.push(['_trackEvent', 'Newsletter', 'Signup', 'OK']);
		    }
		    else if (temp == "ERROR_EMAIL_FORMAT") {

			  _gaq.push(['_trackEvent', 'Newsletter', 'Signup', 'ERROR_EMAIL_FORMAT']);
			  alert("Please check if your email address is formatted correctly");
			}
		    else if (temp == "ERROR_MAILCHIMP_214") {
			   _gaq.push(['_trackEvent', 'Newsletter', 'Signup', 'You already did']);
			  alert("Thanks - but it seems that you're already on the list. Please contact us if not.");
			}

		    else  {
			   _gaq.push(['_trackEvent', 'Newsletter', 'Signup', 'DEVINE INTERVENTION (WTFWS)']);
			  alert("Something went wrong ( " + temp + ")");
			}

		 $("#signupbutton").attr('disabled', '');
		 $("#signupbutton").attr('value', 'Send');

             }  
          );  
 });  




//Examples of how to assign the ColorBox event to elements
				$("a[rel='example1']").colorbox();
				$("a[rel='example2']").colorbox({transition:"fade"});
				$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
				$("a[rel='example4']").colorbox({slideshow:true});
				$(".example5").colorbox();
				$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
				$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
				$(".example8").colorbox({inline:true, href:"#inline_example1"});
				$(".example9").colorbox({
					onOpen:function(){ alert('onOpen: colorbox is about to open'); },
					onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
					onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
					onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
					onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
				});
				
				//Example of preserving a JavaScript event for inline calls.
				$("#click").click(function(){ 
					$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
					return false;
				});
			});
