var ips = {
  "system" : {
     "urlroot" : window.location.host.indexOf('idium.n') !== -1 ? window.location.pathname.substring(0,window.location.pathname.indexOf('/',2)) + "/" : "/"
   }
}
$(document).ready(function() {
    $('a.filefolder').click(function(e){
       var unik = $(this).attr("rel");
       e.preventDefault();
       if (!$("." + unik).get()[0]) {
         $.get($(this).attr("href") + ";template=filefolderajax;", function(data){
           var wrapper = "<div class='lightboximages " + unik + "'>" + data + "</div>";
           $(wrapper).appendTo("#content");
           $('a[rel=lightbox['+ unik + ']]').lightBox().eq(0).click();
         });
       } else {
         $("." + unik).find("a:first").click();
       }
    });
    $('a[rel=lightbox[group]]').lightBox();
    
    $("#newsletter").load(ips.system.urlroot + "?template=ajaxnewsletter&lang=eng", function(){
        $("#newsletterForm").submit(function(e){
            e.preventDefault();
            var $response = $("#newsletterResponse"); //cache
            var emailpattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
            if (!emailpattern.test($(this).find("input.text").val())) {
              $response.text("Please enter a valid e-mail adress!")
              return false;
            }
            var ajaxurl = ips.system.urlroot + "?template=ajaxnewsletter";
            $.ajax({
              type : "POST",
              url : ajaxurl,
              data : $(this).serialize(),
              error : function(){$response.text("Sorry! An error occured");},
              success : function(){$response.text("Thank you for signing up for our newsletter!");}
            });

        });
    });
    
});