$(document).ready(function() {
  /* photo items */
  var photoitems=function() {
    var mainphotoItems=$("#mainphoto .photolist a");
    var mainphoto=$("#mainphoto img.photo");
    var currentZIndex=1;
    var activeAnimations=0;
    var currentselected=0;
    var updatePicInterval=false;
    var updatePicture=false;
    var i=0;
    for(i=mainphotoItems.length-1;i>0;i--) {
      //alert(i);
      var alt=$("img", mainphotoItems.get(i)).get(0).title;
      var src=mainphotoItems.get(i).href;
      mainphoto.after('<img class="photo" alt="'+alt+'" src="'+src+'" style="display: none" />');
    }
    $("#mainphoto img.photo").css("position: relative");
    var mainphotoClick=function() {
      var i=0;
      var current=0;
      for(i=1;i<mainphotoItems.length;i++) {
        if (mainphotoItems.get(i)==this)
          current=i;
      }
      var items=$("#mainphoto img.photo");
      currentZIndex++;
      var thisitem=items.get(current);
      if (currentselected!=current) {
        currentselected=current;
        $(thisitem).hide();
        $(thisitem).css("z-index", currentZIndex);
        $("#mainphoto .photolist li").removeClass("selected");
        $(mainphotoItems.get(current).parentNode).addClass("selected");

        setTimeout(function() {
          $("#mainphoto .blackband h2").html($("img", mainphotoItems.get(current)).get(0).alt);
        }, 500);
        activeAnimations++;
        $(thisitem).fadeIn(1000, function() {
          if (activeAnimations) {
            activeAnimations--;
          }
          if (!activeAnimations) {
            currentZIndex=1;
            items.css("z-index", 0);
            $(thisitem).css("z-index", 1);
          }
        });
      }
      updatePicture();
      return false;
    }
    mainphotoItems.click(mainphotoClick);
    updatePicture=function() {
      if (updatePicInterval)
        clearInterval(updatePicInterval);
      updatePicInterval=setInterval(function() {
        var ncurrentselected=currentselected+1;
        if (ncurrentselected>=mainphotoItems.length)
          ncurrentselected=0;
        mainphotoClick.call(mainphotoItems.get(ncurrentselected));
      }, 5000);
    };
    updatePicture();
  }
  if ($("#mainphoto .photolist a").length) photoitems();
  var initGoogleMap=function() {
    var googleMapLoaded=false;
    var mlocation = new GLatLng(43.152688889, 22.588513889);
    var map=false;
    var showInfoWindow=function() {};
    var showGoogleMap=function() {
      $(".mapHolder").hide();
      $(".mapHolder").fadeIn(1000, function() {
        if (!googleMapLoaded) {
          googleMapLoaded=true;
          var mapHolder=$("#mapHolder").get(0);
          if (GBrowserIsCompatible()) {
            map = new GMap2(mapHolder);
            showInfoWindow=function() {
              map.openInfoWindow(mlocation,
                "<strong>"+window.mapAddress.title+"</strong><br />\n"+
                window.mapAddress.line1+"<br />"+
                window.mapAddress.line2+"<br />"+
                window.mapAddress.line3);
            };
            map.setCenter(mlocation, 17);
            map.setMapType(G_HYBRID_MAP);
            map.setUIToDefault();
            var marker=new GMarker(mlocation);
            map.addOverlay(marker);
            GEvent.addListener(marker, "click", showInfoWindow);
            (map.getCenter(),
                   document.createTextNode("Hotel Gali"));
          }
        }
        if (GBrowserIsCompatible()) {
          showInfoWindow();
        }
      });
      return false;
    }
    var hideGoogleMap=function() {
      $(".mapHolder").fadeOut(1000);
      return false;
    }
    $("#mapHolder").click(function() { return false; });
    $(".mapHolder").click(hideGoogleMap);
    $(".mapHolderBorder a.close").click(hideGoogleMap);
    $(".mapTrigger").click(showGoogleMap);
  }
  if ($("#mapHolder").length) initGoogleMap();
});

$(window).load(function() {
  
});
