$(document).ready(function(){
  // подсветка мапов
  $('.map').maphilight({
    fill: true,
    fillColor: 'ffff00',
    fillOpacity: 0.5,
    stroke: true,
    strokeColor: 'ffff00',
    strokeOpacity: 1,
    strokeWidth: 1
  });
  $('.map_blue').maphilight({
    fill: true,
    fillColor: '467fff',
    fillOpacity: 0.5,
    stroke: true,
    strokeColor: '467fff',
    strokeOpacity: 1,
    strokeWidth: 1
  });
    
/*
* --------------------------------------------------------------------
* Переключатель тумб в фотоальбоме
* (с) Bullet 2011
*/
  var thumbs = $('#photo_thumbs li');
  if(thumbs.size()){
    if ($.browser.msie)
      $(document).ready(function(){
        $('#photo_holder').animate({height:$('#photo_holder img').height()},{duration: 300});
      });
    else
      $('#photo_holder img').load(function(){
        $('#photo_holder').animate({height:$('#photo_holder img').height()},{duration: 300});
      });
    thumbs.click(function(event){
      event.preventDefault();
      getNewPhoto(this);
      return false;
    });
  }
  
  function getNewPhoto(elem){
    var photo_holder = $('#photo_holder');
    var new_thumb = $('img', elem);
    if(!new_thumb.hasClass('active')){
      var photo_caption = $('#photo_caption');
      var old_photo = $('img',photo_holder);
      var img_link = $('a', elem).attr('href');
      var active_thumb = $('#photo_thumbs li img.active');
      
      photo_caption.fadeOut(400, function(){
        photo_caption.html('<span>'+new_thumb.attr('alt')+'</span>');
      });
      
      old_photo.after('<img src="'+img_link+'" style="display:none;" alt="'+new_thumb.attr('alt')+'">');
      $('img:hidden',photo_holder).load(function(){
        old_photo.fadeOut(400, function(){
          $(this).remove();
          photo_holder.animate({height:$('img',photo_holder).height()},{duration: 300});
        });
        $('img',photo_holder).fadeIn(400);
        photo_caption.fadeIn(400);
      });
      
      if ($.browser.msie){
        active_thumb.css({opacity: '0.4', border: '2px solid #aaa'});
        active_thumb.removeClass('active');
        new_thumb.css({opacity: '1', border: '2px solid #f33'});
        new_thumb.addClass('active');
      }
      else{
        active_thumb.animate(
          {opacity: '0.4', border: '#aaa'},  
          {duration: 100, 
          complete: function() {
            $(this).removeClass('active');
            new_thumb.animate(
              {opacity: '1', border: '#f33'},  
              {duration: 100, 
              complete: function() {
                $(this).addClass('active');
              }
            });
          }
        });
      }
    }
  }
  
/**
* --------------------------------------------------------------------
* Перключатель фотографий
*/
  $('#cycleImages').cycle({
    fx:      'fade',
    speed:  1000,
    timeout: 5000
  });
});
