/*  Banner Interactive Rotation
 *  (c) 2006 Flurin Egger <flurin@entopic.com>
 *  BIR is freely distributable under the terms of an MIT-style license.
 *  version 0.0.1 - 2006.03.27
/* --------------------------------------------------------------------------*/

// From prototype.lite 

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

//note: In this file included are Moo.fx and prototype.lite
//note: Banner methods _setupContainer and _setupContentElements need customization

var Banner = Class.create();
Banner.prototype = {
	initialize: function(image){
		this.image = $(image);
		this.currentMessage = 0;
		this.messageTimeout = 5000; // ms
		
		if(arguments.length > 1){
			this.messages = arguments[1];
		}
		
		this._createBanner();
	},
	_createBanner: function(){			
		this._setupContainer();
		this._setupContentElements();
		this.startRotation();
	},
	startRotation: function(){
		if(!this.effect){	this._setupEffect();	}
		if(!this.messages) { return; }
		this.effect.toggle();	
	},
	setMessage: function(id){
		var m = this.messages[id];
		this.link_el.href = m.link;
		this.title_el.innerHTML = m.title;
		this.body_el.innerHTML = m.body;
	},
	_setupEffect: function(){
		this.effect = new fx.Opacity(this.link_el,{duration:500, onComplete:function(){this._effectCycle()}.bind(this)});			
	},
	_effectCycle: function(){
		if(this.effect.now == 0){
			if(this.currentMessage == (this.messages.length - 1)){ this.currentMessage = 0;} else {this.currentMessage++;}	
			this.setMessage(this.currentMessage);		
			this.effect.toggle();
		}
		if(this.messages.length > 1){
			setTimeout(function(){this.effect.toggle()}.bind(this),this.messageTimeout);
		}
	},
	_setupContainer: function(){
		this.container_el = document.createElement("SPAN");
		this.container_el.style.display = "block";
		if(this.image && this.image.width){
			this.container_el.style.width = this.image.width + "px";
			this.container_el.style.height = this.image.height + "px";			
		} else {
			this.container_el.style.width = "140px";
			this.container_el.style.height = "400px";			
		}
		
		this.container_el.style.paddingTop = "1px";
		this.container_el.style.overflow = "hidden";
		this.container_el.style.visibility = "visible";
		
		this.container_el.style.background = "url("+this.image.src+") #fff 0 0 no-repeat";					

		this.image.parentNode.replaceChild(this.container_el,this.image);
	},
	_setupContentElements: function(){
		this.link_el = document.createElement("A");
		this.title_el = document.createElement("STRONG");
		this.body_el = document.createElement("SPAN");	
				
		this.link_el.style.display = "block";
		this.link_el.style.margin = "175px 7px 7px 7px";
		this.link_el.style.fontFamily = "verdana, sans-serif";
		this.link_el.style.fontSize = "12px";
		this.link_el.style.fontWeight = "bold";
		this.link_el.style.color = "#022A9E";
		this.link_el.style.textDecoration = "none";	
		this.link_el.style.textAlign = "left";
				
		this.title_el.style.display = "block";
		this.title_el.style.marginBottom = "20px";
		this.title_el.style.fontSize = "14px";
		this.title_el.style.textDecoration = "underline";
		
		this.body_el.style.color = "#000";
		this.body_el.style.fontWeight = "normal";	

		this.container_el.appendChild(this.link_el);						
		this.link_el.appendChild(this.title_el);
		this.link_el.appendChild(this.body_el);
	}
}

/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
//note: even more stripped down to be used with BIR.

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

//useful array functions
Array.prototype.each = function(func){
	for(var i=0;ob=this[i];i++) func(ob, i);
}

function $c(array){
	var nArray = [];
	for (i=0;el=array[i];i++) nArray.push(el);
	return nArray;
}

/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
Sunday, March 05, 2006
v 1.2.3
*/

var fx = new Object();
//base
fx.Base = function(){};
fx.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 500,
		onComplete: '',
		transition: fx.sinoidal
	}
	Object.extend(this.options, options || {});
	},

	step: function() {
		var time  = (new Date).getTime();
		if (time >= this.options.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			var Tpos = (time - this.startTime) / (this.options.duration);
			this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from;
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
}

//fader
fx.Opacity = Class.create();
fx.Opacity.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.now = 1;
		this.increase();
		this.setOptions(options);
	},

	increase: function() {
		if (this.now == 1 && (/Firefox/.test(navigator.userAgent))) this.now = 0.9999;
		this.setOpacity(this.now);
	},
	
	setOpacity: function(opacity) {
		if (opacity == 0 && this.el.style.visibility != "hidden") this.el.style.visibility = "hidden";
		else if (this.el.style.visibility != "visible") this.el.style.visibility = "visible";
		if (window.ActiveXObject) {this.el.style.filter = "alpha(opacity=" + opacity*100 + ")";}
		this.el.style.opacity = opacity;
	},

	toggle: function() {
		if (this.now > 0) this.custom(1, 0);
		else this.custom(0, 1);
	}
});

//transitions
fx.sinoidal = function(pos){
	return ((-Math.cos(pos*Math.PI)/2) + 0.5);
	//this transition is from script.aculo.us
}


/* ====================================================== 
 * Dynamic generated content
/* ====================================================== */

	var vacatures = new Array(
	
	{
		link: "http://cv.webredacteur.nl/banner/click/59",
		title: "Aan de slag als webredacteur?",
		body: "<img src=\"http://www.webredacteur.nl/banners/balgroen.gif\" style=\"border: none;\"/> Schrijf je in op: webredactiebank.nl"	
	},
	
	{
		link: "http://cv.webredacteur.nl/banner/click/60",
		title: "Gezocht: webredacteur",
		body: "meerdere vacatures:<br>\n<br>\n<img src=\"http://www.webredacteur.nl/banners/balgroen.gif\" style=\"border: none;\"/>&nbsp;webredacteur<br>\n<br>\n<img src=\"http://www.webredacteur.nl/banners/balgroen.gif\" style=\"border: none;\"/>&nbsp;contentmanager<br>\n<br>\n<img src=\"http://www.webredacteur.nl/banners/balgroen.gif\" style=\"border: none;\"/>&nbsp;parttime redacteur<br>\n"	
	},
	
	{
		link: "http://cv.webredacteur.nl/banner/click/61",
		title: "Cursus webredactie",
		body: "Online schrijven is een vak\n<br>\n<br>\n<img src=\"http://www.webredacteur.nl/banners/balgroen.gif\" style=\"border: none;\"/>&nbsp;Cursus<br>\n&nbsp;&nbsp;&nbsp;&nbsp;Webredactie\n&nbsp;&nbsp;&nbsp;&nbsp;"	
	}
	
	);
	
	var b = new Banner("_entopic_banner_140x400",vacatures);