//feedbackRotator
feedbackRotatorDelay = 10000;
function feedbackRotatorBlock(){
  $('.feedbacks_block div.testimonial:visible:last').fadeOut('slow');
  $('.feedbacks_block .bl_content').prepend($('.feedbacks_block div.testimonial:last'));
  $('.feedbacks_block tr:first').show();
  var height = $('.feedbacks_block div.testimonial:first').height();
  $('.feedbacks_block div.testimonial:first').hide();
  $('.feedbacks_block .bl_content').animate({"top" : '+' + height}, 500, 'linear', function(){
    $(this).css('padding-top', 0);
    $('.feedbacks_block div.testimonial:first').fadeIn('slow');
  });
  setTimeout(feedbackRotatorBlock, feedbackRotatorDelay);
}
setTimeout(feedbackRotatorBlock, feedbackRotatorDelay);
//End Of feedbackRotator

//feedbackRotator
feedbackRotatorDelay = 10000;
function feedbackRotator(){
  $('table.feedbacks tr:visible:last').fadeOut('slow');
  $('table.feedbacks').prepend($('table.feedbacks tr:last'));
  $('table.feedbacks tr:first').show();
  var height = $('table.feedbacks tr:first').height();
  $('table.feedbacks tr:first').hide();
  $('table.feedbacks tbody').animate({"top" : '+' + height}, 500, 'linear', function(){
    $(this).css('padding-top', 0);
    $('table.feedbacks tr:first').fadeIn('slow');
  });
  setTimeout(feedbackRotator, feedbackRotatorDelay);
}
setTimeout(feedbackRotator, feedbackRotatorDelay);
//End Of feedbackRotator

$('#add-testimonial').submit(function(){
  $('#add-testimonial').ajaxSubmit({
    success: function(result){
      result = result.replace("<html", "<myhtml");
      result = result.replace("</html", "</myhtml");
      result = result.replace("<body", "<mybody");
      result = result.replace("</body", "</mybody");

      $('.errors').remove();
      $error = $('.errors', result);
      if($error.length > 0){
        $('#add-testimonial').before($error);
        change_antibot_image('on_testimonials');
      }

      $saved = $('h1.saved', result);
      if($saved.length > 0){
        $('.dialogue').empty().append($saved).fadeIn(1500).delay(3000).fadeOut(1500);
        $('.submitTestimonialBody').fadeOut();
        $('#add-testimonial #title').val('');
        $('#add-testimonial #body').val('');
      }
    },
    error: function(xhr){
      console.log('error');
      console.log(xhr);
      change_antibot_image('on_testimonials');
    }
  });

  return false;
});

function LoadAjaxData(link){
  if(typeof LoadAjaxData.cache == 'undefined'){LoadAjaxData.cache = []}
  $link = $(link);
  var addr = $link.attr('href');
  if ($link.hasClass('needlogin') && $('form[name="loginform"]').length != 0){
    addr = "/error_message.php?login_incorrect";
  }


  if(typeof LoadAjaxData.cache[addr] == 'undefined'){
    $('#selected-content').fadeOut('fast', function(){
      $('#selected-content').html('<center><img src="/skin1/images/ajax-bar-loader.gif" /></center>');
      $('#selected-content').fadeIn('fast');
    });

    $.get(addr, function(result){
        result = result.replace("<html", "<myhtml");
        result = result.replace("</html", "</myhtml");
        result = result.replace("<body", "<mybody");
        result = result.replace("</body", "</mybody");

        $data = $('.dialog-c-content', result);
        LoadAjaxData.cache[addr] = $data;

      $('#selected-content').hide();
      $('#selected-content').html($data);
      $('#selected-content').fadeIn('slow');

    });
  }else{
      $('#selected-content').fadeOut('fast');
      $('#selected-content').html(LoadAjaxData.cache[addr]);
      $('#selected-content').fadeIn('slow');
  }

}

$('.ajaxLoaded').live('click', function(){LoadAjaxData(this);return false;});
