var dakota = {
	src: '/dakota.swf'
    };
//
	sIFR.activate(this.dakota);
function init_sIFR() {
	sIFR.replace(this.dakota, {
		selector: 'h1'
		,css: [
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #000000; color: #fcee21;  }'
			,'a { text-decoration: none; }'
			,'a:link { color: #000000; }'
			,'a:hover { color: #CCCCCC; }'
		],offsetLeft:3
		,tuneWidth :-10
		,filters: {Glow: {
			strength:1,
			blurY:20,
			blurX:20,
			knockout:false,
			quality:1,
			color:'#fcee21'
        }}
	});
	sIFR.replace(this.dakota, {
		selector: 'h2.dakota'
		,css: [
			'.sIFR-root { text-align: right; font-weight: normal; background-color: #000000; color: #fcee21;  }'
			,'a { text-decoration: none; }'
			,'a:link { color: #000000; }'
			,'a:hover { color: #CCCCCC; }'
		],offsetLeft:3
		,tuneWidth :-10
		,filters: {Glow: {
			strength:1,
			blurY:20,
			blurX:20,
			knockout:false,
			quality:1,
			color:'#fcee21'
        }}
	});
	sIFR.replace(this.dakota, {
		selector: 'h3.dakota'
		,css: [
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #000000; color: #fcee21;  }'
			,'a { text-decoration: none; }'
			,'a:link { color: #000000; }'
			,'a:hover { color: #CCCCCC; }'
		],offsetLeft:3
		,tuneWidth :-5
		,filters: {Glow: {
			strength:1,
			blurY:20,
			blurX:20,
			knockout:false,
			quality:1,
			color:'#fcee21'
        }}
	});
	sIFR.replace(this.dakota, {
		selector: 'legend.dakota'
		,css: [
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #000000; color: #fcee21;  }'
			,'a { text-decoration: none; }'
			,'a:link { color: #000000; }'
			,'a:hover { color: #CCCCCC; }'
	  	],
	  	forceWidth:true,
	  	tuneHeight:3
	  	,offsetTop:3
	  	,offsetLeft:3
	  	,tuneWidth :5
	  	,filters: {Glow: {
			strength:1,
			blurY:20,
			blurX:20,
			knockout:false,
			quality:1,
			color:'#fcee21'
        }}
	}); 
	sIFR.replace(this.dakota, {
		selector: 'h4.dakota'
		,css: [
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #000000; color: #29abe2;  }'
			,'a { text-decoration: none; }'
			,'a:link { color: #000000; }'
			,'a:hover { color: #CCCCCC; }'
	  	],offsetLeft:3
	  	,tuneWidth :5
	  	,filters: {Glow: {
			strength:1,
			blurY:20,
			blurX:20,
			knockout:false,
			quality:1,
			color:'#29abe2'
        }}
	});
}
window.addEvent('domready',function(e) {init_sIFR()});

window.addEvent('domready',function(e) {init_Behaviour()});

function init_Behaviour() {
	$('beachheader').addEvent('click',function() {document.location='/'});
	$('beachheader').setStyle('cursor','pointer');
	
	
	var externallinks = $$("a").filter(function(el) {
        return (el.rel && el.rel.test(/^external/i)) || (el.href && !el.href.test(/^http:\/\/beach.donitas\.nl/i) && el.href.test(/^http/i));
    });

    externallinks.each(function(el) {
        $(el).setAttribute('target', '_blank');
        el.addClass('external');
    });
	
	externallinks.each(function(el) {
						  
						  
		el.addEvent('click',function(ev) { 
			
			var t = ev.target;
			while(t != null && t.nodeName != 'A') {
				t = t.parentNode;	
			}
			if (t != null) {
				pageTracker._trackPageview(t.href);
			}
		} );						   
	} );
	
}

var images = [
                	
                	{ 'src': '/img/footer/1.png' }
                	,
                	{ 'src': '/img/footer/2.png' }
                	,
                	{ 'src': '/img/footer/3.png' }
                	,
                	{ 'src': '/img/footer/4.png' }
                	,
                	{ 'src': '/img/footer/5.png' }
                	,
                	{ 'src': '/img/footer/6.png' }
                	,
                	{ 'src': '/img/footer/7.png' }
                	,
                	{ 'src': '/img/footer/8.png' }
                	,
                	{ 'src': '/img/footer/9.png' }
                	,
                	{ 'src': '/img/footer/10.png' }
                	,
                	{ 'src': '/img/footer/11.png' }
                	,
                	{ 'src': '/img/footer/12.png' },
                	{ 'src': '/img/footer/13.png' },
                	{ 'src': '/img/footer/1.jpg' },
					{ 'src': '/img/footer/2.jpg' },
					{ 'src': '/img/footer/3.jpg' },
					{ 'src': '/img/footer/4.jpg' },
					{ 'src': '/img/footer/5.jpg' },
					{ 'src': '/img/footer/6.jpg' },
					{ 'src': '/img/footer/7.jpg' },
					{ 'src': '/img/footer/8.jpg' },
					{ 'src': '/img/footer/9.jpg' },
					{ 'src': '/img/footer/10.jpg' },
					{ 'src': '/img/footer/11.jpg' },
					{ 'src': '/img/footer/12.jpg' },
					{ 'src': '/img/footer/13.jpg' },
					{ 'src': '/img/footer/14.jpg' },
					{ 'src': '/img/footer/15.jpg' },
					{ 'src': '/img/footer/16.jpg' },
					{ 'src': '/img/footer/17.jpg' },
					{ 'src': '/img/footer/18.jpg' },
					{ 'src': '/img/footer/19.jpg' },
					{ 'src': '/img/footer/20.jpg' },
					{ 'src': '/img/footer/21.jpg' },
					{ 'src': '/img/footer/22.jpg' },
					{ 'src': '/img/footer/1.png' }
                	,
                	{ 'src': '/img/footer/2.png' }
                	,
                	{ 'src': '/img/footer/3.png' }
                	,
                	{ 'src': '/img/footer/4.png' }
                	,
                	{ 'src': '/img/footer/5.png' }
                	,
                	{ 'src': '/img/footer/6.png' }
                	,
                	{ 'src': '/img/footer/7.png' }
                	,
                	{ 'src': '/img/footer/8.png' }
                	,
                	{ 'src': '/img/footer/9.png' }
                	,
                	{ 'src': '/img/footer/10.png' }
                	,
                	{ 'src': '/img/footer/11.png' }
                	,
                	{ 'src': '/img/footer/12.png' },
                	{ 'src': '/img/footer/13.png' }
                		];

