// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


var news_rotator = {
  periodical_executer: null,

  manually_next: function() {
    news_rotator.stop();
    news_rotator.rotate();
  },

  manually_last: function() {
    news_rotator.stop();
    news_rotator.rotate(123, true);
  },

  stop: function() {
    if (!news_rotator.periodical_executer)
      return;
    new Ajax.Request('/rotator/stop');
    $('autorotate_controll').addClassName('disabled');
    $('autorotate_controll').removeClassName('enabled');
    news_rotator.periodical_executer.stop();
    news_rotator.periodical_executer = null;
  },

  run: function() {
    if (news_rotator.periodical_executer)
      return;
    var ctrl = $('autorotate_controll');
    if (ctrl) {
      new Ajax.Request('/rotator/start');
      ctrl.addClassName('enabled');
      ctrl.removeClassName('disabled');
    }
    news_rotator.periodical_executer = new PeriodicalExecuter(news_rotator.rotate,20);
  },

  rotate: function (frequency, do_it_reverse) {
    new Effect.BlindUp('content_outer', {
      afterFinish: function(){
        var rotation_counter = parseInt($('rotation_counter').innerHTML, 10);
        if (typeof do_it_reverse != 'undefined') {
          rotation_counter = rotation_counter * -1;
        }
      	new Ajax.Updater('content_inner', window.location.href, {
          method: 'get',
          parameters: "o="+rotation_counter,
          onSuccess: function() { new Effect.BlindDown('content_outer') }
        });
      }
    });
  }
}


Array.prototype.shuffle = function(){
  var tmp, rand;
  for(var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i];
    this[i] = this[rand];
    this[rand] =tmp;
  }
}

var mouseover = {
  list_img: function(img,width,height) {
    return overlib(' ',FGBACKGROUND,img,WIDTH,width,HEIGHT,height,HAUTO,VAUTO);
  },
  list_summary: function(text) {
    return overlib(text,WIDTH,350);
  }
}

var update_links = function() {
  $$('a[href]').each(function(e){
  if (e.href.match(/reiseangebote\/\d/)) {
    e.href = e.href.replace(/reiseangebote\/(\d+).*$/, 'to/$1/portal');
  }
  });
}

FastInit.addOnLoad(update_links);

/* http://www.kurzurlaub.de/ap_admin/files/anleitung_integration_kurzurlaub_iframe.txt */
function resizeFrame(h, noScroll){ 
  if(!noScroll) scroll(0,0);
  var iFrame = document.getElementById('main_iframe_ap');
  if(!iFrame) return false;
  iFrame.style.height = parseInt(h+20)+'px';
  iFrame.height = h+20;
  return true;
}