function initVacatureWidget(){var c={};c.vacatures=[];c.enhanceVacatures=function(){this.select_el=YAHOO.util.Dom.get("vw-select");this.progress_el=YAHOO.util.Dom.get("vw-progress");YAHOO.util.Dom.removeClass(this.progress_el,"hidden");YAHOO.util.Dom.removeClass(this.select_el,"hidden");for(var b=YAHOO.util.Dom.getElementsByClassName("vw-vacature","div",document.body),f=this.select_el.getElementsByTagName("a"),a=0;a<b.length;a++){this.vacatures[a]={};this.vacatures[a].vacature={};this.vacatures[a].vacature.element= b[a];this.vacatures[a].vacature.select=f[a];YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("vw-holder"),"position","relative");YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("vw-holder"),"height","110px");YAHOO.util.Dom.setStyle(this.vacatures[a].vacature.element,"position","absolute");this.vacatures[a].vacature.select.i=a;YAHOO.util.Event.on(this.vacatures[a].vacature.select,"click",function(d){var e=YAHOO.util.Event.getTarget(d);e.blur();this.stopAnimation();this.startAnimation(e.i);YAHOO.util.Event.preventDefault(d)}, this,true)}for(a=1;a<this.vacatures.length;a++){YAHOO.util.Dom.setStyle(this.vacatures[a].vacature.element,"opacity","0");YAHOO.util.Dom.setStyle(this.vacatures[a].vacature.element,"display","block")}this.curr=0;YAHOO.util.Dom.addClass(this.vacatures[this.curr].vacature.select,"active");YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element,"zIndex","2");this.animProgress=new YAHOO.util.Anim(YAHOO.util.Dom.get("vw-progress-bar"),{height:{from:0,to:88}},5,YAHOO.util.Easing.easeNone);this.animProgress.vacatureWidget= this;this.animProgress.onComplete.subscribe(function(){this.vacatureWidget.startAnimation()});this.animProgress.animate()};c.startAnimation=function(b){if((!this.animFadeIn||!this.animFadeIn.isAnimated())&&(!this.animProgress||!this.animProgress.isAnimated()))this.doAnimation(b)};c.doAnimation=function(b){this.next=b==null?this.curr<this.vacatures.length-1?this.curr+1:0:b;if(this.curr!=this.next){this.animFadeOut=new YAHOO.util.Anim(this.vacatures[this.curr].vacature.element,{opacity:{from:1,to:0}}, 1,YAHOO.util.Easing.easeOut);this.animFadeIn=new YAHOO.util.Anim(this.vacatures[this.next].vacature.element,{opacity:{from:0,to:1}},2.5,YAHOO.util.Easing.backBoth);this.animProgress=new YAHOO.util.Anim(YAHOO.util.Dom.get("vw-progress-bar"),{height:{from:0,to:88}},5,YAHOO.util.Easing.easeNone);this.animFadeOut.vacatureWidget=this;this.animFadeIn.vacatureWidget=this;this.animProgress.vacatureWidget=this;this.animFadeIn.onComplete.subscribe(function(){this.vacatureWidget.animProgress.animate()});this.animProgress.onComplete.subscribe(function(){this.vacatureWidget.doAnimation()}); this.animFadeOut.animate();this.animFadeIn.animate();YAHOO.util.Dom.removeClass(this.vacatures[this.curr].vacature.select,"active");YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element,"zIndex","1");this.curr=this.next;YAHOO.util.Dom.addClass(this.vacatures[this.curr].vacature.select,"active");YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element,"zIndex","2")}};c.stopAnimation=function(){this.animFadeOut&&this.animFadeOut.isAnimated()&&this.animFadeOut.stop(true);if(this.animFadeIn)if(this.animFadeIn.isAnimated()){this.curr= this.next;this.animFadeIn.onComplete.unsubscribeAll();this.animFadeIn.stop(true)}if(this.animProgress)if(this.animProgress.isAnimated()){this.animProgress.onComplete.unsubscribeAll();this.animProgress.stop(true)}};c.enhanceVacatures()}YAHOO.util.Event.onContentReady("vw-holder",initVacatureWidget,this,true);function initVacatureWidget() {

	var vacatureWidget = new Object();

	vacatureWidget.vacatures = new Array();

	vacatureWidget.enhanceVacatures = function() {

		// show hidden progress bar and select links
		this.select_el   = YAHOO.util.Dom.get('vw-select');
		this.progress_el = YAHOO.util.Dom.get('vw-progress');

		YAHOO.util.Dom.removeClass(this.progress_el, 'hidden');
		YAHOO.util.Dom.removeClass(this.select_el,   'hidden');

		// find vacature elements, select links
		var vacature_elms = YAHOO.util.Dom.getElementsByClassName('vw-vacature', 'div', document.body);
		var select_a_elms = this.select_el.getElementsByTagName('a');

		// attach element, select link to vacature
		for (var i = 0; i < vacature_elms.length; i++) {
			this.vacatures[i] = new Object();
			this.vacatures[i].vacature = new Object();
			this.vacatures[i].vacature.element = vacature_elms[i];
			this.vacatures[i].vacature.select  = select_a_elms[i];

			// make sure all vacatures are in the same position
			YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get('vw-holder'), 'position', 'relative');
			YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get('vw-holder'), 'height', '110px');
			YAHOO.util.Dom.setStyle(this.vacatures[i].vacature.element, 'position', 'absolute');

			// attach behaviour
			this.vacatures[i].vacature.select.i = i;

			YAHOO.util.Event.on(this.vacatures[i].vacature.select, 'click', function(e) {

				var target = YAHOO.util.Event.getTarget(e);
				target.blur();

				this.stopAnimation();
				this.startAnimation(target.i);

				YAHOO.util.Event.preventDefault(e);
			}, this, true);
		}

		// hide all vacatures except the first one
		for (var i = 1; i < this.vacatures.length; i++) {

			YAHOO.util.Dom.setStyle(this.vacatures[i].vacature.element, 'opacity', '0');
			YAHOO.util.Dom.setStyle(this.vacatures[i].vacature.element, 'display', 'block');
		}

		// set start
		this.curr = 0;

		// start with progress bar for first vacature
		YAHOO.util.Dom.addClass(this.vacatures[this.curr].vacature.select, 'active');
		YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element, 'zIndex', '2'); // move the next vacature to the front
		this.animProgress = new YAHOO.util.Anim(YAHOO.util.Dom.get('vw-progress-bar'), { height: { from: 0, to: 88 } }, 5, YAHOO.util.Easing.easeNone);
		this.animProgress.vacatureWidget = this;
		this.animProgress.onComplete.subscribe(function() { this.vacatureWidget.startAnimation(); });
		this.animProgress.animate();
	};

	vacatureWidget.startAnimation = function(i) {
		if ((!this.animFadeIn || !this.animFadeIn.isAnimated()) && (!this.animProgress || !this.animProgress.isAnimated())) {
			this.doAnimation(i);
		}
	};

	vacatureWidget.doAnimation = function(i) {

		if (i == null) {
			this.next = (this.curr < (this.vacatures.length - 1))?(this.curr + 1):0;
		} else {
			this.next = i;
		}

		if (this.curr != this.next) {

			// console.log('animate: ' + this.curr + ' to ' + this.next);
			this.animFadeOut  = new YAHOO.util.Anim(this.vacatures[this.curr].vacature.element, { opacity: { from: 1, to: 0 } }, 1, YAHOO.util.Easing.easeOut);
			this.animFadeIn   = new YAHOO.util.Anim(this.vacatures[this.next].vacature.element, { opacity: { from: 0, to: 1 } }, 2.5, YAHOO.util.Easing.backBoth);
			this.animProgress = new YAHOO.util.Anim(YAHOO.util.Dom.get('vw-progress-bar'), { height: { from: 0, to: 88 } }, 5, YAHOO.util.Easing.easeNone);

			this.animFadeOut.vacatureWidget  = this;
			this.animFadeIn.vacatureWidget   = this;
			this.animProgress.vacatureWidget = this;

			this.animFadeIn.onComplete.subscribe(function() { this.vacatureWidget.animProgress.animate(); });
			this.animProgress.onComplete.subscribe(function() { this.vacatureWidget.doAnimation(); });

			this.animFadeOut.animate();
			this.animFadeIn.animate();

			YAHOO.util.Dom.removeClass(this.vacatures[this.curr].vacature.select, 'active');
			YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element, 'zIndex', '1');

			this.curr = this.next;

			YAHOO.util.Dom.addClass(this.vacatures[this.curr].vacature.select, 'active');
			YAHOO.util.Dom.setStyle(this.vacatures[this.curr].vacature.element, 'zIndex', '2'); // move the next vacature to the front
		}
	};

	vacatureWidget.stopAnimation = function() {
		
		// console.log('stopping animation');
		if (this.animFadeOut) {
			if (this.animFadeOut.isAnimated()) {
				this.animFadeOut.stop(true);
			}
		}
		if (this.animFadeIn) {
			if (this.animFadeIn.isAnimated()) {
				this.curr = this.next;
				this.animFadeIn.onComplete.unsubscribeAll();
				this.animFadeIn.stop(true);
			}
		}
		if (this.animProgress) {
			if (this.animProgress.isAnimated()) {
				this.animProgress.onComplete.unsubscribeAll();
				this.animProgress.stop(true);
			}
		}
	};

	// initialize
	vacatureWidget.enhanceVacatures();
};
YAHOO.util.Event.onContentReady('vw-holder', initVacatureWidget, this, true);
