﻿// CiG Build [% USE date %][% date.format %] 

$(document).ready(function() {
  // Slideshow
  $('#slideshow-top').galleryView({
    panel_width: 388,
    panel_height: 230,
    frame_width: 40,
    frame_height: 40,
    overlay_opacity: 0.7,
    panel_scale: 'crop',
    frame_scale: 'crop',
    filmstrip_position: 'left',
    transition_interval: 7000,
    fade_panels: true,
    pause_on_hover: true,
    pointer_size:12
  });  
});




// Good morning it's the news  

// var monthscode = {
//   da:["JAN","FEB","MAR","APR","MAJ","JUN","JUL","AUG","SEP","OKT","NOV","DEC"],
//   de:["JAN","FEB","MAR","APR","MAI","JUN","JUL","AUG","SEP","OKT","NOV","DEZ"],
//   en:["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"],
//   el:["Ιαν","Φεβ","Μάρ","Απρ","Μάι","Ιούν","Ιούλ","Αύγ","Σεπ","Οκτ","Νοέ","Δεκ"],
//   es:["ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT","NOV","DIC"],
//   fi:["TAM","HEL","MAA","HUH","TOU","KES","HEI","ELO","SYY","LOK","MAR","JOU"],
//   fr:["JAN","FEV","MAR","AVR","MAI","JUIN","JUIL","AOUT","SEP","OCT","NOV","DEC"],
//   it:["GEN","FED","MAR","APR","MAG","GIU","LUG","AGO","SET","OTT","NOV","DIC"],
//   nl:["JAN","FEB","MAA","APR","MEI","JUN","JUL","AUG","SEP","OKT","NOV","DEC"],
//   no:["JAN","FEB","MAR","APR","MAI","JUN","JUL","AUG","SEP","OKT","NOV","DES"],
//   pt:["JAN","FEV","MAR","ABR","MAI","JUN","JUL","AGO","SET","OUT","NOV","DEZ"],
//   sv:["JAN","FEB","MAR","APR","MAJ","JUN","JUL","AUG","SEP","OKT","NOV","DEC"]
// };  
// 
// 
// $(window).load(function () {
//   $("div#whatsnew").fadeIn("slow");
//   var newslist = $("div#whatsnew ul").attr("class") +".xml";
//   $.ajax({
//     type: "GET",
//     url: "/[% rootdir %]/news/" + newslist,
//     dataType: "xml",
//     success: function(data) {
//       $("newslist news",data).each(function() {
//         var newsmonth = monthscode[newslist.substr(0,2)][$(this).attr("date").substr(5,2).replace(/^[0]+/g,"") - 1];
//         var newsday = $(this).attr("date").substr(8,2).replace(/^[0]+/g,"");
//         $("#whatsnew ul").append("<li><span class=\"calendar\"><span class=\"calendarmonth\">" + newsmonth + "</span><span class=\"calendarday\">" + newsday + "</span></span>" + $(this).text() + "<div class=\"clearit\"></div></li>");
//       });
//     }
//   });
// });


// Tagline
$(window).load(function () {
  $("h1#tagline").text(tagline[Math.floor(Math.random()*tagline.length)]); 
});


$(document).ready(function () {
  // Login form
  $("#loginForm").submit(function() {
    var gosubmit = true;
    $("p.errormsg,p.successmsg").hide();
    $("label + input").removeClass('error');
    $("#loginForm label + input").each(function() {
      if ($(this).val() == '') {
        $(this).addClass('error');
        $(this).next("p.errormsg").show();
        gosubmit = false;
      }
    });
    return gosubmit;
  })
    
  // language selector
  $("a#langselector").click(function () {
    var langselectorx = $(this).parents("li").position().left;
    $("ul#langlist").toggle().css("left",langselectorx + "px");
    return false;
  });
  $("body").click(function() {
    $("ul#langlist").fadeOut("fast");
  });
  
  // password reminder form
  $("a#showpwreminder").click(function () {switchToPwReminderForm(); return false;});
  $("a#showlogin").click(function() { switchToLoginForm(); return false;});
  
  $("#pwReminderForm").submit(function() {
    $("p#pwdreminderwait").show();
    $("p.errormsg").hide();
    $("label + input").removeClass('error');
    if ($("input#email").val() == '') {
      $("input#email").addClass('error');
      $("input#email").next("p.errormsg").show();      
    } 
    else {
      $.ajax({
        beforeSend: function(req) { req.setRequestHeader("Accept-Language", "en-gb"); },
        type: "POST",
        url: "/pe/f/reminder.do?useNSession=No&MAILADDRESS_FIELD=" + $("input#email").val(),
        dataType: "html",
        success: function(data) {
          $("p#pwdreminderwait").hide();
          if ($("h2",data).text() != '') {
            switchToLoginForm();
            $("#pwresetsuccess").show();      
          }
          else {
            $("p#emailnotfound").show();
            $("input#email").addClass('error');      
          }
        },
        error: function(data) {
          $("p#pwdreminderwait").hide();          
          alert("Something went wrong");
        }
      });
	    }
    return false;
  });  
  
  
});


function switchToPwReminderForm() {
  $("p#pwdreminderwait").hide();
  $("p.errormsg,p.successmsg").hide();
  $("label + input").removeClass('error');
  $("form#loginForm").fadeOut('fast',function() {
    $("input#email").val($("input#username").val());
    $("form#pwReminderForm").fadeIn();
    $("input#email").focus();
  });
}

function switchToLoginForm() {
  $("p#pwdreminderwait").hide();
  $("p.errormsg,p.successmsg").hide();
  $("label + input").removeClass('error');
  $("form#pwReminderForm").fadeOut('fast',function() {
    $("input#username").val($("input#email").val());
    $("input#password").val('');
    $("form#loginForm").fadeIn();
    $("input#password").focus();
  });
}


function changeCurrentLocale(newLocale) {
  $.ajax({
    type: "POST",
    url: "/pe/f/zbChangeLocale.do",
    data: { country: newLocale.substr(3,2), language: newLocale.substr(0,2) },
    success: function() {
      parent.location = location.protocol + '//' + location.host + location.pathname;
    }
  });
}
