var DynamicPhotoContent = Class.create({
	
	container: "dynamicphotocont",
	
	initialize: function() {
		
		var photos = [];
		photos[0] = "./images/molen-zw1.jpg";
		photos[1] = "./images/molen-zw2.jpg";
		photos[2] = "./images/molen-zw3.jpg";
		photos[3] = "./images/molen-zw4.jpg";
		photos[4] = "./images/molen-zw5.jpg";
		photos[5] = "./images/molen-zw6.jpg";
		photos[6] = "./images/molen-zw7.jpg";
		
		this.photos = this.shuffle(photos);
		var key = 0;
		this.animatePhoto(key);
	
	},
	
	animatePhoto: function(key, loop) {
		
			
			var curPhoto = this.photos[key];
			if(key == (this.photos.length - 1)) {
				var nextPhoto = this.photos[0];
				key = 0;
			} else {
				var nextPhoto = this.photos[key+1];
			}
			
			var img1  = document.createElement("IMG");
			var img2  = document.createElement("IMG");
			img1.src = curPhoto;
			img2.src = nextPhoto;
			
			$("photocontainer1").setOpacity(1);
			$("photocontainer1").innerHTML = '';
			$("photocontainer2").innerHTML = '';
			$("photocontainer1").appendChild(img1);
			$("photocontainer2").appendChild(img2);
	
			var attributes = {
		        opacity: { to: 0 }
		    };
		    var anim = new YAHOO.util.Anim('photocontainer1', attributes);
		    var instance = this;
		    setTimeout(function() {
				anim.animate();
				anim.onComplete.subscribe(function() {
					var firstDescendant = $("photocontainer1").firstDescendant();
					$(firstDescendant).remove();
					if(key == instance.photos.length) {
						var index = 0;	
					} else {
						var index = key + 1;	
					}
					
					setTimeout(function() {
						instance.animatePhoto(index)
					}, 2000);
				});
	   		}, 2000);
	},
	
	shuffle:function(o){
		for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
		return o;
	}

});
