//new Ajax.PeriodicalUpdater("marktdaten","http://entwicklung.investor-facts.de/ajax/prototype_top_flops.php?indices=DAX", {  frequency: 3, evalScripts: true});
//div muss wie objekt heissen
//div mit status icon muss "div"_status_icon heissen
var ir_portal_auto_refresh = Class.create({
  initialize: function(ziel_div, ajax_anfrage) {
    this.ziel_div  = ziel_div;
    this.auto_refresh=false;
    this.timeout=false;
    this.prototype_periodical_updater=false;
    this.ajax_anfrage=ajax_anfrage;
  },

	//public
  change_auto_refresh: function() {
    this.stop_prototype_periodical_updater();
    this.auto_refresh = !this.auto_refresh;
    this.show_status_icon(); 	
    if(this.auto_refresh){
    	this.init_prototype_periodical_updater();
    }
    else{
    	this.prototype_periodical_updater=false;
    }
  },
  
  //private
  normales_ajax_update: function() {
  	new Ajax.Updater({ success: this.ziel_div },this.ajax_anfrage, {  evalScripts: true});
  },
  
  //private
  init_prototype_periodical_updater: function() {
  	this.prototype_periodical_updater = new Ajax.PeriodicalUpdater({ success: this.ziel_div },this.ajax_anfrage, {  frequency: 3, evalScripts: true});
  	this.timeout=setTimeout(this.ziel_div+".change_auto_refresh()", 1*60000); //minuten
  },
  
  //private
  stop_prototype_periodical_updater: function() {
    if( this.prototype_periodical_updater !== false ){
    	this.prototype_periodical_updater.stop();
    }
  	if( this.timeout !== false ){
  		clearTimeout(this.timeout);
  		this.timeout = false;
  	}    
  },
 
  //public
  start: function(ajax_anfrage) {
  	this.change_ajax_anfrage(this.ajax_anfrage);
  	this.show_status_icon(); 	
  },
  	 
  //public
  change_ajax_anfrage: function(ajax_anfrage) {
  	this.stop_prototype_periodical_updater();
  	this.ajax_anfrage = ajax_anfrage;
  	if(this.auto_refresh){
  		this.init_prototype_periodical_updater();
  	}
  	else{
  		this.normales_ajax_update();
  	}
  },
  
	show_status_icon: function() {
	if( this.auto_refresh === true )
		$(this.ziel_div+'_status_icon').innerHTML='<a class="druck_small" onclick=" '+this.ziel_div+'.change_auto_refresh();" style="cursor: pointer;"><img vspace="0" hspace="0" style="padding-right: 2px;border-color:#CCCCCC;" src="/images/b_realtime.gif" alt="Push stoppen" border="0" title="Push stoppen"/></a>';
	else
		$(this.ziel_div+'_status_icon').innerHTML='<a class="druck_small" onclick=" '+this.ziel_div+'.change_auto_refresh();" style="cursor: pointer;"><img vspace="0" hspace="0" style="padding-right: 2px;border-color:#CCCCCC;" src="/images/b_delayed.gif" alt="Push starten" border="0" title="Push starten" /></a>'; 		 	
	}     
});

var werbung_ein_aus = Class.create({
  initialize: function(ziel_div) {
    this.ziel_div  	= ziel_div;
    this.ajax_anfrage='http://entwicklung.investor-facts.de/ajax/werbung_div.php?div='+ziel_div;
    this.start();
  },
  start: function(){
  	setTimeout(this.ziel_div+".ein()", 10*1000);	
  },
  ein: function(){
  	new Ajax.Updater( this.ziel_div ,this.ajax_anfrage, {  evalScripts: true});
		Effect.Appear(this.ziel_div);
		setTimeout(this.ziel_div+".aus()", 20*1000);	
  },
  aus: function(){
		Effect.Fade(this.ziel_div);
		setTimeout(this.ziel_div+".ein()", 10*1000);	
  } 
});
