
var slideDelay = 6 * 1000;
var slideDuration = 0.5;
var pulseDuration = 1;

function onLoad() {
	var img1 = new Image();
	var img2 = new Image();
	img1.src = "assets/images/pijl_wit.gif";
	img2.src = "assets/images/pijl_grijs.gif";
	
	document.getElementById("search_panel").style.display = "none";
	document.getElementById("search_filler").style.display = "none";
	document.getElementById("result_panel").style.display = "none";

	
}

function sliderInterval() {
	$('spotlight_slider').next();
}

function pauseSlider() {
	if(typeof slideInterval != "undefined") {
		clearInterval(window.slideInterval);
		window.slideInterval = undefined;
		$('play_pause').startAnim();
	};
}

function startSlider() {
	$('play_pause').stopAnim();
	window.slideInterval = setInterval(sliderInterval, slideDelay);
}

function switchArrow(oAnchor) {
	oImg = oAnchor.lastChild;
	if(oImg.src.match(/pijl_grijs.gif$/g)) {
		oImg.src = "/assets/images/pijl_wit.gif";	
	}
	else {
		oImg.src = "/assets/images/pijl_grijs.gif";
	}
}

function loadSlider() {
	var slide_h	= 173; // slide height
	var s 	= $('spotlight_slider');
	var sl 	= $$('div#spotlight_slider div.slider')[0];
	var c 	= $$('div#spotlight_slider div#slider_control a');
	var pp 	= $$('div#spotlight_slider img#play_pause')[0];
	var el	= sl.immediateDescendants();
	s.num = el.size();
	s.cur = 0;
	
	var clone = document.createElement("div");
	clone.innerHTML = el[0].innerHTML;
	clone.id = "clone";
	
	sl.appendChild(clone);
	
	pp.onclick = function() {
		if(typeof slideInterval == "undefined") {
			startSlider();
		} else {
			pauseSlider();
		}
	}
	
	pp.startAnim = function() {
		this.animate();
	}
	pp.animate = function() {
		if(typeof slideInterval == "undefined") {
			doAfter = function() {$('play_pause').animate()}
			this.effect1 = new Effect.Opacity(this, { duration:pulseDuration/2, from:1.0, to: 0.5, queue:{position:'end', scope:'pulse'}, scope:'pulse' } );
			this.effect2 = new Effect.Opacity(this, { duration:pulseDuration/2, from:0.5, to: 1.0, queue:{position:'end', scope:'pulse'}, afterFinish:doAfter } );
		}
	}
	pp.stopAnim = function() {
		if(this.effect1.state != 'finished') {
			this.effect1.cancel();
		} 
		if(this.effect2.state != 'finished') {
			this.effect2.cancel();
		}
		this.setStyle({ opacity:1.0 });
		s.next();
	}
	
	s.goto = function(n) {
		if(arguments[1]) {
			doAfter = arguments[1];
		} else {
			doAfter = function() {};
		}
		if(this.cur != n) {
			var move_y = this.cur*slide_h - n*slide_h;
			new Effect.Move(sl, { x:0, y:move_y, duration:slideDuration , afterFinish:doAfter, queue:'end' } );
			this.cur = n;
		}
	}
	
	s.next = function() {
		var c = $$('div#spotlight_slider div#slider_control a');
		if(this.cur != this.num-1) {
			this.goto(this.cur+1);
			var cur = this.cur;
			//setTimeout( function() {
				c.invoke('on_blur');
				$$('div#spotlight_slider div#slider_control a#link_'+cur+' img')[0].src='assets/images/item_pointer_sel.gif';
			//}, (slideDuration / 2) * 1000);
		} else {
			this.goto(this.cur+1, function(){$('spotlight_slider').do_reset();} );
			//setTimeout( function() {
				c.invoke('on_blur');
				$$('div#spotlight_slider div#slider_control a#link_0 img')[0].src='assets/images/item_pointer_sel.gif';
			//}, (slideDuration / 2) * 1000);
		}
	}
	
	s.do_reset = function() {
		this.cur = 0;
		sl.setStyle( { top:'0px' } );
	}
	
	c.each(function(e, i) {
		e.onclick = function(e) {
			if(!e) {
				e = window.event;
			}
			Event.stop(e);
			$('spotlight_slider').goto(i);
			
			$$('div#spotlight_slider div#slider_control a').invoke('on_blur');
			$(this).down().src="assets/images/item_pointer_sel.gif";
			
			pauseSlider();
		};
		e.on_blur = function() {
			$(this).down().src="assets/images/item_pointer.gif";
		}
	});
}