Element.extend({
    shake : function(amt){
        var a = (amt || 20), b = -1 * a, f = this.effect('left', { duration:200 } );
        f.start(0,b)   .chain(function(){
        f.start(b,a) }).chain(function(){
        f.start(a,b) }).chain(function(){
        f.start(b,0) });
    }
});

var Background = Class.create();
Background.Resize = function() {
  	var em = $E('body').getStyle('font-size').toInt();
  
	var summary = ((($E('body').hasClass('home')) ? 140 : 92) - $E('#summary div.inner').getLeft()) / em;
	summary = (summary < 0) ? 0 : -summary;
	$E('#summary').setStyle('background-position', summary +'em bottom');
	
	var artists = ($E('#artists div.inner').getLeft() + $E('#artists div.inner').getSize()['size']['x']) / em;
	$E('#artists').setStyle('background-position', artists +'em bottom');
	
	var thema = ($E('#thema div.inner').getLeft() + $E('#thema div.inner').getSize()['size']['x']) / em;
	$E('#thema').setStyle('background-position', thema +'em bottom');
	
	var pratique = ($E('#practice div.inner').getLeft() + $E('#practice div.inner').getSize()['size']['x']) / em;
	$E('#practice').setStyle('background-position', pratique +'em bottom');
	
	var weblog = ($E('#weblog div.inner').getLeft() + $E('#weblog div.inner').getSize()['size']['x']) / em;
	$E('#weblog').setStyle('background-position', weblog +'em bottom');
};


var Slide = Class.create();
Slide.Load = function(images) {
	var loaded = [];
	new Asset.images(images, {
		onProgress: function(i) {
			loaded[i] = this;
		},
		onComplete: function() {
			var timer = 0;
			loaded.each(function(image, i) {
				timer += 2500;
				fx = function() {
					$E('#partners img').remove();
					image.injectInside($E('#partners a'));
				}.delay(timer * 2);
			});
		}
	});
}

var Player = Class.create();
Player.Open = function(id) {
	if(id) {
		window.open('/radio/listen/'+ id +'/', 'player', 'height=250,width=250');
	} else {
		window.open('/radio/stream/', 'stream', 'height=250,width=250');
	}
}

var Webcam = Class.create();
Webcam.CountDown = function(id) {
	counter = $E('#'+ id +' .refresh');
	current = counter.getText();
	now = current - 1;
	if(now == 0) {
		$E('#'+ id +' img').remove();
		img = new Asset.image('http://webcam.esperanzah.be/'+ id +'.jpg');
		img.injectTop($(id));
		now = 60;
	}
	counter.setText(now);
	(function() { Webcam.CountDown(id) }).delay(1000);
}

var Highlight = Class.create();
Highlight.start = function() {
	$('listen').setStyle('position', 'relative');
	$('listen').shake();
}

window.addEvents({
	'resize': function() {
		Background.Resize();
	},
	'domready': function() {
		Background.Resize();
	}
});
