window.addEvent('domready',function() {
  // Transparency hack for IE 6
  if (Browser.Engine.trident4) {
    $$('img[src$=.png]').setStyle('behavior','url(/_scripts/pngfix.htc)');
  }
  
  var currentHead = $('headerfoto').getStyle('background-image');
  var tmpArr;
  
  switch(true) {
    case currentHead.test('staminagroup'):
      tmpArr = ['staminagroup/head1','staminagroup/head2','staminagroup/head3','staminagroup/head4','staminagroup/head5'];
      break;
    case currentHead.test('safarifresh'):
      tmpArr = ['safarifresh/head1','safarifresh/head2','safarifresh/head3','safarifresh/head4','safarifresh/head5','safarifresh/head6'];
      break;
  }
  
  var mySlide = new bgSlide($('headerfoto'),tmpArr,{period:6000});
  
  $$('.smallColumn').addEvent('click',function() {
    location.href = this.getElement('h2 a').getProperty('href');
  });
  
  // Popup
  /*if((location.hostname == 'stamina.online.local' || location.hostname == 'www.staminagroup.eu') && isHomepage()) { 
    window.open('/popup.html','','width=720,height=650');
  }*/
  
  Shadowbox.init();
  
});

/**
 * bgSlide
 *
 * A modified mooSimpeleSlide class - http://code.google.com/p/moosimpeleslide/
 * It changes the background-image instead of images from a list (or something)
 * 
 * copyright 2009 04 02 - Huug Helmink - www.huughelmink.nl
 */
var bgSlide = new Class({
  Implements: Options,
  options: {
    period: 5000
  },
  initialize: function(element,imageArray,options) {
    // Check if imageArray is an array
    if($type(imageArray) != 'array') return;

    this.element = element
    this.images = imageArray;
    this.setOptions(options);
    this.active = 0;
    this.max = this.images.length;
    
    // If period options is set > 0, periodical display an image
    if(this.options.period > 0) this.displayImage.periodical(this.options.period,this);
  },

  displayImage: function() {
    var FxTransitionTime = this.options.period/5;
    
    // Hide image
    this.element.get('tween',{property:'opacity', duration:FxTransitionTime, onComplete:function(item) {
      item.setStyle('display','none');
    }}).start(1,0);
    
    // Set next image or the first
    this.active < this.max-1 ? this.active++ : this.active = 0;
    
    // Show image
    this.element.get('tween',{property:'opacity', duration:FxTransitionTime, onStart:function(item) {
      item.setStyles({
        'background-image':'url(/_images/'+ this.images[this.active] +'.jpg)',
        'display':'inline'
      });
    }.bind(this)}).start(0,1);
  }
});


function isHomepage() {
  var result = false;
  
  var tmp = location.href.replace('http://' + location.hostname,'');
  
  if(tmp.toLowerCase() == '/default.aspx' || tmp == '/') {
    return true;
  } else {
    return false;
  }
}
