$(function(){
	gallery.init();
});

gallery = {
	imgPrefix : '/image/logos/',
	currentImg : 0,
	fadeTime : 500,
	waitTime : 1000,
	
		
	select : {
		container : '#gallery-container',
		img : '#gallery-container img'
	},
	
	images : [
		'agfa.jpg', 'drsystems.jpg', 'emageon.jpg', 'fujifilm.jpg',
		'ge.jpg', 'merge.jpg' , 'philips.jpg', 'rogan.jpg', 'sectra.jpg',
		'siemens.jpg', 'synapse.jpg', 'zillion.jpg'
	],
	
	init : function(){
		$(this.select.container).html( $(this.select.container).html() + this.img(this.images[this.currentImg]))
		.click(function(){
			window.location = '/experience.html';
		});
		
		$(gallery.select.img).css({top : (gallery.centerImgHeight() - 16)}) // the '-24' is a quick fix for the first image
		
		setTimeout(this.rotate, this.waitTime);
	},
	
	rotate  : function(){
		if (gallery.currentImg >= gallery.images.length - 1)
			gallery.currentImg = 0;
		else
			gallery.currentImg++;

		$(gallery.select.img).fadeOut(gallery.fadeTime, function(){
			$(gallery.select.img).attr('src', gallery.imgSrc(gallery.images[gallery.currentImg]))
			$(gallery.select.img).css({top : gallery.centerImgHeight()})
			
			$(gallery.select.img).fadeIn(gallery.fadeTime, function(){
				setTimeout(gallery.rotate, gallery.waitTime);
			})
		})
	},
	
	img : function(url){
		return '<img src="' + this.imgSrc(url) + '" alt="" />';
	},
	
	imgSrc : function(url){
		return this.imgPrefix + url;
	},
	
	centerImgHeight : function(){
		return ($(gallery.select.container).height() / 2) - ($(gallery.select.img).height() / 2);
	}

};