
var SnowControl = Class.create( {

  // Set the number of snowflakes (more than 30 - 40 not recommended)
  snowmax : 200,

  // Set the colors for the snow. Add as many colors as you like
  snowcolor : new Array("#aaaacc","#ddddFF","#ccccDD"),

  // Set the fonts, that create the snowflakes. Add as many fonts as you like
  snowtype : new Array("Arial Black","Arial Narrow","Times","Comic Sans MS"),

  // Set the letter that creates your snowflake (recommended:*)
  snowletter : "*",

  // Set the speed of sinking (recommended values range from 0.3 to 2)
  sinkspeed : 0.6,

  // Set the maximal-size of your snowflaxes
  snowmaxsize : 22,

  // Set the minimal-size of your snowflaxes
  snowminsize : 8,

  // Set the snowing-zone
  // Set 1 for all-over-snowing, set 2 for left-side-snowing 
  // Set 3 for center-snowing, set 4 for right-side-snowing
  snowingzone : 1,



  // end of configuration
  snow : new Array(),
  marginbottom  :  0,  
  marginright  :  0,
  timer  :  0,
  i_snow : 0,
  x_mv : new Array(),
  crds : new Array(),
  lftrght : new Array(),

  // initialisierung
  initialize : function () {

    this.anchor = $('anchor');


    this.marginbottom = document.viewport.getHeight();
    this.marginright = document.viewport.getWidth()
  
    var snowsizerange=this.snowmaxsize-this.snowminsize;

    for (i=0;i<this.snowmax;i++) {

       this.crds[i] = 0;
       this.lftrght[i] = Math.random()*15;
       this.x_mv[i] = 0.03 + Math.random()/10;

       this.createSnowFlake( i );

       this.snow[i]=$("s"+i);
       this.snow[i].style.fontFamily=this.snowtype[this.randommaker(this.snowtype.length)];
       this.snow[i].size=this.randommaker(snowsizerange)+this.snowminsize;
       this.snow[i].style.fontSize=this.snow[i].size;
       this.snow[i].style.color=this.snowcolor[this.randommaker(this.snowcolor.length)];
       this.snow[i].sink=this.sinkspeed*this.snow[i].size/5;

       if (this.snowingzone==1) {this.snow[i].posx=this.randommaker(this.marginright-this.snow[i].size)}
       if (this.snowingzone==2) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)}
       if (this.snowingzone==3) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)+this.marginright/4}
       if (this.snowingzone==4) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)+this.marginright/2}

       this.snow[i].posy=this.randommaker(2*this.marginbottom-this.marginbottom-2*this.snow[i].size);
       this.snow[i].style.left = parseInt(this.snow[i].posx, 10) + "px" ;
       this.snow[i].style.top = parseInt(this.snow[i].posy, 10) + "px";


    }

    this.snowMove = this.movesnow.bind(this);
     
    new PeriodicalExecuter( this.snowMove ,0.05 );


  },

  createSnowFlake : function ( i ) {

   var span = new Element( 'span',{  'id': 's' + i } );
   var stop = "-" + parseInt( this.snowmaxsize, 10 ) + "px";

   span.setStyle( { position: 'absolute', zIndex: '500', top: stop, left: '0' } );

   span.update( this.snowletter );
   this.anchor.appendChild( span );

  },


  randommaker : function( range ) {

    var rand = Math.floor( range*Math.random() );
    return rand;
  },

  movesnow : function() {

    for (i=0;i<this.snowmax;i++) {
      this.crds[i] += this.x_mv[i];
      this.snow[i].posy+=this.snow[i].sink;
      this.snow[i].style.left = parseInt(this.snow[i].posx+this.lftrght[i]*Math.sin(this.crds[i]), 10) + "px";
      this.snow[i].style.top = parseInt(this.snow[i].posy, 10) + "px";

      if (this.snow[i].posy>=this.marginbottom-2*this.snow[i].size || parseInt(this.snow[i].style.left, 10)>(this.marginright-3*this.lftrght[i])) {
       if (this.snowingzone==1) {this.snow[i].posx=this.randommaker(this.marginright-this.snow[i].size)}
       if (this.snowingzone==2) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)}
       if (this.snowingzone==3) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)+this.marginright/4}
       if (this.snowingzone==4) {this.snow[i].posx=this.randommaker(this.marginright/2-this.snow[i].size)+this.marginright/2}
 
       this.snow[i].posy=0;
      }
    }
//    this.timer=setTimeout("this.movesnow",50)
}



} );



  var PageControl = Class.create( {


  // initialisierung
  initialize : function ( pageID ) {

   this.pageID = pageID;

   this.base = 'index.php?id=';

   var s = '{ "navi_01": {"id":"4","text":"Willkommen"}, "navi_02": {"id":"5","text":"Programm"}, "navi_03": {"id":"6","text":"Bildergalerie"}, "navi_04": {"id":"7","text":"Anfahrt"}, "navi_05": {"id":"8","text":"Gruppenangebote"}, "navi_06": {"id":"9","text":"Kontakt"}, "subnavi_01": {"id":"10","text":"Ausstellerbereich"}, "subnavi_02": {"id":"11","text":"Presse"}, "subnavi_03": {"id":"12","text":"Impressum"} }';

   this.menu = s.evalJSON(true);

   this.navis = $('anchor').select('.navi');

   this.navis.each (

        function ( e ) {

                         var t = e.down();
                         t.src = '/fileadmin/images/' + e.id + (( this.menu[e.id].id == this.pageID ) ? 'a.' : 'p.');
                         t.src += ( e.id.indexOf('sub') == 0) ? 'gif' : 'jpg';
                         t.setAttribute('alt', this.menu[e.id].text);
                         t.setAttribute('title', this.menu[e.id].text);
                         t.on('mouseover', this.rollOver.bindAsEventListener( this ));
                         t.on('mouseout', this.rollOut.bindAsEventListener( this ));
                         t.on('click', this.click.bindAsEventListener( this, this.menu[e.id].id ));
                
                       } , this );
   
     //alert( 'pageID = ' + this.pageID );

    // set opernpalais
    // $('opernpalais').on('click', this.goToOpernpalais.bindAsEventListener(this));

    this.snow = new SnowControl();
  
  },

  goToOpernpalais : function ( e ) {

   window.open('http://www.opernpalais.de');
  },


  rollOver : function ( o ) {

   var el = o.element();
   var id = el.up().id;
   this.src = el.src;
   el.src = '/fileadmin/images/' + id + 'a.';
   el.src += ( id.indexOf('sub') == 0) ? 'gif' : 'jpg';
  },

  rollOut : function ( o ) {
  
   var el = o.element();
   el.src = this.src;
  },


  click : function ( o, id ) {

   window.location.href= this.base + id;
  }
 }
);