function init_footer() {

	
	var footercontainer = new Element('div',{'id':'footercontainer'});
	images = images.shuffle();
	for (i = 0; i < 12;i++) {
		var x = new Element('div',{'class':'fotofader'});
		var y = new Element('a');
		var z = new Element('img',{'src':images[i].src});
		y.appendChild(z);
		x.appendChild(y);
		footercontainer.appendChild(x);
		
	}
	$('footer').appendChild(footercontainer);
	slider = new Slideshow($$('.fotofader'), $A(images), 12*250, 250);
	
}

Array.prototype.shuffle = function() {
    return this.sortBy(Math.random);
};

Array.prototype.sortBy = function(iterator, context) {
    return this.map(function(value, index) {
      return {
        value: value,
        criteria: iterator.call(context, value, index)
      };
    }).sort(function(left, right) {
      var a = left.criteria, b = right.criteria;
      return a < b ? -1 : a > b ? 1 : 0;
    }).pluck('value');
  }
  
Array.prototype.pluck = function(property) {
    var results = [];
    this.each(function(value) {
      results.push(value[property]);
    });
    return results;
  },
  

window.addEvent('domready',function(e) {init_footer()});

var Slideshow = new Class({
    initialize: function(elements, photos, speed, opacityspeed) {
        this.elements = elements;
        this.photos = photos;
        this.speed = speed;
        this.opacityspeed = opacityspeed;
        this.displayPool = photos.shuffle();
        this.nextContainerId = 0;
        
        this.preloader = new Preloader();
        for (var index = 0, len = this.photos.length; index < len; ++index) {
            this.preloader.add(this.photos[index].src);
        }
        this.preloader.load();
        var intervalID = this.nextContainer.periodical(this.speed / this.elements.length,this);
        //new PeriodicalExecuter(this.nextContainer.bind(this), ((this.speed * 1000) / this.elements.length) / 1000);
    },
    nextContainer: function() {
    	
        this.display(this.elements[this.nextContainerId]);
        this.nextContainerId = (this.nextContainerId + Math.ceil(Math.random()*(this.elements.length-2))) % this.elements.length;
    }
    ,
    display: function(container) {
    	
        var img = this.displayPool.pop();
        var ahref = new Element('a',{'class':'fadepicture'});
        if (img.href != null) {
            ahref.href = img.href;
            ahref.target = 'blank';
        }
        ahref.setStyles({ position: 'absolute', left: 0, top: 0, opacity: 0, width: container.getSize().x + 'px', height: container.getSize().y + 'px'});

        var imgelement = new Element('img');

        imgelement.src = img.src;
        ahref.appendChild(imgelement);

        var olda = container.getFirst();
        var oldimg = olda.getFirst();
        
        container.appendChild(ahref);

        //fadeineffect = new Effect.Opacity(ahref, { from: 0, to: 1.0, duration: this.opacityspeed });
        //fadeouteffect = new Effect.Opacity(olda[0], { from: 1.0, to: 0.0, duration: this.opacityspeed, delay: this.opacityspeed, afterFinish: function(el) { el.element.parentNode.removeChild(el.element) } });
		ahref.set('tween', {duration: this.opacityspeed});
		olda.set('tween', {duration: this.opacityspeed});
		
        ahref.tween('opacity',1);
        //olda.tween.delay(this.opacityspeed,olda,'opacity',0);
        
        this.cleanUp.delay(2 * this.opacityspeed,this,container,olda);
    },cleanUp : function (container,olda) {
		var olda = container.getFirst();
    	var oldimg = olda.getFirst();
		if (olda.hasClass("fadepicture")) {
        	
            this.displayPool.push({ 'src': oldimg.src, 'href': olda.href });
            this.displayPool = this.displayPool.shuffle();
        }
		container.removeChild(olda);
    }
});


var Preloader = new Class({
initialize: function() {
  this.callbacks = [];
  this.images = [];
  this.loadedImages = [];
  this.imagesLoaded = 0;
  },

  add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object') {
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = this.checkFinished.bind(this);
      this.loadedImages[i].src = this.images[i];
    }
  },
  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  }
});

//