$(document).ready(function(){

  
  $(".greenbut").corner();
  $("#cartBottom a").corner();

// fix images in content

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

// contact

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

      if (temp == 'ERROR_CANTSENDEMAIL' )  {
        $("#contactform").hide();
           $("#contactthanks").show();
        $("#contactthanks").html("<p>Af en eller anden grund kan vi ikke sende din besked. Kontakt os pr. tlf.</p>");  
        
        
      }  
        

      if (temp == 'OK' ) {
        
          $("#contactform").hide();
             $("#contactthanks").show();
          $("#contactthanks").html('<p>Tak for din henvendelse. Vi vender tilbage hurtigt.</p>');
          
          
      }
      

    });
    

    },

  rules: {

    namefrom: {required: true, minlength: 5},
    message: { required: true, minlength: 5 },
    emailfrom: { required: true, email: true }
  },
  messages: {
    message: { required: "Besked mangler", minlength: "Din besked er meget kort? " },
    namefrom: { required: "Navn mangler", minlength: "Dit navn er lidt for kort?" },
    emailfrom: { required: "Email adresse mangler", email: "Din mail er forkert?"}
  }


   });  


// 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;
        });
      });


jQuery(function(){
  jQuery("#productImages a").ivPrepare();
  
  var contentRotator = jQuery("#featuredProducts");       
  if (contentRotator.children(".featuredProduct").length > 1) {
    
    var contentRotatorControl = contentRotator.readyContentRotator({rotatorElementSelector: '.featuredProduct', 
                                                                    beforeRotate: function(fromEle, toEle){ 
                                                                      jQuery('#featuredPages').children().eq(fromEle.index()).removeClass('on');
                                                                      jQuery('#featuredPages').children().eq(toEle.index()).addClass('on');
                                                                    } 
                                                                   }).getContentRotatorControl();
   
  }
});
