var jsTextArray = {"cff1" : 'Заполните пожалуйста поле "ФИО"', "cff2" : 'Заполните пожалуйста поле "Сообщение"',
"cff3" : "Закрыть", "cff4" : "Внимание", "cff5" : 'Заполните пожалуйста поле "Подтверждение"',
"cf1" : 'Заполните пожалуйста поле "Имя"', "cf2" : 'Заполните пожалуйста поле "Вопрос"',
"cf3" : '"Код безопасности" заполнен неверно'};


function galleryOpacityBind(){
  $('.galPicList .gPic')
   .fadeTo('slow', 0.6)
   .mouseover(function(){
     $(this).fadeTo('slow', 1);
   })
   .mouseout(function(){
     $(this).fadeTo('slow', 0.6);
   });
}


function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
   if ($(this).attr("rel") != ""){
     $("body").append("<div class='"+name+"' id='"+name+i+"'>"+$("#"+$(this).attr("rel")).html()+"</div>");
     var my_tooltip = $("#"+name+i);

     $(this).removeAttr("title").mouseover(function(){
       my_tooltip.css({opacity:0.9, display:"none"}).fadeIn(400);
     }).mousemove(function(kmouse){
     tipTop = 0;
           tipLeft = 0;
     if ((kmouse.pageY+my_tooltip.height()+20) > ($(window).height()+$(window).scrollTop())) tipTop = kmouse.pageY-my_tooltip.height()-20;
     else tipTop = kmouse.pageY+20;
     if ((kmouse.pageX+my_tooltip.width()+20) > ($(window).width()+$(window).scrollLeft())) tipLeft = kmouse.pageX-my_tooltip.width()-20;
     else tipLeft = kmouse.pageX+20;

       my_tooltip.css({left:tipLeft, top:tipTop});
     }).mouseout(function(){
       my_tooltip.fadeOut(400);
     }).click(function(){return false});
   }
 });
}

function checkFeedback() {
  var form = $("form#commentform");
  var message = new Array();

  if ($.trim(form.find("[name='name']").val()) == '') message.push(jsTextArray.cf1);
  if ($.trim(form.find("[name='comment']").val()) == '') message.push(jsTextArray.cf2);
  var code = $.trim(form.find("[name='image_value_antispam']").val());
  if (!/^\d{4}$/.test(code)) message.push(jsTextArray.cf3);

  if (message.length) {
    daAlert(jsTextArray.cff4, message.join("<br>"), jsTextArray.cff3, "error");
    return false;
  } else return true;
}

function sendFormInit() {
    $('.cSendForm input')
      .focus(function(){
        if ($(this).val() == $(this).attr('rel')) $(this).val('');
        $(this).removeClass('void');
      })
      .blur(function(){
        if (($(this).val() == '') && $(this).attr('rel')) $(this).val( $(this).attr('rel') ).addClass('void');
      });
    $('.cSendForm textarea')
      .focus(function(){
        if ($(this).val() == $(this).attr('rel')) $(this).val('');
        $(this).removeClass('void');
      })
      .blur(function(){
        if (($(this).val() == '') && $(this).attr('rel')) $(this).val( $(this).attr('rel') ).addClass('void');
      });
    
    $('.cSendForm .row').click(function(){
      $(this).find('textarea, input').focus();
    });
    
    $('.cSendForm input, .cSendForm textarea').each(function(){
      if (($(this).val() == '') && $(this).attr('rel')) $(this).val( $(this).attr('rel') ).addClass('void');
    });
}

function tourImageBind(){
  if ($('.cMiscTourImage').length == 0) return;
  var direction = 1; // direction of movement (-1; +1)
  function imageMove(){
  if ((direction == -1) && (imgBgTopPos <= -imgHeight)) direction = 1;
    if ((direction == 1) && (imgBgTopPos >= 0)) direction = -1;
  imgBgTopPos += direction;
//  alert(imgBgTopPos);
  $('.cMiscTourImage div').css('background-position','0 '+ imgBgTopPos+'px');
    //alert(imgBgTopPos+' '+' '+imgHeight);
  }
  
  var imgSrc = $('.cMiscTourImage div').css('background-image').match(/.+\((.+)\).*/); // full image file path
  var imgBgTopPos = $('.cMiscTourImage div').css('background-position'); //background top position
  if ((imgBgTopPos == 'undefined') || (imgBgTopPos == null)) imgBgTopPos = '0 0px';
  imgBgTopPos = imgBgTopPos.slice(imgBgTopPos.indexOf(' ')+1, -2)*1;
  var imgHeight = 0;
  var imgInterval = null;
  $(new Image()).load(function(){
    $('body').append($(this));
    imgHeight = $(this).height()-$('.cMiscTourImage div').height();
  }).attr('src', imgSrc[1].split('"').join("")).hide();
  imgInterval = setInterval(imageMove, 40);
  $('.cMiscTourImage div').click( function(){
      if (imgInterval){
        clearInterval(imgInterval);
    imgInterval = null;
    }
    else if (imgHeight > 0) imgInterval = setInterval(imageMove,40);
  });

}

function makeHeaders(){
     $(".accordion").accordion({
     active:false,
     autoHeight: false,
     collapsible: true
    });
   };
