/**
 * @author Maarten Molenschot
 */

window.addEvent('domready', function(){
	if($('carousel_container')){
		$$('#carousel_previous_disabled,#carousel_next_disabled').fade('hide');
		
		var slide = new noobSlide({
			box: $('carousel'),
			items: $$('#carousel div.slide'),
			size: 200,
			addButtons: {
				previous: $('carousel_previous'),
				next: $('carousel_next')
			},
			onWalk: function(currentItem,currentHandle){
				var item = parseInt(this.currentIndex);
				if(isNaN(item)) item = 0;
				if(item == 0) {
					$('carousel_previous').fade(0);
					$('carousel_previous_disabled').fade(1);
					$('carousel_next').fade(1);
					$('carousel_next_disabled').fade(0);
				} else if(item >= (this.items.length - 4)) {
					$('carousel_previous').fade(1);
					$('carousel_previous_disabled').fade(0);
					$('carousel_next').fade(0);
					$('carousel_next_disabled').fade(1);
				} else {
					$('carousel_previous').fade(1);
					$('carousel_previous_disabled').fade(0);
					$('carousel_next').fade(1);
					$('carousel_next_disabled').fade(0);
				}
			}
		});
	}
	
	if($('slideshow')){
		var slideshow = new Slideshow('slideshow', SlideshowImages, {
			delay: 6000,
			height: 280,
			//hu: '/img/jpg/',
			hu: '/media/',
			loader: false,
			width: 822
		});
	}
	
	if($('zoekbox_adres') && $('zoekbox_plaats')){
		$('zoekbox_adres').addEvent('click', function(){
			this.getElement('img').set('src', '/img/gif/zoekbox-adres.gif');
			$('zoekbox_plaats').getElement('img').set('src', '/img/gif/zoekbox-plaats-wit.gif');
			$('type_zoekbox').set('value', 'adres');
		});
		
		$('zoekbox_plaats').addEvent('click', function(){
			this.getElement('img').set('src', '/img/gif/zoekbox-plaats.gif');
			$('zoekbox_adres').getElement('img').set('src', '/img/gif/zoekbox-adres-wit.gif');
			$('type_zoekbox').set('value', 'plaats');
		});
		
		$('waarde_zoekbox').addEvents({
			'focus': function(){
				this.set('rel', this.get('value'));
				this.set('value', '');
			},
			'blur': function(){
				if(this.get('value')==''){
					this.set('value', this.get('rel'));
					this.erase('rel');
				}
			}
		});
		
		$('submit_zoekbox').addEvent('click', function(){
			$('form_zoekbox').submit();
		});
	}
	
	if($('detailshow_container')){
		$$('#detailshow_previous_disabled,#detailshow_next_disabled').fade('hide');
		
		var slide = new noobSlide({
			box: $('detailshow'),
			items: $$('#detailshow div.slide'),
			handles: $$('#thumbs div.thumb'),
			size: 574,
			addButtons: {
				previous: $('detailshow_previous'),
				next: $('detailshow_next')
			},
			onWalk: function(currentItem,currentHandle){
				var item = parseInt(this.currentIndex);
				if(isNaN(item)) item = 0;
				if(item == 0) {
					$('detailshow_previous').fade(0);
					$('detailshow_previous_disabled').fade(1);
					$('detailshow_next').fade(1);
					$('detailshow_next_disabled').fade(0);
				} else if(item >= (this.items.length - 1)) {
					$('detailshow_previous').fade(1);
					$('detailshow_previous_disabled').fade(0);
					$('detailshow_next').fade(0);
					$('detailshow_next_disabled').fade(1);
				} else {
					$('detailshow_previous').fade(1);
					$('detailshow_previous_disabled').fade(0);
					$('detailshow_next').fade(1);
					$('detailshow_next_disabled').fade(0);
				}
				
				if(item<(this.items.length-4)){
					$('thumbs').tween('left', -(item*105) + 'px');
				}
				
				$('detailshow_number').set('text', (item+1) + ' van ' + this.items.length);
			}
		});
	}
});
