﻿/* Imperatriz Amelia */

$(function() {
  $("select[name='frommonth']").children("option[value='" + (new Date().getMonth() + 1) + "']").attr("selected", "selected");
  
  $('.gallery a').lightBox();
  jQuery('.first-and-second-carousel').jcarousel({
    wrap: 'circular'
  });

  // acções a de correr depois do site carregar
  $("#maincontent div.Paragraph:last").addClass("noBottomBorder");
  $("#maincontent div.ImageRight div.ParagraphImage img").removeAttr("align");
  
  // Lightbox

  $(".Paragrafo .galeria li a").each(function() {
    ImgSrc = $(this).find("img").attr("src");
    ImgSrc = ImgSrc.substring(0,ImgSrc.lastIndexOf("/"));
    ImgSrc = ImgSrc.substring(0,ImgSrc.lastIndexOf("/"));
    ImgSrc = ImgSrc + "/" + $(this).attr("imgName");
    $(this).attr("href", ImgSrc);
  });

  function CreateGallery(path, SmallHeight, BigWidth, BigHeight) {
    path = path.substring(0,path.lastIndexOf("/"));
    $.ajax({
        url: location.protocol + "//" + location.hostname + "/Files/GetFolderContents.aspx?Path=" + path,
        success: function(data){
          var xml;
          if ($.browser.msie && typeof data == "string") {
            xml = new ActiveXObject("Microsoft.XMLDOM");
            xml.async = false;
            xml.loadXML(data);                
          } else {
             xml = data;
          }
          $(".ParagraphModule").append('<div class="galeria"></div>');
  
          $(xml).find("File").each(function() {
            PathImg=($(this).attr('href'));

            $(".galeria").append('<div class="jCarouselLite"><a href="/admin/public/getimage.aspx?&Image='+PathImg+'&Height='+BigHeight+'&Width='+BigWidth+'&Crop=0"><img src="/admin/public/getimage.aspx?&Image='+PathImg+'&Height='+SmallHeight+'&Crop=0" alt="" border=""/><\/a><\/div>');
            $('.galeria a').lightBox({fixedNavigation:false});
          });
          $(".galeria").append("<div style='clear: both;'></div>")
        }
    });
  }

  $(".jCarouselLite").each(function() {
    $(this).jCarouselLite({
      btnNext: ".galeria .next",
      btnPrev: ".galeria .prev",
      visible: 4,
      afterEnd: function(a) {
        $(".galeria li a").each(function() {
          $(this).lightBox();
        });
      }
    });
    $(this).jcarousel();
  });

  //Carousel
  $(".galeriaQuartos .jCarouselLiteQuartos").each(function() {
    $(this).jCarouselLite({
      btnNext: ".galeriaQuartos .nextQ",
      btnPrev: ".galeriaQuartos .prevQ",
      visible: 4,
      afterEnd: function(a) {
        $(".galeriaQuartos li a").each(function() {
          $(this).lightBox();
        });
      }
    });
    $(this).jcarousel();
  });
  $("select[name='fromday']").children("option[value='" + new Date().getDate() + "']").attr("selected", "selected");
});
