$(document).ready(function(){

	// preload and show illus
	
	if($('#illustration').length > 0) {
		menuitems = new Array('index','film','photo','motion','contact','showreel');
		illus = new Array();
		for(i=0;i<menuitems.length;i++) { illus[i] = $('<img>').attr('src', '/media/img/illus/'+menuitems[i]+'.jpg'); }
		
			$('#menu li').hover(
			function() { 
				$('#illustration').show();
				$('#illustration').html('<img src="/media/img/illus/'+$(this).attr('id')+'.jpg">'); 
			},
			function() { 
				$('#illustration').html('');
				$('#illustration').hide();
			}
		);
	}
	

	
	// is this a page with thumbnails?
	if($('#thumbs').length > 0) {

		active = 0;
		pos = $('#thumbs').position();
		pos = pos.left;
		$('#position').html((active+1)+'/'+$('#thumbs').children().length);
	
		$('#next').click(function(){
			var length = $('#thumbs').children().length;
			if ((active+1) < length) active++;
			else active = 0;
			
			var np = pos - active * 970;
			$('#position').html((active+1)+'/'+$('#thumbs').children().length);
			$('#thumbs').animate({ left: np }, 400);
	
			return false;
		});
	
		$('#prev').click(function(){
			var length = $('#thumbs').children().length;
			if ((active-1) >= 0) {
				active--;
				var np = pos - active * 970;
				$('#position').html((active+1)+'/'+$('#thumbs').children().length);
				$('#thumbs').animate({ left: np }, 400);
			}
			return false;
		});
	
	} // end if thumbnails

	
	// => use same for images but dynamically load images into boxes
	// is this a page with thumbnails?
	if($('#photos').length > 0) {
	
		// change this depending on the requested photo
		// active = 0;
		
		pos = $('#photos').position();
		pos = pos.left;
		$('#position').html((active+1)+'/'+$('#photos').children().length);
		
		// go to active photo
		// $('#photo'+active).attr('src', photos[active]);
		
		$('#photo'+active).parents('a').css('background', 'url('+photos[active]+') 0 0 no-repeat');
		
		
		
		var np = pos - active * 970;
		$('#photos').animate({ left: np }, 0);
	
		$('a.next').click(function(){
			var length = $('#photos').children().length;
			
			if ((active+1) < length) active++;
			else active = 0;
			
			// if($('#photo'+active).attr('src') != photos[active]) $('#photo'+active).attr('src', photos[active]);
			
			if($('#photo'+active).parents('a').css('background') == '') 
				$('#photo'+active).parents('a').css('background', 'url('+photos[active]+') 0 0 no-repeat');

			
			var np = pos - active * 970;
			$('#position').html((active+1)+'/'+$('#photos').children().length);
			$('#photos').animate({ left: np }, 400, 'linear', function(){
				if($('#photo'+(active+1)).length > 0) {
					$('#photo'+(active+1)).parents('a').css('background', 'url('+photos[(active+1)]+') 0 0 no-repeat');
				}
			});
	
			return false;
		});
	
		$('#prev').click(function(){
			var length = $('#photos').children().length;
			if ((active-1) >= 0) {
				active--;
				if($('#photo'+active).attr('src') != photos[active]) $('#photo'+active).attr('src', photos[active]);
				var np = pos - active * 970;
				$('#position').html((active+1)+'/'+$('#photos').children().length);
				$('#photos').animate({ left: np }, 400);
	
			}
			return false;
		});
	
	} // end if thumbnails
	
	/* captions */
	
	if($('#caption').length > 0) {
		$('#thumbs a').hover(
			function() { $('#caption').html(captions[$(this).attr('class')]); },
			function() { $('#caption').html(''); }
		);
	}





});